MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / indexGitRepository

Function indexGitRepository

packages/backend/src/zoekt.ts:11–55  ·  view source on GitHub ↗
(repo: Repo, settings: Settings, revisions: string[], signal?: AbortSignal)

Source from the content-addressed store, hash-verified

9const logger = createLogger('zoekt');
10
11export const indexGitRepository = async (repo: Repo, settings: Settings, revisions: string[], signal?: AbortSignal) => {
12 const { path: repoPath } = getRepoPath(repo);
13 const shardPrefix = getShardPrefix(repo.orgId, repo.id);
14
15 const largeFileGlobPatterns = env.ALWAYS_INDEX_FILE_PATTERNS?.split(',').map(pattern => pattern.trim()) ?? [];
16
17 const command = [
18 'zoekt-git-index',
19 '-allow_missing_branches',
20 `-index ${INDEX_CACHE_DIR}`,
21 `-max_trigram_count ${settings.maxTrigramCount}`,
22 `-file_limit ${settings.maxFileSize}`,
23 `-branches "${revisions.join(',')}"`,
24 `-tenant_id ${repo.orgId}`,
25 `-repo_id ${repo.id}`,
26 `-shard_prefix_override ${shardPrefix}`,
27 ...largeFileGlobPatterns.map((pattern) => `-large_file "${pattern}"`),
28 repoPath
29 ].join(' ');
30
31 return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
32 exec(command, { signal }, (error, stdout, stderr) => {
33 if (error) {
34 reject(error);
35 return;
36 }
37
38 if (stdout) {
39 stdout.split('\n').filter(line => line.trim()).forEach(line => {
40 logger.debug(line);
41 });
42 }
43 if (stderr) {
44 stderr.split('\n').filter(line => line.trim()).forEach(line => {
45 logger.debug(line);
46 });
47 }
48
49 resolve({
50 stdout,
51 stderr
52 });
53 })
54 });
55}
56
57/**
58 * Cleans up temporary shard files left behind by a failed indexing operation.

Callers 1

indexRepositoryMethod · 0.85

Calls 2

getRepoPathFunction · 0.90
getShardPrefixFunction · 0.85

Tested by

no test coverage detected