MCPcopy Index your code
hub / github.com/CodeGraphContext/CodeGraphContext / computeCommonPrefix

Function computeCommonPrefix

website/src/lib/parser.worker.ts:495–513  ·  view source on GitHub ↗

* Compute the longest common directory prefix of all queued file paths. * e.g. ["/home/user/proj/src/a.ts", "/home/user/proj/lib/b.ts"] * → "/home/user/proj"

(paths: string[])

Source from the content-addressed store, hash-verified

493 * → "/home/user/proj"
494 */
495function computeCommonPrefix(paths: string[]): string {
496 if (paths.length === 0) return '';
497 const dirs = paths.map(p => {
498 const norm = p.replace(/\\/g, '/');
499 return norm.substring(0, norm.lastIndexOf('/'));
500 });
501 const first = dirs[0].split('/');
502 let common = first;
503 for (let i = 1; i < dirs.length; i++) {
504 const parts = dirs[i].split('/');
505 const newCommon: string[] = [];
506 for (let j = 0; j < Math.min(common.length, parts.length); j++) {
507 if (common[j] === parts[j]) newCommon.push(common[j]);
508 else break;
509 }
510 common = newCommon;
511 }
512 return common.join('/');
513}
514
515/**
516 * Lazily create (or return cached) Folder nodes for the repo-relative segments only.

Callers 1

parser.worker.tsFile · 0.85

Calls 2

mapMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected