MCPcopy Index your code
hub / github.com/coder/mux / repairBaseRepoMissingObjectsFromLocal

Method repairBaseRepoMissingObjectsFromLocal

src/node/runtime/SSHRuntime.ts:913–1004  ·  view source on GitHub ↗
(
    projectPath: string,
    baseRepoPathArg: string,
    initLogger: InitLogger,
    abortSignal?: AbortSignal
  )

Source from the content-addressed store, hash-verified

911 }
912
913 private async repairBaseRepoMissingObjectsFromLocal(
914 projectPath: string,
915 baseRepoPathArg: string,
916 initLogger: InitLogger,
917 abortSignal?: AbortSignal
918 ): Promise<void> {
919 if (abortSignal?.aborted) {
920 throw new Error(OPERATION_ABORTED_ERROR);
921 }
922
923 await this.transport.acquireConnection({
924 abortSignal,
925 onWait: (waitMs) => logSSHBackoffWait(initLogger, waitMs),
926 });
927
928 if (abortSignal?.aborted) {
929 throw new Error(OPERATION_ABORTED_ERROR);
930 }
931
932 initLogger.logStep("Repairing shared base repository object cache...");
933 const remoteAbortController = createAbortController(
934 BASE_REPO_MISSING_OBJECT_REPAIR_TIMEOUT_MS,
935 abortSignal
936 );
937
938 try {
939 const remoteStream = await this.exec(`git -C ${baseRepoPathArg} unpack-objects -r`, {
940 cwd: "/tmp",
941 abortSignal: remoteAbortController.signal,
942 });
943 const remoteStdoutPromise = streamToString(remoteStream.stdout);
944 const remoteStderrPromise = streamToString(remoteStream.stderr);
945
946 // A normal fetch/push can be a no-op when the remote already has the
947 // commit object but is missing blobs from the same tree. Stream a complete
948 // non-thin local pack and let `unpack-objects -r` add only the missing
949 // objects without deleting or recreating the shared gitdir used by siblings.
950 const gitProc = spawn("git", ["-C", projectPath, "pack-objects", "--all", "--stdout"], {
951 stdio: ["ignore", "pipe", "pipe"],
952 windowsHide: true,
953 });
954
955 let packStderr = "";
956 gitProc.stderr?.on("data", (data: Buffer) => {
957 const chunk = data.toString();
958 packStderr += chunk;
959 for (const line of chunk.split("\n").filter(Boolean)) {
960 initLogger.logStderr(line);
961 }
962 });
963 const gitExitCodePromise = waitForProcessExit(gitProc);
964
965 try {
966 await pipeReadableToWebWritable(gitProc.stdout, remoteStream.stdin, abortSignal);
967 } catch (error) {
968 gitProc.kill();
969 throw error;
970 }

Calls 12

streamToStringFunction · 0.90
logSSHBackoffWaitFunction · 0.85
createAbortControllerFunction · 0.85
waitForProcessExitFunction · 0.85
logStepMethod · 0.80
onMethod · 0.80
logStderrMethod · 0.80
acquireConnectionMethod · 0.65
execMethod · 0.65
killMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected