Commit

Compare diffs from where the two branches last agreed, as a pull request would

syntaqxcommitted Parentbb913cfBrowse files
1 file+6−50/1 viewed
+6−5
4545 const base = asked.base ?? found.defaultBranch;
4646 const head = asked.head;
4747 if (!head || head === base) return { base, head, branches, comparison: null, commits: [], same: head === base };
48− const [compared, headLog, baseLog] = await Promise.all([
49− repos.compare(found.id, viewer, base, head),
50− repos.log(path, viewer, head, HEAD_DEPTH),
51− repos.log(path, viewer, base, BASE_DEPTH),
52− ]);
48+ const [headLog, baseLog] = await Promise.all([repos.log(path, viewer, head, HEAD_DEPTH), repos.log(path, viewer, base, BASE_DEPTH)]);
5349 if (!headLog.ok || headLog.value.length === 0) throw new Response(`There is no branch, tag or commit named ${head}.`, { status: 404 });
5450 // What head has that base does not: its history down to the first commit base also has.
5551 const onBase = new Set(baseLog.ok ? baseLog.value.map((commit) => commit.hash) : []);
6056 author: commit.author.name,
6157 at: commit.authoredAt,
6258 }));
59+ // The changes from where the two last agreed, as a pull request would
60+ // bring them: what base gained since is not head taking it away. When
61+ // that point is past what was read, the two tips are compared.
62+ const mergeBase = shared === -1 ? base : headLog.value[shared]!.hash;
63+ const compared = await repos.compare(found.id, viewer, mergeBase, head);
6364 const comparison: Comparison | null = compared.ok ? compared.value : null;
6465 return { base, head, branches, comparison, commits, same: false };
6566 }