mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Share the file-tree status mapping
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user