mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 21:02:02 +00:00
Fix common ancestor finding: iterate backwards to find deepest ancestor
getPath returns root-first, so iterating forward found root as common ancestor instead of the deepest shared node. Now iterates backwards.
This commit is contained in:
parent
a602e8aba8
commit
92947a3dc4
1 changed files with 5 additions and 4 deletions
|
|
@ -91,14 +91,15 @@ export function collectEntriesForBranchSummary(
|
||||||
return { entries: [], commonAncestorId: null };
|
return { entries: [], commonAncestorId: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find common ancestor
|
// Find common ancestor (deepest node that's on both paths)
|
||||||
const oldPath = new Set(session.getPath(oldLeafId).map((e) => e.id));
|
const oldPath = new Set(session.getPath(oldLeafId).map((e) => e.id));
|
||||||
const targetPath = session.getPath(targetId);
|
const targetPath = session.getPath(targetId);
|
||||||
|
|
||||||
|
// targetPath is root-first, so iterate backwards to find deepest common ancestor
|
||||||
let commonAncestorId: string | null = null;
|
let commonAncestorId: string | null = null;
|
||||||
for (const entry of targetPath) {
|
for (let i = targetPath.length - 1; i >= 0; i--) {
|
||||||
if (oldPath.has(entry.id)) {
|
if (oldPath.has(targetPath[i].id)) {
|
||||||
commonAncestorId = entry.id;
|
commonAncestorId = targetPath[i].id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue