mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Share which commits each revision adds
Patch and Revision each computed it with their own copy of the loop.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
import type { Commit } from "@bindings/repo/Commit";
|
||||
import type { Snippet } from "svelte";
|
||||
|
||||
import mapValues from "lodash/mapValues";
|
||||
import partial from "lodash/partial";
|
||||
import { slide } from "svelte/transition";
|
||||
|
||||
@@ -38,6 +39,7 @@
|
||||
splitDescription,
|
||||
visibleCommitsOf,
|
||||
} from "@app/lib/revisionDescription";
|
||||
import { newCommitsByRevision } from "@app/lib/revisionList";
|
||||
import * as roles from "@app/lib/roles";
|
||||
import { push } from "@app/lib/router";
|
||||
import {
|
||||
@@ -539,16 +541,12 @@
|
||||
}
|
||||
}),
|
||||
).then(entries => {
|
||||
const next: Record<string, Commit[]> = {};
|
||||
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||
const seen = new Set<string>();
|
||||
revisions.forEach((rev, i) => {
|
||||
const [, commits] = entries[i];
|
||||
const novel = commits.filter(c => !seen.has(c.id));
|
||||
novel.forEach(c => seen.add(c.id));
|
||||
next[rev.id] = [...novel].reverse();
|
||||
});
|
||||
commitsByRevision = next;
|
||||
const commits = Object.fromEntries(entries);
|
||||
// Newest first, as the timeline lists them.
|
||||
commitsByRevision = mapValues(
|
||||
newCommitsByRevision(revisions, id => commits[id] ?? []),
|
||||
added => [...added].reverse(),
|
||||
);
|
||||
});
|
||||
});
|
||||
const olderRevisionIds = $derived(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Revision } from "@bindings/cob/patch/Revision";
|
||||
import type { Commit } from "@bindings/repo/Commit";
|
||||
|
||||
import type { RevisionListSettings } from "@app/lib/revisionListSettings";
|
||||
|
||||
@@ -46,3 +47,20 @@ export function orderRevisions(
|
||||
return settings.sortDesc ? [...group].reverse() : group;
|
||||
});
|
||||
}
|
||||
|
||||
/// The commits each revision adds over the revisions before it, in the order
|
||||
/// `commitsOf` lists them. A later revision usually contains every earlier
|
||||
/// commit, so counting its full range would count them again.
|
||||
export function newCommitsByRevision(
|
||||
revisions: { id: string }[],
|
||||
commitsOf: (revisionId: string) => Commit[],
|
||||
): Record<string, Commit[]> {
|
||||
const seen = new Set<string>();
|
||||
const result: Record<string, Commit[]> = {};
|
||||
for (const revision of revisions) {
|
||||
const added = commitsOf(revision.id).filter(c => !seen.has(c.id));
|
||||
added.forEach(c => seen.add(c.id));
|
||||
result[revision.id] = added;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+11
-11
@@ -12,6 +12,7 @@
|
||||
import type { Commit } from "@bindings/repo/Commit";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import mapValues from "lodash/mapValues";
|
||||
import { SvelteSet } from "svelte/reactivity";
|
||||
|
||||
import { commentSourcesOf } from "@app/lib/commentSources";
|
||||
@@ -28,7 +29,11 @@
|
||||
import { patchContributions } from "@app/lib/patchContributions";
|
||||
import type { ReviewEntry } from "@app/lib/reviewSummary";
|
||||
import { revisionTitle } from "@app/lib/revisionDescription";
|
||||
import { orderRevisions, revisionNumbers } from "@app/lib/revisionList";
|
||||
import {
|
||||
newCommitsByRevision,
|
||||
orderRevisions,
|
||||
revisionNumbers,
|
||||
} from "@app/lib/revisionList";
|
||||
import { revisionListSettings } from "@app/lib/revisionListSettings";
|
||||
import * as roles from "@app/lib/roles";
|
||||
import * as router from "@app/lib/router";
|
||||
@@ -378,16 +383,11 @@
|
||||
}
|
||||
}),
|
||||
).then(entries => {
|
||||
const next: Record<string, number> = {};
|
||||
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||
const seen = new Set<string>();
|
||||
ordered.forEach((rev, i) => {
|
||||
const [, commits] = entries[i];
|
||||
const novel = commits.filter(c => !seen.has(c.id));
|
||||
novel.forEach(c => seen.add(c.id));
|
||||
next[rev.id] = novel.length;
|
||||
});
|
||||
commitCountsByRevisionId = next;
|
||||
const commits = Object.fromEntries(entries);
|
||||
commitCountsByRevisionId = mapValues(
|
||||
newCommitsByRevision(ordered, id => commits[id] ?? []),
|
||||
added => added.length,
|
||||
);
|
||||
});
|
||||
});
|
||||
// Per-revision diff stats for the dropdown: one request each, so they are
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { Commit } from "@bindings/repo/Commit";
|
||||
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { orderRevisions, revisionNumbers } from "@app/lib/revisionList";
|
||||
import {
|
||||
newCommitsByRevision,
|
||||
orderRevisions,
|
||||
revisionNumbers,
|
||||
} from "@app/lib/revisionList";
|
||||
import type { RevisionListSettings } from "@app/lib/revisionListSettings";
|
||||
|
||||
import { author, revision } from "./support/cobs";
|
||||
@@ -93,3 +99,23 @@ describe("orderRevisions", () => {
|
||||
expect(ids(input)).toEqual(ids(revisions));
|
||||
});
|
||||
});
|
||||
|
||||
test("newCommitsByRevision keeps only commits not in an earlier revision", () => {
|
||||
const c = (id: string) => ({ id }) as Commit;
|
||||
const commits: Record<string, Commit[]> = {
|
||||
a1: [c("1"), c("2")],
|
||||
b1: [c("1"), c("2"), c("3")],
|
||||
c1: [c("2"), c("4"), c("3"), c("5")],
|
||||
};
|
||||
|
||||
const added = newCommitsByRevision(
|
||||
[{ id: "a1" }, { id: "b1" }, { id: "c1" }],
|
||||
id => commits[id],
|
||||
);
|
||||
|
||||
expect(
|
||||
Object.fromEntries(
|
||||
Object.entries(added).map(([id, list]) => [id, list.map(x => x.id)]),
|
||||
),
|
||||
).toEqual({ a1: ["1", "2"], b1: ["3"], c1: ["4", "5"] });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user