Skip to content

Commit 33062b7

Browse files
bherilameta-codesync[bot]
authored andcommitted
Fix sortAsc crash when set contains commits not in the DAG
Summary: During drag-and-drop rebase previews, the preview DAG may contain optimistic commits (e.g. OPTIMISTIC_REBASE_SUCC: hashes) that are not present in the cached defaultSortAscIndex. Previously this threw "not in the dag" errors. Instead of silently filtering out missing commits (which would lose them from the sorted output), fall back to the full topological sortAsc on the underlying commitDag when any hash in the set is missing from the cached index. This preserves all commits in the output while avoiding the crash. Fixes #1229 Differential Revision: D99703453 fbshipit-source-id: 3ccfc17ffa1a88ced16c8b700d72ffcb70fb6fec
1 parent 8d1fb9c commit 33062b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

addons/isl/src/dag/dag.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ export class Dag extends SelfUpdate<CommitDagRecord> {
273273
if (set === undefined) {
274274
return [...sorted];
275275
}
276-
const hashes = arrayFromHashes(set === undefined ? this.all() : set);
276+
const hashes = arrayFromHashes(set);
277+
if (hashes.some(h => !index.has(h))) {
278+
// Fall back to full topological sort when set contains commits not in
279+
// the cached index (e.g. optimistic rebase preview commits).
280+
return this.commitDag.sortAsc(set, {compare: sortAscCompare});
281+
}
277282
return hashes.sort((a, b) => {
278-
const aIdx = index.get(a);
279-
const bIdx = index.get(b);
280-
if (aIdx == null || bIdx == null) {
281-
throw new Error(`Commit ${a} or ${b} is not in the dag.`);
282-
}
283-
return aIdx - bIdx;
283+
return (index.get(a) as number) - (index.get(b) as number);
284284
});
285285
}
286286
// Otherwise, fallback to sortAsc.

0 commit comments

Comments
 (0)