Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index default branch #148

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/backend/src/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const getGiteaReposFromConfig = async (config: GiteaConfig, ctx: AppConte
id: repoId,
cloneUrl: cloneUrl.toString(),
path: repoPath,
defaultBranch: repo.default_branch,
isStale: false,
isFork: repo.fork!,
isArchived: !!repo.archived,
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ type OctokitRepository = {
subscribers_count?: number,
forks_count?: number,
archived?: boolean,
default_branch?: string,
topics?: string[],
size?: number,
size?: number
}

export const getGitHubReposFromConfig = async (config: GitHubConfig, signal: AbortSignal, ctx: AppContext) => {
Expand Down Expand Up @@ -79,6 +80,7 @@ export const getGitHubReposFromConfig = async (config: GitHubConfig, signal: Abo
id: repoId,
cloneUrl: cloneUrl.toString(),
path: repoPath,
defaultBranch: repo.default_branch,
isStale: false,
isFork: repo.fork,
isArchived: !!repo.archived,
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const getGitLabReposFromConfig = async (config: GitLabConfig, ctx: AppCon
cloneUrl: cloneUrl.toString(),
path: repoPath,
isStale: false,
defaultBranch: project.default_branch,
isFork,
isArchived: project.archived,
topics: project.topics ?? [],
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AppContext, LocalRepository, GitRepository, Repository, Settings } from
import { cloneRepository, fetchRepository, getGitRepoFromConfig } from "./git.js";
import { createLogger } from "./logger.js";
import { createRepository, Database, loadDB, updateRepository, updateSettings } from './db.js';
import { arraysEqualShallow, isRemotePath, measure } from "./utils.js";
import { arraysEqualShallow, stringsEqualFalseySafe, isRemotePath, measure } from "./utils.js";
import { DEFAULT_SETTINGS } from "./constants.js";
import stripJsonComments from 'strip-json-comments';
import { indexGitRepository, indexLocalRepository } from "./zoekt.js";
Expand Down Expand Up @@ -154,7 +154,8 @@ export const isRepoReindexingRequired = (previous: Repository, current: Reposito

return (
!arraysEqualShallow(previous.branches, current.branches) ||
!arraysEqualShallow(previous.tags, current.tags)
!arraysEqualShallow(previous.tags, current.tags) ||
!stringsEqualFalseySafe(previous.defaultBranch, current.defaultBranch)
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface GitRepository extends BaseRepository {
cloneUrl: string;
branches: string[];
tags: string[];
defaultBranch?: string;
gitConfigMetadata?: Record<string, string>;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ export const arraysEqualShallow = <T>(a?: readonly T[], b?: readonly T[]) => {

return true;
}

export const stringsEqualFalseySafe = (a?: string, b?: string): boolean => {
if (a === b) return true;
else if (!a && !b) return true;
else return false;
}
1 change: 1 addition & 0 deletions packages/backend/src/zoekt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const indexGitRepository = async (repo: GitRepository, settings: Settings
...repo.branches ?? [],
...repo.tags ?? [],
];
if (repo.defaultBranch) revisions.push(repo.defaultBranch);

const command = `zoekt-git-index -allow_missing_branches -index ${ctx.indexPath} -max_trigram_count ${settings.maxTrigramCount} -file_limit ${settings.maxFileSize} -branches ${revisions.join(',')} ${repo.path}`;

Expand Down