2024-11-01 17:51:14 +00:00
|
|
|
import { exec } from "child_process";
|
2025-01-14 21:37:31 +00:00
|
|
|
import { AppContext, LocalRepository, Settings } from "./types.js";
|
|
|
|
|
import { Repo } from "@sourcebot/db";
|
|
|
|
|
import { getRepoPath } from "./utils.js";
|
|
|
|
|
import { DEFAULT_SETTINGS } from "./constants.js";
|
2024-11-01 17:51:14 +00:00
|
|
|
|
|
|
|
|
const ALWAYS_EXCLUDED_DIRS = ['.git', '.hg', '.svn'];
|
|
|
|
|
|
2025-01-14 21:37:31 +00:00
|
|
|
export const indexGitRepository = async (repo: Repo, ctx: AppContext) => {
|
2024-11-07 02:28:10 +00:00
|
|
|
const revisions = [
|
2025-01-14 21:37:31 +00:00
|
|
|
'HEAD'
|
2024-11-07 02:28:10 +00:00
|
|
|
];
|
2025-01-15 00:46:36 +00:00
|
|
|
|
2025-01-24 21:16:08 +00:00
|
|
|
const shardPrefix = `${repo.orgId}_${repo.id}`;
|
2025-01-14 21:37:31 +00:00
|
|
|
const repoPath = getRepoPath(repo, ctx);
|
2025-01-24 21:16:08 +00:00
|
|
|
const command = `zoekt-git-index -allow_missing_branches -index ${ctx.indexPath} -file_limit ${DEFAULT_SETTINGS.maxFileSize} -branches ${revisions.join(',')} -tenant_id ${repo.orgId} -shard_prefix ${shardPrefix} ${repoPath}`;
|
2024-11-07 02:28:10 +00:00
|
|
|
|
2024-11-01 17:51:14 +00:00
|
|
|
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
|
2024-11-07 02:28:10 +00:00
|
|
|
exec(command, (error, stdout, stderr) => {
|
2024-11-01 17:51:14 +00:00
|
|
|
if (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resolve({
|
|
|
|
|
stdout,
|
|
|
|
|
stderr
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 22:34:43 +00:00
|
|
|
export const indexLocalRepository = async (repo: LocalRepository, settings: Settings, ctx: AppContext, signal?: AbortSignal) => {
|
2024-11-01 17:51:14 +00:00
|
|
|
const excludedDirs = [...ALWAYS_EXCLUDED_DIRS, repo.excludedPaths];
|
2024-12-09 22:34:43 +00:00
|
|
|
const command = `zoekt-index -index ${ctx.indexPath} -file_limit ${settings.maxFileSize} -ignore_dirs ${excludedDirs.join(',')} ${repo.path}`;
|
2024-11-01 17:51:14 +00:00
|
|
|
|
|
|
|
|
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
|
|
|
|
|
exec(command, { signal }, (error, stdout, stderr) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resolve({
|
|
|
|
|
stdout,
|
|
|
|
|
stderr
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|