MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / acquireProject

Function acquireProject

src/mcp/project-lifecycle.ts:39–67  ·  view source on GitHub ↗
(
  root: string,
  open: () => CodeGraph,
  options: Parameters<CodeGraph['watch']>[0],
)

Source from the content-addressed store, hash-verified

37
38/** Engines in one process share a graph; other processes share the writer slot. */
39export function acquireProject(
40 root: string,
41 open: () => CodeGraph,
42 options: Parameters<CodeGraph['watch']>[0],
43): ProjectLease {
44 root = realpathSync(root);
45 const key = canonicalProjectRoot(root);
46 let project = projects.get(key);
47 if (!project) {
48 const cg = open();
49 project = { key, cg, refs: 0, owner: false, caughtUp: false, retirement: null, gate: null, socket: null, options,
50 dropProgress: null, timer: setInterval(() => { void ready(root, project!); }, 1000) };
51 project.timer.unref();
52 projects.set(key, project);
53 }
54 const entry = project;
55 entry.refs++;
56 let released = false;
57 return {
58 cg: entry.cg,
59 ready: () => ready(root, entry),
60 release: () => {
61 if (released) return Promise.resolve();
62 released = true;
63 if (--entry.refs === 0) return retire(root, entry);
64 return Promise.resolve();
65 },
66 };
67}
68
69function retire(root: string, project: Project): Promise<void> {
70 if (project.retirement) return project.retirement;

Callers 3

constructorMethod · 0.90
startWatchingMethod · 0.90

Calls 7

canonicalProjectRootFunction · 0.90
readyFunction · 0.85
retireFunction · 0.70
getMethod · 0.65
resolveMethod · 0.65
openFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected