Share the file-tree status mapping

This commit is contained in:
Rūdolfs Ošiņš
2026-08-14 17:30:47 +02:00
parent 3d4fb16281
commit 9196e4f726
2 changed files with 28 additions and 19 deletions
+22
View File
@@ -4,6 +4,7 @@ import type {
} from "@app/components/diffFileHeaderState.svelte";
import type { FileDiff } from "@bindings/diff/FileDiff";
import type { Blob } from "@bindings/source/Blob";
import type { GitStatusEntry } from "@pierre/trees";
import { isIgnoredPath } from "@app/lib/ignoredFiles";
import { invoke } from "@app/lib/invoke";
@@ -33,6 +34,27 @@ export function fileStatusLabel(status: FileStatus): string | undefined {
}
}
/// The changed files in the shape `PierreTree` marks its rows with. A copy reads
/// as an addition, which is what it is on the new side; there is no "copied" for
/// the tree to show.
export function gitStatusEntries(files: FileDiff[]): GitStatusEntry[] {
return files.map((file): GitStatusEntry => {
const path = fileDiffPath(file);
switch (file.status) {
case "added":
return { path, status: "added" };
case "deleted":
return { path, status: "deleted" };
case "modified":
return { path, status: "modified" };
case "moved":
return { path, status: "renamed" };
case "copied":
return { path, status: "added" };
}
});
}
export interface FileMeta {
// Files with no renderable text diff. Pierre has no binary concept and would
// render them as an empty body with a dead expand caret, so the header shows a
+6 -19
View File
@@ -2,10 +2,13 @@
import type { Diff } from "@bindings/diff/Diff";
import type { Commit } from "@bindings/repo/Commit";
import type { RepoInfo } from "@bindings/repo/RepoInfo";
import type { GitStatusEntry } from "@pierre/trees";
import { diffOptions } from "@app/lib/diffOptions.svelte";
import { fileDiffPath, fileMetaOf, fullFileLoader } from "@app/lib/diffText";
import {
fileMetaOf,
fullFileLoader,
gitStatusEntries,
} from "@app/lib/diffText";
import { getDiffText } from "@app/lib/invoke";
import * as router from "@app/lib/router";
import type { SidebarData } from "@app/lib/router/definitions";
@@ -49,23 +52,7 @@
}>();
let allCollapsed = $state(false);
const changedFiles = $derived(
diff.files.map((file): GitStatusEntry => {
const path = fileDiffPath(file);
switch (file.status) {
case "added":
return { path, status: "added" };
case "deleted":
return { path, status: "deleted" };
case "modified":
return { path, status: "modified" };
case "moved":
return { path, status: "renamed" };
case "copied":
return { path, status: "added" };
}
}),
);
const changedFiles = $derived(gitStatusEntries(diff.files));
const treePaths = $derived(changedFiles.map(file => file.path));
const fileMeta = $derived(fileMetaOf(diff.files));