@statewalker/vcs-commands 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/add-command.d.ts +32 -0
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/add-patch/add-patch.d.ts +7 -0
- package/dist/commands/add-patch/add-patch.d.ts.map +1 -1
- package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
- package/dist/commands/am/am-command.d.ts +47 -0
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-command.d.ts +2 -0
- package/dist/commands/apply/apply-command.d.ts.map +1 -1
- package/dist/commands/apply/apply-parse.d.ts +7 -0
- package/dist/commands/apply/apply-parse.d.ts.map +1 -1
- package/dist/commands/apply/index.d.ts +1 -1
- package/dist/commands/apply/index.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +303 -8
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/blame-ignore.d.ts +48 -0
- package/dist/commands/blame-ignore.d.ts.map +1 -0
- package/dist/commands/check-mailmap-command.d.ts +49 -0
- package/dist/commands/check-mailmap-command.d.ts.map +1 -0
- package/dist/commands/checkout-command.d.ts +7 -0
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/checkout-paths.d.ts +4 -0
- package/dist/commands/checkout-paths.d.ts.map +1 -1
- package/dist/commands/cherry-command.d.ts +61 -0
- package/dist/commands/cherry-command.d.ts.map +1 -0
- package/dist/commands/cherry-pick-command.d.ts +23 -1
- package/dist/commands/cherry-pick-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +32 -0
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clean-interactive.d.ts +56 -0
- package/dist/commands/clean-interactive.d.ts.map +1 -0
- package/dist/commands/clone-command.d.ts +116 -2
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/commit-command.d.ts +50 -2
- package/dist/commands/commit-command.d.ts.map +1 -1
- package/dist/commands/describe-command.d.ts +71 -64
- package/dist/commands/describe-command.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts +118 -6
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/fetch-command.d.ts +60 -0
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/fetch-multiple-command.d.ts +193 -0
- package/dist/commands/fetch-multiple-command.d.ts.map +1 -0
- package/dist/commands/format-patch-command.d.ts +28 -2
- package/dist/commands/format-patch-command.d.ts.map +1 -1
- package/dist/commands/git-describe.d.ts +77 -4
- package/dist/commands/git-describe.d.ts.map +1 -1
- package/dist/commands/git-hooks.d.ts +15 -1
- package/dist/commands/git-hooks.d.ts.map +1 -1
- package/dist/commands/index.d.ts +12 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +5 -3
- package/dist/commands/init-command.d.ts +89 -0
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/line-log.d.ts +161 -0
- package/dist/commands/line-log.d.ts.map +1 -0
- package/dist/commands/log-command.d.ts +235 -6
- package/dist/commands/log-command.d.ts.map +1 -1
- package/dist/commands/log-graph.d.ts +4 -2
- package/dist/commands/log-graph.d.ts.map +1 -1
- package/dist/commands/log-output.d.ts +66 -1
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/mailmap.d.ts +24 -1
- package/dist/commands/mailmap.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +51 -1
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/merge-drivers.d.ts +2 -0
- package/dist/commands/merge-drivers.d.ts.map +1 -1
- package/dist/commands/merge-strategy-options.d.ts +69 -0
- package/dist/commands/merge-strategy-options.d.ts.map +1 -0
- package/dist/commands/merge-support.d.ts +10 -0
- package/dist/commands/merge-support.d.ts.map +1 -1
- package/dist/commands/message-cleanup.d.ts +2 -0
- package/dist/commands/message-cleanup.d.ts.map +1 -1
- package/dist/commands/name-rev-command.d.ts +65 -0
- package/dist/commands/name-rev-command.d.ts.map +1 -0
- package/dist/commands/name-rev.d.ts +110 -22
- package/dist/commands/name-rev.d.ts.map +1 -1
- package/dist/commands/octopus-merge.d.ts +26 -1
- package/dist/commands/octopus-merge.d.ts.map +1 -1
- package/dist/commands/ort-merge.d.ts +16 -0
- package/dist/commands/ort-merge.d.ts.map +1 -1
- package/dist/commands/ort-recursive.d.ts.map +1 -1
- package/dist/commands/patch-id.d.ts +58 -0
- package/dist/commands/patch-id.d.ts.map +1 -1
- package/dist/commands/pull-command.d.ts +182 -38
- package/dist/commands/pull-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +65 -0
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/range-diff/index.d.ts +4 -0
- package/dist/commands/range-diff/index.d.ts.map +1 -0
- package/dist/commands/range-diff/linear-assignment.d.ts +27 -0
- package/dist/commands/range-diff/linear-assignment.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff-command.d.ts +121 -0
- package/dist/commands/range-diff/range-diff-command.d.ts.map +1 -0
- package/dist/commands/range-diff/range-diff.d.ts +106 -0
- package/dist/commands/range-diff/range-diff.d.ts.map +1 -0
- package/dist/commands/read-tree-command.d.ts +14 -0
- package/dist/commands/read-tree-command.d.ts.map +1 -1
- package/dist/commands/rebase-command.d.ts +21 -2
- package/dist/commands/rebase-command.d.ts.map +1 -1
- package/dist/commands/remerge-diff.d.ts +59 -0
- package/dist/commands/remerge-diff.d.ts.map +1 -0
- package/dist/commands/remote-command.d.ts +41 -0
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/remote-show-command.d.ts +204 -0
- package/dist/commands/remote-show-command.d.ts.map +1 -0
- package/dist/commands/reset-command.d.ts +19 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/restore-command.d.ts +7 -0
- package/dist/commands/restore-command.d.ts.map +1 -1
- package/dist/commands/rev-list-command.d.ts +75 -3
- package/dist/commands/rev-list-command.d.ts.map +1 -1
- package/dist/commands/revert-command.d.ts +22 -1
- package/dist/commands/revert-command.d.ts.map +1 -1
- package/dist/commands/revision-range.d.ts +2 -0
- package/dist/commands/revision-range.d.ts.map +1 -1
- package/dist/commands/sequencer-pick.d.ts +102 -1
- package/dist/commands/sequencer-pick.d.ts.map +1 -1
- package/dist/commands/sequencer-support.d.ts +10 -1
- package/dist/commands/sequencer-support.d.ts.map +1 -1
- package/dist/commands/shortlog-command.d.ts +109 -0
- package/dist/commands/shortlog-command.d.ts.map +1 -0
- package/dist/commands/shortlog.d.ts +151 -0
- package/dist/commands/shortlog.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +31 -2
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-commands.d.ts +90 -2
- package/dist/commands/submodule-commands.d.ts.map +1 -1
- package/dist/commands/submodule-fetch.d.ts +149 -0
- package/dist/commands/submodule-fetch.d.ts.map +1 -0
- package/dist/commands/submodule-model.d.ts +8 -0
- package/dist/commands/submodule-model.d.ts.map +1 -1
- package/dist/commands/submodule-unpack.d.ts +120 -0
- package/dist/commands/submodule-unpack.d.ts.map +1 -0
- package/dist/commands/submodule-update-command.d.ts +8 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/subtree-shift.d.ts +27 -0
- package/dist/commands/subtree-shift.d.ts.map +1 -0
- package/dist/commands/switch-command.d.ts +3 -0
- package/dist/commands/switch-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +2 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -1
- package/dist/{commands-ISM52N0n.js → commands-CNvli5bl.js} +39426 -61169
- package/dist/errors/command-errors.d.ts +25 -0
- package/dist/errors/command-errors.d.ts.map +1 -1
- package/dist/errors/index.js +29 -1
- package/dist/fsck-CPeDh9fh.js +5138 -0
- package/dist/git-command.d.ts +31 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +97 -1
- package/dist/git.d.ts.map +1 -1
- package/dist/guarded-transport-command.d.ts +82 -0
- package/dist/guarded-transport-command.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/remote-transport-CCmBadm-.js +1606 -0
- package/dist/rename/detect-renames.d.ts +20 -0
- package/dist/rename/detect-renames.d.ts.map +1 -1
- package/dist/rename/diffcore-break.d.ts +51 -0
- package/dist/rename/diffcore-break.d.ts.map +1 -0
- package/dist/rename/index.d.ts +1 -0
- package/dist/rename/index.d.ts.map +1 -1
- package/dist/results/blame-format.d.ts +62 -1
- package/dist/results/blame-format.d.ts.map +1 -1
- package/dist/results/clone-result.d.ts +9 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-dirstat.d.ts +36 -0
- package/dist/results/diff-dirstat.d.ts.map +1 -0
- package/dist/results/diff-entry.d.ts +10 -0
- package/dist/results/diff-entry.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/diff-output.d.ts +18 -0
- package/dist/results/diff-output.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +12 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.d.ts +2 -0
- package/dist/results/index.d.ts.map +1 -1
- package/dist/results/index.js +2 -2
- package/dist/results/init-result.d.ts +8 -1
- package/dist/results/init-result.d.ts.map +1 -1
- package/dist/results/line-range-hunks.d.ts +27 -0
- package/dist/results/line-range-hunks.d.ts.map +1 -0
- package/dist/results/merge-result.d.ts +8 -1
- package/dist/results/merge-result.d.ts.map +1 -1
- package/dist/results/pull-result.d.ts +11 -0
- package/dist/results/pull-result.d.ts.map +1 -1
- package/dist/results/push-result.d.ts +5 -0
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +1 -1
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/results-BDuEgdLU.js +46847 -0
- package/dist/transport-command.d.ts +14 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/commands/add-command.ts +115 -0
- package/src/commands/add-patch/add-patch.ts +8 -0
- package/src/commands/add-patch/patch-backend.ts +20 -2
- package/src/commands/am/am-command.ts +138 -4
- package/src/commands/apply/apply-command.ts +52 -9
- package/src/commands/apply/apply-parse.ts +10 -0
- package/src/commands/apply/index.ts +8 -1
- package/src/commands/blame-command.ts +1450 -51
- package/src/commands/blame-ignore.ts +307 -0
- package/src/commands/check-mailmap-command.ts +129 -0
- package/src/commands/checkout-command.ts +97 -12
- package/src/commands/checkout-paths.ts +28 -0
- package/src/commands/cherry-command.ts +187 -0
- package/src/commands/cherry-pick-command.ts +42 -1
- package/src/commands/clean-command.ts +92 -12
- package/src/commands/clean-interactive.ts +522 -0
- package/src/commands/clone-command.ts +596 -44
- package/src/commands/commit-command.ts +180 -47
- package/src/commands/describe-command.ts +341 -254
- package/src/commands/diff-command.ts +616 -56
- package/src/commands/fetch-command.ts +353 -6
- package/src/commands/fetch-multiple-command.ts +665 -0
- package/src/commands/format-patch-command.ts +189 -77
- package/src/commands/git-describe.ts +456 -217
- package/src/commands/git-hooks.ts +42 -3
- package/src/commands/index.ts +17 -0
- package/src/commands/init-command.ts +603 -49
- package/src/commands/line-log.ts +931 -0
- package/src/commands/log-command.ts +1414 -177
- package/src/commands/log-graph.ts +6 -3
- package/src/commands/log-output.ts +173 -10
- package/src/commands/mailmap.ts +41 -5
- package/src/commands/merge-command.ts +274 -16
- package/src/commands/merge-drivers.ts +3 -0
- package/src/commands/merge-strategy-options.ts +224 -0
- package/src/commands/merge-support.ts +101 -21
- package/src/commands/message-cleanup.ts +1 -1
- package/src/commands/name-rev-command.ts +184 -0
- package/src/commands/name-rev.ts +700 -109
- package/src/commands/octopus-merge.ts +35 -11
- package/src/commands/ort-merge.ts +41 -7
- package/src/commands/ort-recursive.ts +40 -2
- package/src/commands/patch-id.ts +109 -0
- package/src/commands/pull-command.ts +718 -224
- package/src/commands/push-command.ts +353 -3
- package/src/commands/range-diff/index.ts +3 -0
- package/src/commands/range-diff/linear-assignment.ts +203 -0
- package/src/commands/range-diff/range-diff-command.ts +433 -0
- package/src/commands/range-diff/range-diff.ts +617 -0
- package/src/commands/read-tree-command.ts +74 -3
- package/src/commands/rebase-command.ts +141 -65
- package/src/commands/remerge-diff.ts +241 -0
- package/src/commands/remote-command.ts +98 -10
- package/src/commands/remote-show-command.ts +836 -0
- package/src/commands/reset-command.ts +78 -3
- package/src/commands/restore-command.ts +15 -0
- package/src/commands/rev-list-command.ts +187 -11
- package/src/commands/revert-command.ts +41 -1
- package/src/commands/revision-range.ts +3 -1
- package/src/commands/sequencer-pick.ts +323 -29
- package/src/commands/sequencer-support.ts +164 -2
- package/src/commands/shortlog-command.ts +354 -0
- package/src/commands/shortlog.ts +361 -0
- package/src/commands/show-command.ts +2 -1
- package/src/commands/status-command.ts +115 -25
- package/src/commands/status-format.ts +1 -1
- package/src/commands/submodule-commands.ts +321 -3
- package/src/commands/submodule-fetch.ts +789 -0
- package/src/commands/submodule-model.ts +9 -1
- package/src/commands/submodule-unpack.ts +265 -0
- package/src/commands/submodule-update-command.ts +39 -5
- package/src/commands/subtree-shift.ts +215 -0
- package/src/commands/switch-command.ts +9 -0
- package/src/commands/tree-restore.ts +6 -1
- package/src/commands/worktree-overwrite-checks.ts +5 -0
- package/src/errors/command-errors.ts +35 -0
- package/src/git-command.ts +87 -1
- package/src/git.ts +146 -0
- package/src/guarded-transport-command.ts +171 -0
- package/src/index.ts +1 -0
- package/src/rename/detect-renames.ts +42 -8
- package/src/rename/diffcore-break.ts +166 -0
- package/src/rename/index.ts +1 -0
- package/src/results/blame-format.ts +268 -43
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-dirstat.ts +117 -0
- package/src/results/diff-entry.ts +12 -0
- package/src/results/diff-formatter.ts +1 -0
- package/src/results/diff-output.ts +127 -2
- package/src/results/fetch-result.ts +12 -1
- package/src/results/index.ts +2 -0
- package/src/results/init-result.ts +10 -1
- package/src/results/line-range-hunks.ts +126 -0
- package/src/results/merge-result.ts +9 -0
- package/src/results/pull-result.ts +7 -0
- package/src/results/push-result.ts +5 -0
- package/src/results/status-result.ts +2 -2
- package/src/transport-command.ts +34 -3
- package/dist/fsck-DLRpbwTj.js +0 -13405
- package/dist/results-TB2IJ64h.js +0 -4700
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Commit, ObjectId, PersonIdent } from "@statewalker/vcs-core";
|
|
2
2
|
import { DEFAULT_BIG_FILE_THRESHOLD } from "@statewalker/vcs-core";
|
|
3
3
|
import {
|
|
4
|
+
ByteLines,
|
|
4
5
|
type InternedText,
|
|
5
6
|
LineInterner,
|
|
6
7
|
parseGitBool,
|
|
@@ -9,7 +10,11 @@ import {
|
|
|
9
10
|
type XdiffAlgorithm,
|
|
10
11
|
type XdiffOptions,
|
|
11
12
|
xdiffHunks,
|
|
13
|
+
xdlHashRecord,
|
|
12
14
|
} from "@statewalker/vcs-utils";
|
|
15
|
+
import { decodeGitPath, encodeGitPath } from "@statewalker/vcs-utils/encoding";
|
|
16
|
+
import { computeObjectId } from "@statewalker/vcs-utils/pack";
|
|
17
|
+
import { expandUserPath } from "@statewalker/vcs-working-tree";
|
|
13
18
|
|
|
14
19
|
import { RefNotFoundError } from "../errors/ref-errors.js";
|
|
15
20
|
import { GitCommand } from "../git-command.js";
|
|
@@ -20,11 +25,26 @@ import {
|
|
|
20
25
|
detectRenames,
|
|
21
26
|
GIT_MAX_SCORE,
|
|
22
27
|
} from "../rename/index.js";
|
|
28
|
+
import {
|
|
29
|
+
type Fingerprint,
|
|
30
|
+
guessLineBlames,
|
|
31
|
+
type LineBlame,
|
|
32
|
+
lineFingerprints,
|
|
33
|
+
} from "./blame-ignore.js";
|
|
34
|
+
import { parseGitColor } from "./config-value-types.js";
|
|
23
35
|
import { abbrevLengths } from "./core-config.js";
|
|
36
|
+
import { localTimezoneOffset } from "./git-date.js";
|
|
37
|
+
import { hostEnvironmentOf } from "./git-ident.js";
|
|
38
|
+
import { type Mailmap, readMailmapFile, readRepositoryMailmap } from "./mailmap.js";
|
|
39
|
+
import { OperationState } from "./merge-support.js";
|
|
24
40
|
import { canonicalObjectId } from "./object-id-input.js";
|
|
25
41
|
|
|
26
42
|
/** Line bytes the interner holds before blame starts a new one (see `setInternerByteLimit`) */
|
|
27
43
|
const DEFAULT_INTERNER_BYTE_LIMIT = 64 * 1024 * 1024;
|
|
44
|
+
/** Bytes of the files looked in for copies kept interned between commits */
|
|
45
|
+
const COPY_SOURCE_CACHE_BYTES = 16 * 1024 * 1024;
|
|
46
|
+
/** Bytes of line hashes of the files looked in for copies kept between commits */
|
|
47
|
+
const COPY_HASH_CACHE_BYTES = 32 * 1024 * 1024;
|
|
28
48
|
|
|
29
49
|
/**
|
|
30
50
|
* A single blame entry - represents authorship of one or more consecutive lines.
|
|
@@ -49,6 +69,16 @@ export interface BlameEntry {
|
|
|
49
69
|
previous?: { commitId: ObjectId; path: string };
|
|
50
70
|
/** A boundary commit (a root commit, unless `setShowRoot(true)`): `^` in git's output */
|
|
51
71
|
boundary?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Lines an ignored commit changed, blamed on the line of its parent they resemble (`?` in
|
|
74
|
+
* git's output and `ignored` in the porcelain ones under `blame.markIgnoredLines`)
|
|
75
|
+
*/
|
|
76
|
+
ignored?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Lines an ignored commit changed that resemble no line of its parent, so stay its own
|
|
79
|
+
* (`*` and `unblamable` under `blame.markUnblamableLines`)
|
|
80
|
+
*/
|
|
81
|
+
unblamable?: boolean;
|
|
52
82
|
}
|
|
53
83
|
|
|
54
84
|
/**
|
|
@@ -85,8 +115,23 @@ export interface BlameResult {
|
|
|
85
115
|
* line ranges asked for
|
|
86
116
|
*/
|
|
87
117
|
entries: BlameEntry[];
|
|
88
|
-
/** The blamed file's content at the start commit */
|
|
118
|
+
/** The blamed file's content at the start commit (`--reverse`: at the commit reversed from) */
|
|
89
119
|
content?: Uint8Array;
|
|
120
|
+
/** Whether git's output marks ignored lines (`blame.markIgnoredLines`, `setMarkIgnoredLines`) */
|
|
121
|
+
markIgnoredLines?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether git's output marks unblamable lines (`blame.markUnblamableLines`,
|
|
124
|
+
* `setMarkUnblamableLines`)
|
|
125
|
+
*/
|
|
126
|
+
markUnblamableLines?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* The entries in the order blame found them, before sorting and coalescing: what
|
|
129
|
+
* `git blame --incremental` prints (`formatBlameIncremental`). Each entry's `boundary` is
|
|
130
|
+
* what git knew when it printed the entry.
|
|
131
|
+
*/
|
|
132
|
+
incremental?: BlameEntry[];
|
|
133
|
+
/** The output settings of the repository's configuration (defaults of `formatBlame`) */
|
|
134
|
+
output?: BlameOutputConfig;
|
|
90
135
|
/**
|
|
91
136
|
* Get the blame entry for a specific line (1-based).
|
|
92
137
|
*
|
|
@@ -137,8 +182,60 @@ export interface BlameResult {
|
|
|
137
182
|
autoAbbrev?(): Promise<number>;
|
|
138
183
|
}
|
|
139
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The output settings `git blame` reads from the configuration (`git_blame_config`), which
|
|
187
|
+
* `formatBlame` takes as defaults of its options
|
|
188
|
+
*/
|
|
189
|
+
export interface BlameOutputConfig {
|
|
190
|
+
/** `blame.date`: the date mode (`--date`), as written */
|
|
191
|
+
date?: string;
|
|
192
|
+
/** `blame.showEmail` (`-e`) */
|
|
193
|
+
showEmail?: boolean;
|
|
194
|
+
/** `blame.blankBoundary` (`-b`) */
|
|
195
|
+
blankBoundary?: boolean;
|
|
196
|
+
/** `blame.coloring=repeatedLines` (`--color-lines`) */
|
|
197
|
+
colorLines?: boolean;
|
|
198
|
+
/** `blame.coloring=highlightRecent` (`--color-by-age`) */
|
|
199
|
+
colorByAge?: boolean;
|
|
200
|
+
/** `color.blame.repeatedLines`: the escape sequence of the color (default cyan) */
|
|
201
|
+
repeatedLinesColor?: string;
|
|
202
|
+
/** `color.blame.highlightRecent`: `<color>,<date>,<color>,...` as written */
|
|
203
|
+
highlightRecent?: string;
|
|
204
|
+
/** Warnings git prints while reading these settings (invalid values it skips) */
|
|
205
|
+
warnings?: string[];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The buffer blamed instead of the file of the start commit (`setContents`): git's fake
|
|
210
|
+
* working-tree commit on top of the start commit
|
|
211
|
+
*/
|
|
212
|
+
export interface BlameContentsOptions {
|
|
213
|
+
/**
|
|
214
|
+
* The `--contents` argument, named in the fake commit's summary (`-` reads "standard
|
|
215
|
+
* input", the default)
|
|
216
|
+
*/
|
|
217
|
+
name?: string;
|
|
218
|
+
/**
|
|
219
|
+
* The working tree's file blamed as `git blame <path>` without a revision does: the commit
|
|
220
|
+
* is "Not Committed Yet" instead of "External file (--contents)"
|
|
221
|
+
*/
|
|
222
|
+
workingTree?: boolean;
|
|
223
|
+
/** The fake commit's time in seconds (default now) */
|
|
224
|
+
time?: number;
|
|
225
|
+
/** Its zone, `+HHMM` (default the local zone at `time`) */
|
|
226
|
+
tzOffset?: string;
|
|
227
|
+
/**
|
|
228
|
+
* The file's mode, as git's `canon_mode` of the `--contents` file's stat or the working
|
|
229
|
+
* tree file's lstat (`120000` for a link, whose content is its target); default, as for
|
|
230
|
+
* standard input, the index entry's mode at the path, else `100644`
|
|
231
|
+
*/
|
|
232
|
+
mode?: number;
|
|
233
|
+
}
|
|
234
|
+
|
|
140
235
|
/** A version of the file in a commit (`struct blame_origin`) */
|
|
141
236
|
interface Origin {
|
|
237
|
+
/** Creation order: stands for the pointer order git sorts suspects by (`compare_blame_suspect`) */
|
|
238
|
+
seq: number;
|
|
142
239
|
commitId: ObjectId;
|
|
143
240
|
path: string;
|
|
144
241
|
blobId: ObjectId;
|
|
@@ -149,8 +246,12 @@ interface Origin {
|
|
|
149
246
|
guilty: boolean;
|
|
150
247
|
/** The next origin of the same commit */
|
|
151
248
|
next: Origin | null;
|
|
249
|
+
/** The previous origin of the same commit (the list is doubly linked to move one in O(1)) */
|
|
250
|
+
prev: Origin | null;
|
|
152
251
|
/** The blob's lines (split and hashed once), while the origin is compared */
|
|
153
252
|
lines?: InternedText;
|
|
253
|
+
/** The lines' fingerprints, while an ignored commit's origin passes blame */
|
|
254
|
+
fingerprints?: Fingerprint[];
|
|
154
255
|
}
|
|
155
256
|
|
|
156
257
|
/** A run of lines (`struct blame_entry`), 0-based */
|
|
@@ -162,6 +263,10 @@ interface Entry {
|
|
|
162
263
|
/** First line in the suspect's file */
|
|
163
264
|
sLno: number;
|
|
164
265
|
numLines: number;
|
|
266
|
+
/** Blamed on a parent of an ignored commit by resemblance */
|
|
267
|
+
ignored: boolean;
|
|
268
|
+
/** Changed by an ignored commit and like no line of its parent */
|
|
269
|
+
unblamable: boolean;
|
|
165
270
|
}
|
|
166
271
|
|
|
167
272
|
/** Something with a `next` link: a list head or an entry (`struct blame_entry **`) */
|
|
@@ -172,13 +277,46 @@ interface Slot {
|
|
|
172
277
|
interface CommitState {
|
|
173
278
|
commit: Commit;
|
|
174
279
|
origins: Origin | null;
|
|
280
|
+
/** The origins by path (git's list is searched linearly; `-C -C -C` makes it long) */
|
|
281
|
+
originsByPath: Map<string, Origin>;
|
|
175
282
|
uninteresting: boolean;
|
|
176
283
|
}
|
|
177
284
|
|
|
178
285
|
const S_IFMT = 0o170000;
|
|
179
286
|
const TREE_MODE = 0o040000;
|
|
287
|
+
const GITLINK_MODE = 0o160000;
|
|
288
|
+
/** blame.h's `BLAME_DEFAULT_MOVE_SCORE` and `BLAME_DEFAULT_COPY_SCORE` */
|
|
289
|
+
const BLAME_DEFAULT_MOVE_SCORE = 20;
|
|
290
|
+
const BLAME_DEFAULT_COPY_SCORE = 40;
|
|
180
291
|
const INT_MAX = Number.MAX_SAFE_INTEGER;
|
|
181
292
|
|
|
293
|
+
/** Whether any line hash is among `wanted` */
|
|
294
|
+
function sharesLine(hashes: Int32Array, wanted: Set<number>): boolean {
|
|
295
|
+
for (let i = 0; i < hashes.length; i++) if (wanted.has(hashes[i])) return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** An origin moved to the front of its commit's list (`get_origin` finding it) */
|
|
300
|
+
function moveOriginToFront(st: CommitState, o: Origin): void {
|
|
301
|
+
if (!o.prev) return;
|
|
302
|
+
o.prev.next = o.next;
|
|
303
|
+
if (o.next) o.next.prev = o.prev;
|
|
304
|
+
o.prev = null;
|
|
305
|
+
o.next = st.origins;
|
|
306
|
+
if (st.origins) st.origins.prev = o;
|
|
307
|
+
st.origins = o;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** An origin no entry refers to taken off its commit's list (`blame_origin_decref` freeing it) */
|
|
311
|
+
function unlinkOrigin(st: CommitState, o: Origin): void {
|
|
312
|
+
if (o.prev) o.prev.next = o.next;
|
|
313
|
+
else if (st.origins === o) st.origins = o.next;
|
|
314
|
+
if (o.next) o.next.prev = o.prev;
|
|
315
|
+
o.prev = null;
|
|
316
|
+
o.next = null;
|
|
317
|
+
if (st.originsByPath.get(o.path) === o) st.originsByPath.delete(o.path);
|
|
318
|
+
}
|
|
319
|
+
|
|
182
320
|
/** `reverse_blame`: `head` reversed, ending in `tail` */
|
|
183
321
|
function reverseBlame(head: Entry | null, tail: Entry | null): Entry | null {
|
|
184
322
|
let h = head;
|
|
@@ -223,20 +361,136 @@ function splitBlameAt(e: Entry, len: number, suspect: Origin): Entry {
|
|
|
223
361
|
lno: e.lno + len,
|
|
224
362
|
sLno: e.sLno + len,
|
|
225
363
|
numLines: e.numLines - len,
|
|
364
|
+
ignored: e.ignored,
|
|
365
|
+
unblamable: e.unblamable,
|
|
226
366
|
};
|
|
227
367
|
e.numLines = len;
|
|
228
368
|
return n;
|
|
229
369
|
}
|
|
230
370
|
|
|
231
|
-
/**
|
|
371
|
+
/** One part of a split entry (the on-stack `struct blame_entry` of `split_overlap`) */
|
|
372
|
+
interface Part {
|
|
373
|
+
suspect: Origin | null;
|
|
374
|
+
lno: number;
|
|
375
|
+
sLno: number;
|
|
376
|
+
numLines: number;
|
|
377
|
+
ignored: boolean;
|
|
378
|
+
unblamable: boolean;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** `struct blame_entry split[3]`: before the chunk, the chunk the parent takes, after it */
|
|
382
|
+
type Split = [Part, Part, Part];
|
|
383
|
+
|
|
384
|
+
const emptyPart = (e?: Entry): Part => ({
|
|
385
|
+
suspect: null,
|
|
386
|
+
lno: 0,
|
|
387
|
+
sLno: 0,
|
|
388
|
+
numLines: 0,
|
|
389
|
+
ignored: e?.ignored ?? false,
|
|
390
|
+
unblamable: e?.unblamable ?? false,
|
|
391
|
+
});
|
|
392
|
+
const emptySplit = (e?: Entry): Split => [emptyPart(e), emptyPart(e), emptyPart(e)];
|
|
393
|
+
|
|
394
|
+
/** A queue appended at its tail (`struct blame_entry ***`); the tail's `next` is set at the end */
|
|
395
|
+
interface Queue {
|
|
396
|
+
tail: Slot;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** git's `split_overlap`: `e` cut where `[tlno, same)` (its suspect's lines) came from `parent` */
|
|
400
|
+
function splitOverlap(e: Entry, tlno: number, plno: number, same: number, parent: Origin): Split {
|
|
401
|
+
const split = emptySplit(e);
|
|
402
|
+
let chunkEnd: number;
|
|
403
|
+
if (e.sLno < tlno) {
|
|
404
|
+
// a part before the chunk, not blamed on the parent
|
|
405
|
+
split[0] = {
|
|
406
|
+
suspect: e.suspect,
|
|
407
|
+
lno: e.lno,
|
|
408
|
+
sLno: e.sLno,
|
|
409
|
+
numLines: tlno - e.sLno,
|
|
410
|
+
ignored: e.ignored,
|
|
411
|
+
unblamable: e.unblamable,
|
|
412
|
+
};
|
|
413
|
+
split[1].lno = e.lno + tlno - e.sLno;
|
|
414
|
+
split[1].sLno = plno;
|
|
415
|
+
} else {
|
|
416
|
+
split[1].lno = e.lno;
|
|
417
|
+
split[1].sLno = plno + (e.sLno - tlno);
|
|
418
|
+
}
|
|
419
|
+
if (same < e.sLno + e.numLines) {
|
|
420
|
+
// a part after the chunk, not blamed on the parent
|
|
421
|
+
split[2] = {
|
|
422
|
+
suspect: e.suspect,
|
|
423
|
+
lno: e.lno + (same - e.sLno),
|
|
424
|
+
sLno: same,
|
|
425
|
+
numLines: e.sLno + e.numLines - same,
|
|
426
|
+
ignored: e.ignored,
|
|
427
|
+
unblamable: e.unblamable,
|
|
428
|
+
};
|
|
429
|
+
chunkEnd = split[2].lno;
|
|
430
|
+
} else chunkEnd = e.lno + e.numLines;
|
|
431
|
+
split[1].numLines = chunkEnd - split[1].lno;
|
|
432
|
+
if (split[1].numLines >= 1) split[1].suspect = parent;
|
|
433
|
+
return split;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** git's `add_blame_entry`: a new entry from `src` appended */
|
|
437
|
+
function addBlameEntry(queue: Queue, src: Part): void {
|
|
438
|
+
const e: Entry = {
|
|
439
|
+
next: null,
|
|
440
|
+
suspect: src.suspect as Origin,
|
|
441
|
+
lno: src.lno,
|
|
442
|
+
sLno: src.sLno,
|
|
443
|
+
numLines: src.numLines,
|
|
444
|
+
ignored: src.ignored,
|
|
445
|
+
unblamable: src.unblamable,
|
|
446
|
+
};
|
|
447
|
+
queue.tail.next = e;
|
|
448
|
+
queue.tail = e;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** git's `dup_entry`: `dst` takes `src`'s place and is appended */
|
|
452
|
+
function dupEntry(queue: Queue, dst: Entry, src: Part): void {
|
|
453
|
+
dst.suspect = src.suspect as Origin;
|
|
454
|
+
dst.lno = src.lno;
|
|
455
|
+
dst.sLno = src.sLno;
|
|
456
|
+
dst.numLines = src.numLines;
|
|
457
|
+
dst.ignored = src.ignored;
|
|
458
|
+
dst.unblamable = src.unblamable;
|
|
459
|
+
queue.tail.next = dst;
|
|
460
|
+
queue.tail = dst;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** git's `split_blame`: the parts of `e` queued to the parent's (`blamed`) and its own lists */
|
|
464
|
+
function splitBlame(blamed: Queue, unblamed: Queue, split: Split, e: Entry): void {
|
|
465
|
+
if (split[0].suspect && split[2].suspect) {
|
|
466
|
+
dupEntry(unblamed, e, split[0]);
|
|
467
|
+
addBlameEntry(unblamed, split[2]);
|
|
468
|
+
addBlameEntry(blamed, split[1]);
|
|
469
|
+
} else if (!split[0].suspect && !split[2].suspect) {
|
|
470
|
+
dupEntry(blamed, e, split[1]);
|
|
471
|
+
} else if (split[0].suspect) {
|
|
472
|
+
dupEntry(unblamed, e, split[0]);
|
|
473
|
+
addBlameEntry(blamed, split[1]);
|
|
474
|
+
} else {
|
|
475
|
+
dupEntry(blamed, e, split[1]);
|
|
476
|
+
addBlameEntry(unblamed, split[2]);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* A priority queue of commits: newest committer date first (oldest first in reverse, as
|
|
482
|
+
* `compare_commits_by_reverse_commit_date`), ties first in, first out
|
|
483
|
+
*/
|
|
232
484
|
class CommitQueue {
|
|
233
485
|
private heap: Array<{ id: ObjectId; date: number; ctr: number }> = [];
|
|
234
486
|
private ctr = 0;
|
|
235
487
|
|
|
488
|
+
constructor(private readonly reverse = false) {}
|
|
489
|
+
|
|
236
490
|
private less(i: number, j: number): boolean {
|
|
237
491
|
const a = this.heap[i];
|
|
238
492
|
const b = this.heap[j];
|
|
239
|
-
if (a.date !== b.date) return a.date > b.date;
|
|
493
|
+
if (a.date !== b.date) return this.reverse ? a.date < b.date : a.date > b.date;
|
|
240
494
|
return a.ctr < b.ctr;
|
|
241
495
|
}
|
|
242
496
|
|
|
@@ -252,6 +506,16 @@ class CommitQueue {
|
|
|
252
506
|
}
|
|
253
507
|
}
|
|
254
508
|
|
|
509
|
+
/** The ids queued, in no particular order */
|
|
510
|
+
ids(): ObjectId[] {
|
|
511
|
+
return this.heap.map((e) => e.id);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** The date of the commit `get` returns next */
|
|
515
|
+
peekDate(): number | undefined {
|
|
516
|
+
return this.heap[0]?.date;
|
|
517
|
+
}
|
|
518
|
+
|
|
255
519
|
get(): ObjectId | undefined {
|
|
256
520
|
const h = this.heap;
|
|
257
521
|
if (h.length === 0) return undefined;
|
|
@@ -286,8 +550,14 @@ class CommitQueue {
|
|
|
286
550
|
* are its own. A parent with the same blob takes all lines. Root commits are boundaries
|
|
287
551
|
* unless `setShowRoot(true)` (`blame.showRoot`).
|
|
288
552
|
*
|
|
289
|
-
*
|
|
290
|
-
* are
|
|
553
|
+
* Lines moved within the file (`-M`, `setDetectMoves`) and copied from other files (`-C` up
|
|
554
|
+
* to three times, `setDetectCopies`) are found as git's `find_move_in_parent` and
|
|
555
|
+
* `find_copy_in_parent` find them, and names and emails go through the mailmap
|
|
556
|
+
* (`setUseMailmap`). Ignored revisions (`setIgnoreRevs`, `setIgnoreRevsFiles`,
|
|
557
|
+
* `blame.ignoreRevsFile`) pass their changed lines to the parent lines they resemble, by
|
|
558
|
+
* git's fingerprint matching (`guess_line_blames`); `setReverse` blames each line of an old
|
|
559
|
+
* version on the last commit it existed in (`--reverse`), and `setFirstParent` follows
|
|
560
|
+
* first parents only.
|
|
291
561
|
*
|
|
292
562
|
* @example
|
|
293
563
|
* ```typescript
|
|
@@ -314,8 +584,60 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
314
584
|
private lineRanges: Array<[number, number]> = [];
|
|
315
585
|
private diffOptions: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> = {};
|
|
316
586
|
private renameCountLastSpan?: boolean;
|
|
587
|
+
/** `-M`: look for lines moved within the file (`PICKAXE_BLAME_MOVE`) */
|
|
588
|
+
private detectMoves = false;
|
|
589
|
+
/** `-C` given this many times (`PICKAXE_BLAME_COPY`, `_HARDER`, `_HARDEST`) */
|
|
590
|
+
private copyLevel = 0;
|
|
591
|
+
private moveScore = BLAME_DEFAULT_MOVE_SCORE;
|
|
592
|
+
private copyScore = BLAME_DEFAULT_COPY_SCORE;
|
|
593
|
+
private useMailmap = true;
|
|
594
|
+
private ignoreRevs: string[] = [];
|
|
595
|
+
private ignoreRevsFiles: string[] = [];
|
|
596
|
+
private markIgnoredLines?: boolean;
|
|
597
|
+
private markUnblamableLines?: boolean;
|
|
598
|
+
/** `:(optional)` paths in the configuration (git 2.52+) */
|
|
599
|
+
private optionalPaths = true;
|
|
600
|
+
/** `--reverse`: the commit whose lines are followed forward */
|
|
601
|
+
private reverseFrom?: ObjectId;
|
|
602
|
+
private firstParent = false;
|
|
603
|
+
/** The buffer blamed instead of the start commit's file (`--contents`) */
|
|
604
|
+
private contents?: { content: Uint8Array } & BlameContentsOptions;
|
|
605
|
+
/** Commits older than this (committer time, seconds) are boundaries (`--since`) */
|
|
606
|
+
private since?: number;
|
|
607
|
+
/** Commits `--since` marked uninteresting before they were loaded */
|
|
608
|
+
private sinceUninteresting = new Set<ObjectId>();
|
|
609
|
+
/** Blobs that exist only here (the `--contents` buffer: git's `odb_pretend_object`) */
|
|
610
|
+
private pretend = new Map<ObjectId, Uint8Array>();
|
|
611
|
+
/** The entries in the order they were found guilty (`--incremental`) */
|
|
612
|
+
private guilty: Array<{ entry: Entry; origin: Origin; boundary: boolean }> = [];
|
|
613
|
+
/** The commits blamed lines pass to from each commit in reverse (`revs->children`) */
|
|
614
|
+
private children = new Map<ObjectId, ObjectId[]>();
|
|
615
|
+
/** The commits the reverse walk found uninteresting (boundaries) */
|
|
616
|
+
private reverseUninteresting = new Set<ObjectId>();
|
|
617
|
+
/** The commits whose changes are ignored (`sb->ignore_list`) */
|
|
618
|
+
private ignoreList = new Set<ObjectId>();
|
|
619
|
+
|
|
620
|
+
/** The blamed file at the start commit, its line starts and alphanumerics before each line */
|
|
621
|
+
private finalContent: Uint8Array = new Uint8Array(0);
|
|
622
|
+
private finalStarts: Int32Array = new Int32Array(1);
|
|
623
|
+
private finalAlnum: Int32Array = new Int32Array(1);
|
|
624
|
+
private originSeq = 0;
|
|
625
|
+
/** Files looked in for copies, interned, the most recently used last (`copySourceText`) */
|
|
626
|
+
private copySources = new Map<ObjectId, InternedText>();
|
|
627
|
+
private copySourceBytes = 0;
|
|
628
|
+
/** Line hashes of the files looked in for copies (null: over the big file threshold) */
|
|
629
|
+
private copyHashes = new Map<ObjectId, Int32Array | null>();
|
|
630
|
+
private copyHashBytes = 0;
|
|
631
|
+
private copyHashCacheBytes = COPY_HASH_CACHE_BYTES;
|
|
632
|
+
private copySourceCacheBytes = COPY_SOURCE_CACHE_BYTES;
|
|
633
|
+
/** The hash of each line of the final file (`lineHashesOf`) */
|
|
634
|
+
private finalHashes: Int32Array = new Int32Array(0);
|
|
317
635
|
|
|
318
636
|
private states = new Map<ObjectId, CommitState>();
|
|
637
|
+
/** The `--contents` buffer's blob and mode */
|
|
638
|
+
private fakeEntry?: { id: ObjectId; mode: number };
|
|
639
|
+
/** The index's files with the `--contents` buffer at its path (the fake commit's "tree") */
|
|
640
|
+
private fakeFiles?: Map<string, { id: ObjectId; mode: number }>;
|
|
319
641
|
/** Numbers the lines of every version compared, so each is split and hashed once */
|
|
320
642
|
private interner?: LineInterner;
|
|
321
643
|
|
|
@@ -410,19 +732,149 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
410
732
|
}
|
|
411
733
|
|
|
412
734
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
735
|
+
* Find lines moved or copied within the file (`-M[<num>]`): lines a commit moved are blamed
|
|
736
|
+
* on the commit that wrote them. A block is taken when it has more than `score`
|
|
737
|
+
* alphanumeric characters (default 20; 0 keeps the default, as git's).
|
|
738
|
+
*/
|
|
739
|
+
setDetectMoves(detect: boolean, score?: number): this {
|
|
740
|
+
this.checkCallable();
|
|
741
|
+
this.detectMoves = detect;
|
|
742
|
+
if (score) this.moveScore = score;
|
|
743
|
+
return this;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Find lines copied from other files (`-C[<num>]` given `level` times; any level also
|
|
748
|
+
* finds moves): 1 looks in the files the commit changed, 2 also in every file of the parent
|
|
749
|
+
* when the blamed file was created or renamed, 3 in every file of the parent always. A block
|
|
750
|
+
* is taken when it has more than `score` alphanumeric characters (default 40; 0 keeps the
|
|
751
|
+
* default).
|
|
752
|
+
*/
|
|
753
|
+
setDetectCopies(level: number, score?: number): this {
|
|
754
|
+
this.checkCallable();
|
|
755
|
+
this.copyLevel = Math.max(0, Math.min(3, Math.floor(level)));
|
|
756
|
+
if (this.copyLevel > 0) this.detectMoves = true;
|
|
757
|
+
if (score) this.copyScore = score;
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Map the names and emails of authors and committers through the mailmap (`.mailmap`,
|
|
763
|
+
* `mailmap.blob`, `mailmap.file`), as git blame always does (default true). The entries'
|
|
764
|
+
* commits then carry the mapped identities.
|
|
765
|
+
*/
|
|
766
|
+
setUseMailmap(use: boolean): this {
|
|
767
|
+
this.checkCallable();
|
|
768
|
+
this.useMailmap = use;
|
|
769
|
+
return this;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Ignore the changes these revisions made (`--ignore-rev <rev>`, each peeled to a commit):
|
|
774
|
+
* their lines are blamed on the lines of their parents they resemble most (git's fuzzy
|
|
775
|
+
* matching), or stay theirs (unblamable) when none does.
|
|
776
|
+
*
|
|
777
|
+
* @throws Error `cannot find revision <rev> to ignore` when a name gives no commit
|
|
778
|
+
*/
|
|
779
|
+
setIgnoreRevs(revs: string[]): this {
|
|
780
|
+
this.checkCallable();
|
|
781
|
+
this.ignoreRevs = [...revs];
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Ignore the revisions listed in these files (`--ignore-revs-file <file>`, read after
|
|
787
|
+
* `blame.ignoreRevsFile`): full object ids, one per line, `#` comments; an empty name
|
|
788
|
+
* forgets the files before it. A relative path is read from the worktree's top.
|
|
789
|
+
*
|
|
790
|
+
* @throws Error `could not open object name list: <file>`, `invalid object name: <line>`
|
|
791
|
+
*/
|
|
792
|
+
setIgnoreRevsFiles(files: string[]): this {
|
|
793
|
+
this.checkCallable();
|
|
794
|
+
this.ignoreRevsFiles = [...files];
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** Mark lines blamed through an ignored commit (`?`; default `blame.markIgnoredLines`) */
|
|
799
|
+
setMarkIgnoredLines(mark: boolean): this {
|
|
800
|
+
this.checkCallable();
|
|
801
|
+
this.markIgnoredLines = mark;
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** Mark lines an ignored commit keeps (`*`; default `blame.markUnblamableLines`) */
|
|
806
|
+
setMarkUnblamableLines(mark: boolean): this {
|
|
807
|
+
this.checkCallable();
|
|
808
|
+
this.markUnblamableLines = mark;
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Blame in reverse (`--reverse <from>..<start>`): the lines of the file at `from`, each
|
|
814
|
+
* blamed on the last commit up to the start commit (default HEAD) it still existed in.
|
|
815
|
+
*/
|
|
816
|
+
setReverse(from: ObjectId): this {
|
|
817
|
+
from = canonicalObjectId(from);
|
|
818
|
+
this.checkCallable();
|
|
819
|
+
this.reverseFrom = from;
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Follow only first parents (`--first-parent`); with `setReverse`, the range must lie on
|
|
825
|
+
* the start commit's first-parent chain.
|
|
826
|
+
*/
|
|
827
|
+
setFirstParent(first: boolean): this {
|
|
828
|
+
this.checkCallable();
|
|
829
|
+
this.firstParent = first;
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Blame a buffer instead of the start commit's file (`--contents <file>`): git's fake
|
|
835
|
+
* commit on top of the start commit (default HEAD) and the commits `MERGE_HEAD` names,
|
|
836
|
+
* with null id, holding `content` at the blamed path of the index. Its lines are blamed on
|
|
837
|
+
* "External file (--contents)" where the parents' file differs (`workingTree`: "Not
|
|
838
|
+
* Committed Yet", as `git blame <path>` blames the working tree's file); a path only the
|
|
839
|
+
* index has is all its own, a rename staged in the index is followed. The content is taken
|
|
840
|
+
* as git stores it (no clean filters).
|
|
841
|
+
*
|
|
842
|
+
* @throws Error `--contents and --reverse do not blend well.` with `setReverse`, and
|
|
843
|
+
* `no such path '<path>' in HEAD` when neither a parent nor the index has the path
|
|
844
|
+
*/
|
|
845
|
+
setContents(content: Uint8Array, options: BlameContentsOptions = {}): this {
|
|
846
|
+
this.checkCallable();
|
|
847
|
+
this.contents = { ...options, content };
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Stop at commits older than `timestamp` (seconds, committer time; `--since`): they and
|
|
853
|
+
* their ancestors are boundaries, as git's `revs->max_age`
|
|
854
|
+
*/
|
|
855
|
+
setSince(timestamp: number): this {
|
|
856
|
+
this.checkCallable();
|
|
857
|
+
this.since = timestamp;
|
|
858
|
+
return this;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Details that changed between git versions: `histogramRediff` (git 2.54+, default
|
|
863
|
+
* true), `legacyMinimal` (git before 2.5x), `renameCountLastSpan` (rename scores of
|
|
864
|
+
* git 2.50+, default true) and `optionalPaths` (a `blame.ignoreRevsFile` of
|
|
865
|
+
* `:(optional)<path>` naming a missing file is skipped: git 2.52+, default true)
|
|
416
866
|
*/
|
|
417
867
|
setCompatibility(
|
|
418
868
|
options: Pick<XdiffOptions, "histogramRediff" | "legacyMinimal"> & {
|
|
419
869
|
renameCountLastSpan?: boolean;
|
|
870
|
+
optionalPaths?: boolean;
|
|
420
871
|
},
|
|
421
872
|
): this {
|
|
422
873
|
this.checkCallable();
|
|
423
|
-
const { renameCountLastSpan, ...diff } = options;
|
|
874
|
+
const { renameCountLastSpan, optionalPaths, ...diff } = options;
|
|
424
875
|
this.diffOptions = { ...this.diffOptions, ...diff };
|
|
425
876
|
if (renameCountLastSpan !== undefined) this.renameCountLastSpan = renameCountLastSpan;
|
|
877
|
+
if (optionalPaths !== undefined) this.optionalPaths = optionalPaths;
|
|
426
878
|
return this;
|
|
427
879
|
}
|
|
428
880
|
|
|
@@ -456,6 +908,20 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
456
908
|
return this;
|
|
457
909
|
}
|
|
458
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Set how many bytes the caches of `-C` keep between commits (default 32 MiB of line hashes
|
|
913
|
+
* of the files looked in, 16 MiB of their contents): a file not kept is read again for the
|
|
914
|
+
* next commit, as git reads it. The output does not change.
|
|
915
|
+
*
|
|
916
|
+
* @param bytes Size in bytes
|
|
917
|
+
*/
|
|
918
|
+
setCopyCacheByteLimit(bytes: number): this {
|
|
919
|
+
this.checkCallable();
|
|
920
|
+
this.copyHashCacheBytes = bytes;
|
|
921
|
+
this.copySourceCacheBytes = bytes;
|
|
922
|
+
return this;
|
|
923
|
+
}
|
|
924
|
+
|
|
459
925
|
/**
|
|
460
926
|
* Execute the blame command.
|
|
461
927
|
*
|
|
@@ -472,27 +938,40 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
472
938
|
this.algorithm ??= algorithmValue(config.value("diff.algorithm")) ?? "myers";
|
|
473
939
|
this.indentHeuristic ??= boolValue(config.value("diff.indentHeuristic")) ?? true;
|
|
474
940
|
this.showRoot ??= boolValue(config.value("blame.showRoot")) ?? false;
|
|
941
|
+
this.markIgnoredLines ??= boolValue(config.value("blame.markIgnoredLines")) ?? false;
|
|
942
|
+
this.markUnblamableLines ??= boolValue(config.value("blame.markUnblamableLines")) ?? false;
|
|
943
|
+
await this.buildIgnoreList(config);
|
|
475
944
|
|
|
945
|
+
if (this.contents && this.reverseFrom !== undefined) {
|
|
946
|
+
throw new Error("--contents and --reverse do not blend well.");
|
|
947
|
+
}
|
|
476
948
|
let startId = this.startCommit;
|
|
477
949
|
if (!startId) {
|
|
478
950
|
const head = await this.refsStore.resolve("HEAD");
|
|
479
951
|
if (!head?.objectId) {
|
|
480
|
-
throw new Error("
|
|
952
|
+
if (this.contents) throw new Error("no such ref: HEAD");
|
|
953
|
+
throw new Error(this.reverseFrom ? "No commit to dig up from?" : "No HEAD commit found");
|
|
481
954
|
}
|
|
482
955
|
startId = head.objectId;
|
|
483
956
|
}
|
|
957
|
+
if (this.reverseFrom !== undefined) {
|
|
958
|
+
// --reverse <from>..<start>: the lines of <from>, followed forward to <start>
|
|
959
|
+
await this.prepareReverse(this.reverseFrom, startId);
|
|
960
|
+
startId = this.reverseFrom;
|
|
961
|
+
}
|
|
484
962
|
|
|
485
963
|
const resultPath = this.filePath;
|
|
964
|
+
if (this.contents) startId = await this.fakeWorkingTreeCommit(startId, resultPath);
|
|
486
965
|
const start = await this.state(startId);
|
|
487
966
|
if (!start) {
|
|
488
967
|
throw new RefNotFoundError(`Cannot find commit: ${startId}`);
|
|
489
968
|
}
|
|
490
|
-
const entry = await this.lookup(start.commit.tree, resultPath);
|
|
969
|
+
const entry = this.contents ? this.fakeEntry : await this.lookup(start.commit.tree, resultPath);
|
|
491
970
|
if (!entry) {
|
|
492
971
|
throw new Error(`File not found: ${resultPath}`);
|
|
493
972
|
}
|
|
494
|
-
const size = await this.
|
|
495
|
-
if (size > this.bigFileThreshold) {
|
|
973
|
+
const size = await this.blobSize(entry.id);
|
|
974
|
+
if (!this.contents && size > this.bigFileThreshold) {
|
|
496
975
|
throw new Error(
|
|
497
976
|
`${resultPath} is ${size} bytes, larger than bigFileThreshold (${this.bigFileThreshold})`,
|
|
498
977
|
);
|
|
@@ -503,18 +982,27 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
503
982
|
const content = await this.readBlob(entry.id);
|
|
504
983
|
finalOrigin.lines = this.lineInterner().text(content);
|
|
505
984
|
const lineCount = countLines(content);
|
|
985
|
+
if (this.detectMoves || this.copyLevel > 0) this.prepareLines(content, lineCount);
|
|
506
986
|
|
|
507
987
|
// the initial entries: the whole file, or the -L ranges (sorted and merged)
|
|
508
988
|
const ranges = this.ranges(lineCount);
|
|
509
989
|
let head: Entry | null = null;
|
|
510
990
|
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
511
991
|
const [s, e] = ranges[i];
|
|
512
|
-
head = {
|
|
992
|
+
head = {
|
|
993
|
+
next: head,
|
|
994
|
+
suspect: finalOrigin,
|
|
995
|
+
lno: s,
|
|
996
|
+
sLno: s,
|
|
997
|
+
numLines: e - s,
|
|
998
|
+
ignored: false,
|
|
999
|
+
unblamable: false,
|
|
1000
|
+
};
|
|
513
1001
|
}
|
|
514
1002
|
const final: Slot = { next: null };
|
|
515
1003
|
if (head) {
|
|
516
1004
|
finalOrigin.suspects = head;
|
|
517
|
-
const queue = new CommitQueue();
|
|
1005
|
+
const queue = new CommitQueue(this.reverseFrom !== undefined);
|
|
518
1006
|
queue.put(startId, start.commit.committer.timestamp);
|
|
519
1007
|
await this.assignBlame(queue, final);
|
|
520
1008
|
}
|
|
@@ -530,19 +1018,37 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
530
1018
|
last &&
|
|
531
1019
|
last.suspect === e.suspect &&
|
|
532
1020
|
last.sLno + last.numLines === e.sLno &&
|
|
533
|
-
last.lno + last.numLines === e.lno
|
|
1021
|
+
last.lno + last.numLines === e.lno &&
|
|
1022
|
+
last.ignored === e.ignored &&
|
|
1023
|
+
last.unblamable === e.unblamable
|
|
534
1024
|
) {
|
|
535
1025
|
last.numLines += e.numLines;
|
|
536
1026
|
} else coalesced.push({ ...e });
|
|
537
1027
|
}
|
|
538
1028
|
|
|
1029
|
+
const mailmap = this.useMailmap ? await this.loadMailmap() : undefined;
|
|
1030
|
+
const mapped = new Map<ObjectId, Commit>();
|
|
1031
|
+
const commitOf = (st: CommitState, id: ObjectId): Commit => {
|
|
1032
|
+
if (!mailmap || mailmap.empty) return st.commit;
|
|
1033
|
+
let c = mapped.get(id);
|
|
1034
|
+
if (!c) {
|
|
1035
|
+
const author = mapIdent(mailmap, st.commit.author);
|
|
1036
|
+
const committer = mapIdent(mailmap, st.commit.committer);
|
|
1037
|
+
c =
|
|
1038
|
+
author === st.commit.author && committer === st.commit.committer
|
|
1039
|
+
? st.commit
|
|
1040
|
+
: { ...st.commit, author, committer };
|
|
1041
|
+
mapped.set(id, c);
|
|
1042
|
+
}
|
|
1043
|
+
return c;
|
|
1044
|
+
};
|
|
539
1045
|
const entries: BlameEntry[] = [];
|
|
540
1046
|
for (const e of coalesced) {
|
|
541
1047
|
const st = this.states.get(e.suspect.commitId);
|
|
542
1048
|
if (!st) continue;
|
|
543
1049
|
const prev = e.suspect.previous;
|
|
544
1050
|
entries.push({
|
|
545
|
-
commit: st.
|
|
1051
|
+
commit: commitOf(st, e.suspect.commitId),
|
|
546
1052
|
commitId: e.suspect.commitId,
|
|
547
1053
|
sourcePath: e.suspect.path,
|
|
548
1054
|
sourceStart: e.sLno + 1,
|
|
@@ -550,9 +1056,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
550
1056
|
lineCount: e.numLines,
|
|
551
1057
|
...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
|
|
552
1058
|
boundary: st.uninteresting,
|
|
1059
|
+
...(e.ignored ? { ignored: true } : {}),
|
|
1060
|
+
...(e.unblamable ? { unblamable: true } : {}),
|
|
553
1061
|
});
|
|
554
1062
|
}
|
|
555
1063
|
const result = createBlameResult(resultPath, lineCount, entries, content);
|
|
1064
|
+
result.incremental = [];
|
|
1065
|
+
for (const g of this.guilty) {
|
|
1066
|
+
const st = this.states.get(g.origin.commitId);
|
|
1067
|
+
if (!st) continue;
|
|
1068
|
+
const prev = g.origin.previous;
|
|
1069
|
+
result.incremental.push({
|
|
1070
|
+
commit: commitOf(st, g.origin.commitId),
|
|
1071
|
+
commitId: g.origin.commitId,
|
|
1072
|
+
sourcePath: g.origin.path,
|
|
1073
|
+
sourceStart: g.entry.sLno + 1,
|
|
1074
|
+
resultStart: g.entry.lno + 1,
|
|
1075
|
+
lineCount: g.entry.numLines,
|
|
1076
|
+
...(prev ? { previous: { commitId: prev.commitId, path: prev.path } } : {}),
|
|
1077
|
+
boundary: g.boundary,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
result.output = blameOutputConfig(config);
|
|
1081
|
+
result.markIgnoredLines = this.markIgnoredLines;
|
|
1082
|
+
result.markUnblamableLines = this.markUnblamableLines;
|
|
556
1083
|
const workingCopy = this.workingCopy;
|
|
557
1084
|
result.autoAbbrev = async () => {
|
|
558
1085
|
const lengths = await abbrevLengths(
|
|
@@ -564,6 +1091,187 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
564
1091
|
return result;
|
|
565
1092
|
}
|
|
566
1093
|
|
|
1094
|
+
/** The commits a commit's lines pass to: its parents, or its children in reverse */
|
|
1095
|
+
private scapegoats(st: CommitState, commitId: ObjectId): ObjectId[] {
|
|
1096
|
+
if (this.reverseFrom !== undefined) return this.children.get(commitId) ?? [];
|
|
1097
|
+
return this.firstParent ? st.commit.parents.slice(0, 1) : st.commit.parents;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* builtin/blame.c's `build_ignorelist`: `blame.ignoreRevsFile` (sorted, as git inserts
|
|
1102
|
+
* them), the files given, then the revisions given
|
|
1103
|
+
*/
|
|
1104
|
+
private async buildIgnoreList(config: RemoteConfigStore): Promise<void> {
|
|
1105
|
+
const environment = hostEnvironmentOf(this.workingCopy);
|
|
1106
|
+
const worktree = this.worktreeAccess;
|
|
1107
|
+
const configured = new Set<string>();
|
|
1108
|
+
for (let value of config.values("blame.ignoreRevsFile")) {
|
|
1109
|
+
const optional = this.optionalPaths && value.startsWith(":(optional)");
|
|
1110
|
+
if (optional) value = value.slice(":(optional)".length);
|
|
1111
|
+
const path = expandUserPath(value, environment);
|
|
1112
|
+
if (path === undefined) throw new Error(`failed to expand user dir in: '${value}'`);
|
|
1113
|
+
if (optional && path && !(await readMailmapFile(path, environment, worktree))) continue;
|
|
1114
|
+
configured.add(path);
|
|
1115
|
+
}
|
|
1116
|
+
// string_list_insert keeps the configured names sorted (strcmp) and unique
|
|
1117
|
+
const files = [...[...configured].sort(compareBytes), ...this.ignoreRevsFiles];
|
|
1118
|
+
const resolver = this.revisionResolver();
|
|
1119
|
+
const peelToCommit = async (id: ObjectId) => {
|
|
1120
|
+
const peeled = await resolver.peelTags(id).catch(() => undefined);
|
|
1121
|
+
return peeled?.type === "commit" ? peeled.id : undefined;
|
|
1122
|
+
};
|
|
1123
|
+
const hexLength = this.objectFormat.hexLength;
|
|
1124
|
+
const list = this.ignoreList;
|
|
1125
|
+
for (const file of files) {
|
|
1126
|
+
if (file === "") {
|
|
1127
|
+
list.clear();
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
const bytes = await readMailmapFile(file, environment, worktree);
|
|
1131
|
+
if (!bytes) throw new Error(`could not open object name list: ${file}`);
|
|
1132
|
+
const text = decodeGitPath(bytes);
|
|
1133
|
+
const lines = text.split("\n");
|
|
1134
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
1135
|
+
for (const raw of lines) {
|
|
1136
|
+
const hash = raw.indexOf("#");
|
|
1137
|
+
const name = (hash < 0 ? raw : raw.slice(0, hash)).replace(/^[ \t\n\r]+|[ \t\n\r]+$/g, "");
|
|
1138
|
+
if (!name) continue;
|
|
1139
|
+
if (name.length !== hexLength || !/^[0-9a-fA-F]+$/.test(name)) {
|
|
1140
|
+
throw new Error(`invalid object name: ${name}`);
|
|
1141
|
+
}
|
|
1142
|
+
const id = await peelToCommit(name.toLowerCase());
|
|
1143
|
+
if (id) list.add(id);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
for (const rev of this.ignoreRevs) {
|
|
1147
|
+
const resolved = await resolver.resolve(rev).catch(() => undefined);
|
|
1148
|
+
const id = resolved ? await peelToCommit(resolved) : undefined;
|
|
1149
|
+
if (!id) throw new Error(`cannot find revision ${rev} to ignore`);
|
|
1150
|
+
list.add(id);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* The children each commit passes its lines to in `--reverse` (git's `--children` walk of
|
|
1156
|
+
* `<from>..<start>`: `limit_list` then `set_children`, or the first-parent chain)
|
|
1157
|
+
*/
|
|
1158
|
+
private async prepareReverse(from: ObjectId, to: ObjectId): Promise<void> {
|
|
1159
|
+
this.reverseUninteresting.add(from);
|
|
1160
|
+
const children = this.children;
|
|
1161
|
+
if (this.firstParent) {
|
|
1162
|
+
let c = to;
|
|
1163
|
+
for (;;) {
|
|
1164
|
+
const st = await this.state(c);
|
|
1165
|
+
if (!st) throw new RefNotFoundError(`Cannot find commit: ${c}`);
|
|
1166
|
+
if (c === from || st.commit.parents.length === 0) break;
|
|
1167
|
+
const parent = st.commit.parents[0];
|
|
1168
|
+
children.set(parent, [c]);
|
|
1169
|
+
c = parent;
|
|
1170
|
+
}
|
|
1171
|
+
if (c !== from) {
|
|
1172
|
+
throw new Error("--reverse --first-parent together require range along first-parent chain");
|
|
1173
|
+
}
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const UNINTERESTING = 1;
|
|
1177
|
+
const SEEN = 2;
|
|
1178
|
+
const ADDED = 4;
|
|
1179
|
+
const flags = new Map<ObjectId, number>();
|
|
1180
|
+
const flag = (id: ObjectId) => flags.get(id) ?? 0;
|
|
1181
|
+
const set = (id: ObjectId, f: number) => flags.set(id, flag(id) | f);
|
|
1182
|
+
const parentsOf = (id: ObjectId) => this.states.get(id)?.commit.parents ?? [];
|
|
1183
|
+
const dateOf = (id: ObjectId) => this.states.get(id)?.commit.committer.timestamp ?? 0;
|
|
1184
|
+
const parse = async (id: ObjectId) => (await this.state(id)) !== undefined;
|
|
1185
|
+
// mark_parents_uninteresting: through the commits already parsed
|
|
1186
|
+
const markParentsUninteresting = (id: ObjectId) => {
|
|
1187
|
+
const pending = [...parentsOf(id)];
|
|
1188
|
+
while (pending.length > 0) {
|
|
1189
|
+
const p = pending.pop() as ObjectId;
|
|
1190
|
+
if (flag(p) & UNINTERESTING) continue;
|
|
1191
|
+
set(p, UNINTERESTING);
|
|
1192
|
+
if (this.states.has(p)) pending.push(...parentsOf(p));
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
// prepare_revision_walk: the pending commits (<from> first), each once, by date
|
|
1196
|
+
const starts: Array<{ id: ObjectId; uninteresting: boolean }> = [
|
|
1197
|
+
{ id: from, uninteresting: true },
|
|
1198
|
+
{ id: to, uninteresting: false },
|
|
1199
|
+
];
|
|
1200
|
+
const queue = new CommitQueue();
|
|
1201
|
+
const initial: ObjectId[] = [];
|
|
1202
|
+
for (const s of starts) {
|
|
1203
|
+
if (!(await parse(s.id))) throw new RefNotFoundError(`Cannot find commit: ${s.id}`);
|
|
1204
|
+
if (s.uninteresting) {
|
|
1205
|
+
set(s.id, UNINTERESTING);
|
|
1206
|
+
markParentsUninteresting(s.id);
|
|
1207
|
+
}
|
|
1208
|
+
if (flag(s.id) & SEEN) continue;
|
|
1209
|
+
set(s.id, SEEN);
|
|
1210
|
+
initial.push(s.id);
|
|
1211
|
+
}
|
|
1212
|
+
initial
|
|
1213
|
+
.map((id, i) => ({ id, i }))
|
|
1214
|
+
.sort((a, b) => dateOf(b.id) - dateOf(a.id) || a.i - b.i)
|
|
1215
|
+
.forEach((e) => {
|
|
1216
|
+
queue.put(e.id, dateOf(e.id));
|
|
1217
|
+
});
|
|
1218
|
+
const everybodyUninteresting = () => queue.ids().every((id) => flag(id) & UNINTERESTING);
|
|
1219
|
+
const newlist: ObjectId[] = [];
|
|
1220
|
+
let slop = 5;
|
|
1221
|
+
let date = Number.POSITIVE_INFINITY;
|
|
1222
|
+
for (let id = queue.get(); id !== undefined; id = queue.get()) {
|
|
1223
|
+
// process_parents
|
|
1224
|
+
if (!(flag(id) & ADDED)) {
|
|
1225
|
+
set(id, ADDED);
|
|
1226
|
+
if (flag(id) & UNINTERESTING) {
|
|
1227
|
+
for (const p of parentsOf(id)) {
|
|
1228
|
+
set(p, UNINTERESTING);
|
|
1229
|
+
if (!(await parse(p))) continue;
|
|
1230
|
+
markParentsUninteresting(p);
|
|
1231
|
+
if (flag(p) & SEEN) continue;
|
|
1232
|
+
set(p, SEEN);
|
|
1233
|
+
queue.put(p, dateOf(p));
|
|
1234
|
+
}
|
|
1235
|
+
} else {
|
|
1236
|
+
for (const p of parentsOf(id)) {
|
|
1237
|
+
if (!(await parse(p))) throw new RefNotFoundError(`Cannot find commit: ${p}`);
|
|
1238
|
+
if (!(flag(p) & SEEN)) {
|
|
1239
|
+
set(p, SEEN);
|
|
1240
|
+
queue.put(p, dateOf(p));
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
if (flag(id) & UNINTERESTING) {
|
|
1246
|
+
markParentsUninteresting(id);
|
|
1247
|
+
// still_interesting
|
|
1248
|
+
const next = queue.peekDate();
|
|
1249
|
+
if (next === undefined) break;
|
|
1250
|
+
if (date <= next || !everybodyUninteresting()) slop = 5;
|
|
1251
|
+
else slop--;
|
|
1252
|
+
if (slop) continue;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
date = dateOf(id);
|
|
1256
|
+
newlist.push(id);
|
|
1257
|
+
}
|
|
1258
|
+
// set_children: each child prepended to its parents' lists
|
|
1259
|
+
for (const c of newlist) {
|
|
1260
|
+
for (const p of parentsOf(c)) {
|
|
1261
|
+
const list = children.get(p);
|
|
1262
|
+
if (list) list.unshift(c);
|
|
1263
|
+
else children.set(p, [c]);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
for (const [id, f] of flags) {
|
|
1267
|
+
if (f & UNINTERESTING) {
|
|
1268
|
+
this.reverseUninteresting.add(id);
|
|
1269
|
+
const st = this.states.get(id);
|
|
1270
|
+
if (st) st.uninteresting = true;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
|
|
567
1275
|
/** The -L ranges as 0-based half-open ranges, sorted and merged; the whole file otherwise */
|
|
568
1276
|
private ranges(lineCount: number): Array<[number, number]> {
|
|
569
1277
|
if (this.lineRanges.length === 0) return lineCount > 0 ? [[0, lineCount]] : [];
|
|
@@ -600,13 +1308,30 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
600
1308
|
commitId = queue.get();
|
|
601
1309
|
continue;
|
|
602
1310
|
}
|
|
603
|
-
if (
|
|
1311
|
+
if (
|
|
1312
|
+
this.reverseFrom !== undefined ||
|
|
1313
|
+
(!st.uninteresting &&
|
|
1314
|
+
!(this.since !== undefined && st.commit.committer.timestamp < this.since))
|
|
1315
|
+
) {
|
|
1316
|
+
await this.passBlame(suspect, queue);
|
|
1317
|
+
} else {
|
|
1318
|
+
st.uninteresting = true;
|
|
1319
|
+
this.markParentsUninteresting(st);
|
|
1320
|
+
}
|
|
604
1321
|
// treat root commit as boundary
|
|
605
1322
|
if (st.commit.parents.length === 0 && !this.showRoot) st.uninteresting = true;
|
|
606
1323
|
// take responsibility for the remaining entries
|
|
607
1324
|
let ent = suspect.suspects;
|
|
608
1325
|
if (ent) {
|
|
609
1326
|
suspect.guilty = true;
|
|
1327
|
+
// found_guilty_entry: what --incremental prints, in this order
|
|
1328
|
+
for (let e: Entry | null = ent; e; e = e.next) {
|
|
1329
|
+
this.guilty.push({
|
|
1330
|
+
entry: { ...e, next: null },
|
|
1331
|
+
origin: suspect,
|
|
1332
|
+
boundary: st.uninteresting,
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
610
1335
|
while (ent.next) ent = ent.next;
|
|
611
1336
|
ent.next = final.next;
|
|
612
1337
|
final.next = suspect.suspects;
|
|
@@ -615,14 +1340,183 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
615
1340
|
}
|
|
616
1341
|
}
|
|
617
1342
|
|
|
618
|
-
/**
|
|
1343
|
+
/**
|
|
1344
|
+
* revision.c's `mark_parents_uninteresting`: the parents marked, and the parents of those
|
|
1345
|
+
* already loaded (parsed) recursively
|
|
1346
|
+
*/
|
|
1347
|
+
private markParentsUninteresting(st: CommitState): void {
|
|
1348
|
+
const pending = [...st.commit.parents];
|
|
1349
|
+
while (pending.length > 0) {
|
|
1350
|
+
const id = pending.pop() as ObjectId;
|
|
1351
|
+
const parent = this.states.get(id);
|
|
1352
|
+
if (!parent) {
|
|
1353
|
+
this.sinceUninteresting.add(id);
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
if (parent.uninteresting) continue;
|
|
1357
|
+
parent.uninteresting = true;
|
|
1358
|
+
pending.push(...parent.commit.parents);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* blame.c's `fake_working_tree_commit`: a commit with the null id on top of `parentId`
|
|
1364
|
+
* (and the commits MERGE_HEAD names, `append_merge_parents`) whose file at `path` is the
|
|
1365
|
+
* `--contents` buffer; its id is returned
|
|
1366
|
+
*/
|
|
1367
|
+
private async fakeWorkingTreeCommit(parentId: ObjectId, path: string): Promise<ObjectId> {
|
|
1368
|
+
const contents = this.contents as { content: Uint8Array } & BlameContentsOptions;
|
|
1369
|
+
const parent = await this.state(parentId);
|
|
1370
|
+
if (!parent) throw new Error(`no such commit ${parentId}`);
|
|
1371
|
+
const parents = [parentId];
|
|
1372
|
+
// append_parent: lookup_commit_reference, an annotated tag peeled to its commit
|
|
1373
|
+
const resolver = this.revisionResolver();
|
|
1374
|
+
for (const id of await this.mergeHeadParents()) {
|
|
1375
|
+
const peeled = await resolver.peelTags(id).catch(() => undefined);
|
|
1376
|
+
if (peeled?.type !== "commit" || !(await this.state(peeled.id))) {
|
|
1377
|
+
throw new Error(`no such commit ${id}`);
|
|
1378
|
+
}
|
|
1379
|
+
parents.push(peeled.id);
|
|
1380
|
+
}
|
|
1381
|
+
const index = await this.indexEntries();
|
|
1382
|
+
// verify_working_tree_path: a blob of a parent, else any stage of the index
|
|
1383
|
+
let known = false;
|
|
1384
|
+
for (const id of parents) {
|
|
1385
|
+
const st = this.states.get(id);
|
|
1386
|
+
const entry = st && (await this.lookup(st.commit.tree, path));
|
|
1387
|
+
if (entry && (entry.mode & S_IFMT) !== GITLINK_MODE) {
|
|
1388
|
+
known = true;
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
if (!known && !index.some((e) => e.path === path)) {
|
|
1393
|
+
throw new Error(`no such path '${path}' in HEAD`);
|
|
1394
|
+
}
|
|
1395
|
+
const time = contents.time ?? Math.floor(Date.now() / 1000);
|
|
1396
|
+
const tzOffset = contents.tzOffset ?? localTimezoneOffset(time);
|
|
1397
|
+
const ident = contents.workingTree
|
|
1398
|
+
? { name: "Not Committed Yet", email: "not.committed.yet", timestamp: time, tzOffset }
|
|
1399
|
+
: { name: "External file (--contents)", email: "external.file", timestamp: time, tzOffset };
|
|
1400
|
+
const from = contents.workingTree
|
|
1401
|
+
? path
|
|
1402
|
+
: contents.name === undefined || contents.name === "-"
|
|
1403
|
+
? "standard input"
|
|
1404
|
+
: contents.name;
|
|
1405
|
+
const id = this.objectFormat.nullId;
|
|
1406
|
+
const blobId = await computeObjectId("blob", contents.content, this.objectFormat);
|
|
1407
|
+
this.pretend.set(blobId, contents.content);
|
|
1408
|
+
// without a mode (standard input): the index's stage-0 entry's, else a regular file's
|
|
1409
|
+
const staged = index.find((e) => e.path === path && e.stage === 0);
|
|
1410
|
+
const mode = contents.mode ?? staged?.mode ?? 0o100644;
|
|
1411
|
+
this.fakeEntry = { id: blobId, mode };
|
|
1412
|
+
// the index with the path replaced: what git diffs the parents against (do_diff_cache)
|
|
1413
|
+
const files = new Map<string, { id: ObjectId; mode: number }>();
|
|
1414
|
+
for (const e of index) {
|
|
1415
|
+
if (e.stage === 0 && (e.mode & S_IFMT) !== GITLINK_MODE) {
|
|
1416
|
+
files.set(e.path, { id: e.objectId, mode: e.mode });
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
files.set(path, { id: blobId, mode });
|
|
1420
|
+
this.fakeFiles = files;
|
|
1421
|
+
this.states.set(id, {
|
|
1422
|
+
commit: {
|
|
1423
|
+
// the parent's tree stands for the index where a tree is read (`-C`)
|
|
1424
|
+
tree: parent.commit.tree,
|
|
1425
|
+
parents,
|
|
1426
|
+
author: ident,
|
|
1427
|
+
committer: ident,
|
|
1428
|
+
message: `Version of ${path} from ${from}\n`,
|
|
1429
|
+
},
|
|
1430
|
+
origins: null,
|
|
1431
|
+
originsByPath: new Map(),
|
|
1432
|
+
uninteresting: false,
|
|
1433
|
+
});
|
|
1434
|
+
return id;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/** The commits `.git/MERGE_HEAD` names, one per line (`append_merge_parents`) */
|
|
1438
|
+
private async mergeHeadParents(): Promise<ObjectId[]> {
|
|
1439
|
+
let text: string | undefined;
|
|
1440
|
+
try {
|
|
1441
|
+
text = await new OperationState(this.workingCopy.checkout, this.refsStore).read("MERGE_HEAD");
|
|
1442
|
+
} catch {
|
|
1443
|
+
return [];
|
|
1444
|
+
}
|
|
1445
|
+
const out: ObjectId[] = [];
|
|
1446
|
+
// strbuf_getwholeline_fd: only lines ending in a newline (a last one without is dropped)
|
|
1447
|
+
const lines = (text ?? "").split(/(?<=\n)/).filter((l) => l.endsWith("\n"));
|
|
1448
|
+
for (const line of lines) {
|
|
1449
|
+
// get_oid_hex: the line's first digits, the rest ignored; an empty line is refused
|
|
1450
|
+
const hex = line.slice(0, this.objectFormat.hexLength).toLowerCase();
|
|
1451
|
+
if (!this.isFullObjectId(hex)) {
|
|
1452
|
+
throw new Error(`unknown line in '.git/MERGE_HEAD': ${line}`);
|
|
1453
|
+
}
|
|
1454
|
+
out.push(hex);
|
|
1455
|
+
}
|
|
1456
|
+
return out;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/** Every entry of the index, none without one (a bare repository) */
|
|
1460
|
+
private async indexEntries(): Promise<
|
|
1461
|
+
Array<{
|
|
1462
|
+
path: string;
|
|
1463
|
+
mode: number;
|
|
1464
|
+
objectId: ObjectId;
|
|
1465
|
+
stage: number;
|
|
1466
|
+
}>
|
|
1467
|
+
> {
|
|
1468
|
+
try {
|
|
1469
|
+
const staging = this.staging;
|
|
1470
|
+
if (await staging.isOutdated()) await staging.read();
|
|
1471
|
+
const out = [];
|
|
1472
|
+
for await (const e of staging.entries()) {
|
|
1473
|
+
out.push({ path: e.path, mode: e.mode, objectId: e.objectId, stage: e.stage });
|
|
1474
|
+
}
|
|
1475
|
+
return out;
|
|
1476
|
+
} catch {
|
|
1477
|
+
return [];
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
/** git's `pass_blame` */
|
|
619
1482
|
private async passBlame(origin: Origin, queue: CommitQueue): Promise<void> {
|
|
620
1483
|
const st = this.states.get(origin.commitId);
|
|
621
1484
|
if (!st) return;
|
|
622
|
-
const parents = st.
|
|
1485
|
+
const parents = this.scapegoats(st, origin.commitId);
|
|
623
1486
|
const n = parents.length;
|
|
624
|
-
if (n === 0) return;
|
|
625
1487
|
const sgOrigin: Array<Origin | undefined> = new Array(n).fill(undefined);
|
|
1488
|
+
const blames: Slot = { next: null };
|
|
1489
|
+
const blamed: Queue = { tail: blames };
|
|
1490
|
+
const toosmall: Slot = { next: null };
|
|
1491
|
+
await this.passBlameSteps(origin, parents, sgOrigin, blamed, toosmall, queue);
|
|
1492
|
+
blamed.tail.next = null;
|
|
1493
|
+
this.distributeBlame(blames.next, queue);
|
|
1494
|
+
// the entries too small to look for are the origin's again (unsorted, as git leaves them)
|
|
1495
|
+
if (toosmall.next) {
|
|
1496
|
+
let tail = toosmall.next;
|
|
1497
|
+
while (tail.next) tail = tail.next;
|
|
1498
|
+
tail.next = origin.suspects;
|
|
1499
|
+
origin.suspects = toosmall.next;
|
|
1500
|
+
}
|
|
1501
|
+
for (const porigin of sgOrigin) if (porigin && !porigin.suspects) porigin.lines = undefined;
|
|
1502
|
+
origin.lines = undefined;
|
|
1503
|
+
origin.fingerprints = undefined;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* The steps of `pass_blame` before its `finish`: the parents' versions found and compared,
|
|
1508
|
+
* then moves and copies looked for; returning is git's `goto finish`
|
|
1509
|
+
*/
|
|
1510
|
+
private async passBlameSteps(
|
|
1511
|
+
origin: Origin,
|
|
1512
|
+
parents: ObjectId[],
|
|
1513
|
+
sgOrigin: Array<Origin | undefined>,
|
|
1514
|
+
blamed: Queue,
|
|
1515
|
+
toosmall: Slot,
|
|
1516
|
+
queue: CommitQueue,
|
|
1517
|
+
): Promise<void> {
|
|
1518
|
+
const n = parents.length;
|
|
1519
|
+
if (n === 0) return;
|
|
626
1520
|
for (let pass = 0; pass < (this.followRenames ? 2 : 1); pass++) {
|
|
627
1521
|
for (let i = 0; i < n; i++) {
|
|
628
1522
|
if (sgOrigin[i]) continue;
|
|
@@ -651,9 +1545,387 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
651
1545
|
if (!porigin) continue;
|
|
652
1546
|
if (!origin.previous) origin.previous = porigin;
|
|
653
1547
|
await this.passBlameToParent(origin, porigin, queue);
|
|
654
|
-
if (!origin.suspects)
|
|
1548
|
+
if (!origin.suspects) return;
|
|
655
1549
|
}
|
|
656
|
-
|
|
1550
|
+
// pass the remaining suspects of an ignored commit to its parents
|
|
1551
|
+
if (this.ignoreList.has(origin.commitId)) {
|
|
1552
|
+
for (let i = 0; i < n; i++) {
|
|
1553
|
+
const porigin = sgOrigin[i];
|
|
1554
|
+
if (!porigin) continue;
|
|
1555
|
+
await this.passBlameToParent(origin, porigin, queue, true);
|
|
1556
|
+
if (!origin.suspects) return;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
// optionally find moves in the parents' files
|
|
1560
|
+
if (this.detectMoves) {
|
|
1561
|
+
this.filterSuspects(toosmall, origin, this.moveScore);
|
|
1562
|
+
if (origin.suspects) {
|
|
1563
|
+
for (let i = 0; i < n; i++) {
|
|
1564
|
+
const porigin = sgOrigin[i];
|
|
1565
|
+
if (!porigin) continue;
|
|
1566
|
+
await this.findMoveInParent(blamed, toosmall, origin, porigin);
|
|
1567
|
+
if (!origin.suspects) break;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
// optionally find copies from the parents' files
|
|
1572
|
+
if (this.copyLevel > 0) {
|
|
1573
|
+
if (this.copyScore > this.moveScore) {
|
|
1574
|
+
this.filterSuspects(toosmall, origin, this.copyScore);
|
|
1575
|
+
} else if (this.copyScore < this.moveScore) {
|
|
1576
|
+
origin.suspects = blameMerge(origin.suspects, toosmall.next);
|
|
1577
|
+
toosmall.next = null;
|
|
1578
|
+
this.filterSuspects(toosmall, origin, this.copyScore);
|
|
1579
|
+
}
|
|
1580
|
+
if (!origin.suspects) return;
|
|
1581
|
+
for (let i = 0; i < n; i++) {
|
|
1582
|
+
await this.findCopyInParent(blamed, toosmall, origin, parents[i], sgOrigin[i]);
|
|
1583
|
+
if (!origin.suspects) return;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/** `filter_small` of the origin's suspects into `toosmall` */
|
|
1589
|
+
private filterSuspects(toosmall: Slot, origin: Origin, scoreMin: number): void {
|
|
1590
|
+
const src: Slot = { next: origin.suspects };
|
|
1591
|
+
this.filterSmall(toosmall, src, scoreMin);
|
|
1592
|
+
origin.suspects = src.next;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* git's `filter_small`: the entries of `source` scoring at most `scoreMin` moved to the
|
|
1597
|
+
* front of the list after `small`; returns the link before the old head of that list
|
|
1598
|
+
*/
|
|
1599
|
+
private filterSmall(small: Slot, source: Slot, scoreMin: number): Slot {
|
|
1600
|
+
let p = source.next;
|
|
1601
|
+
const oldsmall = small.next;
|
|
1602
|
+
let sm = small;
|
|
1603
|
+
let src = source;
|
|
1604
|
+
while (p) {
|
|
1605
|
+
if (this.entryScore(p.lno, p.numLines) <= scoreMin) {
|
|
1606
|
+
sm.next = p;
|
|
1607
|
+
sm = p;
|
|
1608
|
+
} else {
|
|
1609
|
+
src.next = p;
|
|
1610
|
+
src = p;
|
|
1611
|
+
}
|
|
1612
|
+
p = p.next;
|
|
1613
|
+
}
|
|
1614
|
+
sm.next = oldsmall;
|
|
1615
|
+
src.next = null;
|
|
1616
|
+
return sm;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
/** git's `blame_entry_score`: one more than the alphanumerics of the lines in the final file */
|
|
1620
|
+
private entryScore(lno: number, numLines: number): number {
|
|
1621
|
+
return 1 + this.finalAlnum[lno + numLines] - this.finalAlnum[lno];
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
/** git's `prepare_lines`, and the alphanumerics before each line for `entryScore` */
|
|
1625
|
+
private prepareLines(content: Uint8Array, lineCount: number): void {
|
|
1626
|
+
const starts = new Int32Array(lineCount + 1);
|
|
1627
|
+
const alnum = new Int32Array(lineCount + 1);
|
|
1628
|
+
let line = 0;
|
|
1629
|
+
let count = 0;
|
|
1630
|
+
for (let i = 0; i < content.length; i++) {
|
|
1631
|
+
const c = content[i];
|
|
1632
|
+
if ((c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a)) {
|
|
1633
|
+
count++;
|
|
1634
|
+
} else if (c === 0x0a && ++line < lineCount) {
|
|
1635
|
+
starts[line] = i + 1;
|
|
1636
|
+
alnum[line] = count;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
starts[lineCount] = content.length;
|
|
1640
|
+
alnum[lineCount] = count;
|
|
1641
|
+
this.finalContent = content;
|
|
1642
|
+
this.finalStarts = starts;
|
|
1643
|
+
this.finalAlnum = alnum;
|
|
1644
|
+
if (this.copyLevel > 0) this.finalHashes = this.lineHashesOf(content);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/** git's `copy_split_if_better`: `potential` kept in `best` when it scores no lower */
|
|
1648
|
+
private copySplitIfBetter(best: Split, potential: Split): void {
|
|
1649
|
+
if (!potential[1].suspect) return;
|
|
1650
|
+
if (
|
|
1651
|
+
best[1].suspect &&
|
|
1652
|
+
this.entryScore(potential[1].lno, potential[1].numLines) <
|
|
1653
|
+
this.entryScore(best[1].lno, best[1].numLines)
|
|
1654
|
+
) {
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
best[0] = potential[0];
|
|
1658
|
+
best[1] = potential[1];
|
|
1659
|
+
best[2] = potential[2];
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* git's `find_copy_in_blob`: the best run of `ent`'s lines (in the final file) that the
|
|
1664
|
+
* parent's file has, as a split of `ent`
|
|
1665
|
+
*/
|
|
1666
|
+
private findCopyInBlob(ent: Entry, parent: Origin, file: { text: InternedText }): Split {
|
|
1667
|
+
const split = emptySplit();
|
|
1668
|
+
const interner = this.lineInterner();
|
|
1669
|
+
if (file.text.interner !== interner) file.text = interner.text(file.text.content);
|
|
1670
|
+
const slice = this.finalContent.subarray(
|
|
1671
|
+
this.finalStarts[ent.lno],
|
|
1672
|
+
this.finalStarts[ent.lno + ent.numLines],
|
|
1673
|
+
);
|
|
1674
|
+
const hunks = xdiffHunks(file.text, slice, this.xdiffOptions(interner));
|
|
1675
|
+
let tlno = 0;
|
|
1676
|
+
let plno = 0;
|
|
1677
|
+
const handleSplit = (same: number) => {
|
|
1678
|
+
if (ent.numLines <= tlno || tlno >= same) return;
|
|
1679
|
+
const potential = splitOverlap(ent, tlno + ent.sLno, plno, same + ent.sLno, parent);
|
|
1680
|
+
this.copySplitIfBetter(split, potential);
|
|
1681
|
+
};
|
|
1682
|
+
for (const h of hunks) {
|
|
1683
|
+
handleSplit(h.i2);
|
|
1684
|
+
plno = h.i1 + h.chg1;
|
|
1685
|
+
tlno = h.i2 + h.chg2;
|
|
1686
|
+
}
|
|
1687
|
+
// the rest, if any, matches the parent
|
|
1688
|
+
handleSplit(ent.numLines);
|
|
1689
|
+
return split;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
/** git's `find_move_in_parent`: lines the target is suspected for found in the parent's file */
|
|
1693
|
+
private async findMoveInParent(
|
|
1694
|
+
blamed: Queue,
|
|
1695
|
+
toosmallHead: Slot,
|
|
1696
|
+
target: Origin,
|
|
1697
|
+
parent: Origin,
|
|
1698
|
+
): Promise<void> {
|
|
1699
|
+
let unblamed = target.suspects;
|
|
1700
|
+
if (!unblamed) return;
|
|
1701
|
+
const file = { text: await this.originContent(parent) };
|
|
1702
|
+
let toosmall = toosmallHead;
|
|
1703
|
+
let leftover: Entry | null = null;
|
|
1704
|
+
do {
|
|
1705
|
+
const head: Slot = { next: null };
|
|
1706
|
+
const rest: Queue = { tail: head };
|
|
1707
|
+
let next: Entry | null;
|
|
1708
|
+
for (let e: Entry | null = unblamed; e; e = next) {
|
|
1709
|
+
next = e.next;
|
|
1710
|
+
const split = this.findCopyInBlob(e, parent, file);
|
|
1711
|
+
if (split[1].suspect && this.moveScore < this.entryScore(split[1].lno, split[1].numLines)) {
|
|
1712
|
+
splitBlame(blamed, rest, split, e);
|
|
1713
|
+
} else {
|
|
1714
|
+
e.next = leftover;
|
|
1715
|
+
leftover = e;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
rest.tail.next = null;
|
|
1719
|
+
toosmall = this.filterSmall(toosmall, head, this.moveScore);
|
|
1720
|
+
unblamed = head.next;
|
|
1721
|
+
} while (unblamed);
|
|
1722
|
+
parent.lines = file.text;
|
|
1723
|
+
target.suspects = reverseBlame(leftover, null);
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* git's `find_copy_in_parent`: lines the target is suspected for found in other files of
|
|
1728
|
+
* the parent (`porigin`, the parent's version of the file, was tried by the move pass)
|
|
1729
|
+
*/
|
|
1730
|
+
private async findCopyInParent(
|
|
1731
|
+
blamed: Queue,
|
|
1732
|
+
toosmallHead: Slot,
|
|
1733
|
+
target: Origin,
|
|
1734
|
+
parentId: ObjectId,
|
|
1735
|
+
porigin: Origin | undefined,
|
|
1736
|
+
): Promise<void> {
|
|
1737
|
+
let unblamed = target.suspects;
|
|
1738
|
+
if (!unblamed) return;
|
|
1739
|
+
const parent = await this.state(parentId);
|
|
1740
|
+
const child = this.states.get(target.commitId);
|
|
1741
|
+
if (!parent || !child) return;
|
|
1742
|
+
const harder =
|
|
1743
|
+
this.copyLevel >= 3 || (this.copyLevel >= 2 && (!porigin || target.path !== porigin.path));
|
|
1744
|
+
const candidates = await this.copyCandidates(parent.commit.tree, child.commit.tree, harder);
|
|
1745
|
+
/** Origins this call made: git frees those no split took (`blame_origin_decref`) */
|
|
1746
|
+
const created = new Set<Origin>();
|
|
1747
|
+
const taken = new Set<Origin>();
|
|
1748
|
+
let toosmall = toosmallHead;
|
|
1749
|
+
let leftover: Entry | null = null;
|
|
1750
|
+
do {
|
|
1751
|
+
const head: Slot = { next: null };
|
|
1752
|
+
const rest: Queue = { tail: head };
|
|
1753
|
+
const list: Array<{ ent: Entry; split: Split }> = [];
|
|
1754
|
+
// the line hashes of the entries: a file sharing none of them cannot give a split
|
|
1755
|
+
const wanted = new Set<number>();
|
|
1756
|
+
for (let e: Entry | null = unblamed; e; e = e.next) {
|
|
1757
|
+
list.push({ ent: e, split: emptySplit() });
|
|
1758
|
+
for (let l = e.lno; l < e.lno + e.numLines; l++) wanted.add(this.finalHashes[l]);
|
|
1759
|
+
}
|
|
1760
|
+
for (const c of candidates) {
|
|
1761
|
+
// find_move already dealt with this path
|
|
1762
|
+
if (porigin && c.path === porigin.path) continue;
|
|
1763
|
+
let hashes = this.copyHashes.get(c.id);
|
|
1764
|
+
let content: Uint8Array | undefined;
|
|
1765
|
+
if (hashes === undefined) {
|
|
1766
|
+
if (c.id !== target.blobId && (await this.isBig(c.id))) hashes = null;
|
|
1767
|
+
else {
|
|
1768
|
+
content = await this.readBlob(c.id, true);
|
|
1769
|
+
hashes = this.lineHashesOf(content);
|
|
1770
|
+
}
|
|
1771
|
+
this.keepCopyHashes(c.id, hashes);
|
|
1772
|
+
}
|
|
1773
|
+
if (hashes === null) continue;
|
|
1774
|
+
if (!sharesLine(hashes, wanted)) {
|
|
1775
|
+
// git's get_origin still moves a known origin to the front
|
|
1776
|
+
const known = parent.originsByPath.get(c.path);
|
|
1777
|
+
if (known) moveOriginToFront(parent, known);
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
const isNew = !parent.originsByPath.has(c.path);
|
|
1781
|
+
const norigin = this.getOrigin(parentId, c.path);
|
|
1782
|
+
if (isNew) created.add(norigin);
|
|
1783
|
+
norigin.blobId = c.id;
|
|
1784
|
+
norigin.mode = c.mode;
|
|
1785
|
+
const file = {
|
|
1786
|
+
text:
|
|
1787
|
+
norigin.lines ??
|
|
1788
|
+
this.copySources.get(c.id) ??
|
|
1789
|
+
this.lineInterner().text(content ?? (await this.readBlob(c.id, true))),
|
|
1790
|
+
};
|
|
1791
|
+
for (const item of list) {
|
|
1792
|
+
this.copySplitIfBetter(item.split, this.findCopyInBlob(item.ent, norigin, file));
|
|
1793
|
+
}
|
|
1794
|
+
this.keepCopySourceText(c.id, file.text);
|
|
1795
|
+
}
|
|
1796
|
+
for (const { ent, split } of list) {
|
|
1797
|
+
if (split[1].suspect && this.copyScore < this.entryScore(split[1].lno, split[1].numLines)) {
|
|
1798
|
+
taken.add(split[1].suspect);
|
|
1799
|
+
splitBlame(blamed, rest, split, ent);
|
|
1800
|
+
} else {
|
|
1801
|
+
ent.next = leftover;
|
|
1802
|
+
leftover = ent;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
rest.tail.next = null;
|
|
1806
|
+
toosmall = this.filterSmall(toosmall, head, this.copyScore);
|
|
1807
|
+
unblamed = head.next;
|
|
1808
|
+
} while (unblamed);
|
|
1809
|
+
target.suspects = reverseBlame(leftover, null);
|
|
1810
|
+
for (const o of created) if (!taken.has(o) && !o.suspects) unlinkOrigin(parent, o);
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* The hash of each line, as the line interner hashes it (`xdl_hash_record` under
|
|
1815
|
+
* whitespace flags): lines a diff can match hash alike
|
|
1816
|
+
*/
|
|
1817
|
+
private lineHashesOf(content: Uint8Array): Int32Array {
|
|
1818
|
+
const lines = new ByteLines(content);
|
|
1819
|
+
const ws = whitespaceFlags({ ignoreWhitespace: this.ignoreWhitespace });
|
|
1820
|
+
const n = lines.size();
|
|
1821
|
+
if (!ws) return lines.lineHashes.slice(0, n);
|
|
1822
|
+
const out = new Int32Array(n);
|
|
1823
|
+
for (let i = 0; i < n; i++)
|
|
1824
|
+
out[i] = xdlHashRecord(content, lines.start(i), lines.start(i + 1), ws);
|
|
1825
|
+
return out;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Kept while the cache has room (and never evicted): a commit scans its parent's files in
|
|
1830
|
+
* the order the next one scans them, so evicting the oldest would evict every file before
|
|
1831
|
+
* its next use
|
|
1832
|
+
*/
|
|
1833
|
+
private keepCopyHashes(blobId: ObjectId, hashes: Int32Array | null): void {
|
|
1834
|
+
const size = 64 + (hashes ? hashes.byteLength : 0);
|
|
1835
|
+
if (this.copyHashBytes + size > this.copyHashCacheBytes) return;
|
|
1836
|
+
this.copyHashes.set(blobId, hashes);
|
|
1837
|
+
this.copyHashBytes += size;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
/** A file a copy was looked for in, interned, kept as `keepCopyHashes` keeps hashes */
|
|
1841
|
+
private keepCopySourceText(blobId: ObjectId, text: InternedText): void {
|
|
1842
|
+
const old = this.copySources.get(blobId);
|
|
1843
|
+
if (old) {
|
|
1844
|
+
this.copySources.set(blobId, text);
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
if (this.copySourceBytes + text.content.length > this.copySourceCacheBytes) return;
|
|
1848
|
+
this.copySources.set(blobId, text);
|
|
1849
|
+
this.copySourceBytes += text.content.length;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* The parent's files `find_copy_in_parent` looks in, in the order git's tree diff lists
|
|
1854
|
+
* them: those the commit changed or removed, or (`harder`, find_copies_harder) all of
|
|
1855
|
+
* them; never gitlinks
|
|
1856
|
+
*/
|
|
1857
|
+
private async copyCandidates(
|
|
1858
|
+
parentTree: ObjectId,
|
|
1859
|
+
childTree: ObjectId,
|
|
1860
|
+
harder: boolean,
|
|
1861
|
+
): Promise<Array<{ path: string; id: ObjectId; mode: number }>> {
|
|
1862
|
+
const out: Array<{ path: string; id: ObjectId; mode: number }> = [];
|
|
1863
|
+
const walk = async (tree: ObjectId, other: ObjectId | undefined, prefix: string) => {
|
|
1864
|
+
if (!harder && tree === other) return;
|
|
1865
|
+
const others = new Map<string, { id: ObjectId; mode: number }>();
|
|
1866
|
+
if (other && !harder) {
|
|
1867
|
+
for await (const e of this.trees.loadTree(other)) others.set(e.name, e);
|
|
1868
|
+
}
|
|
1869
|
+
for await (const e of this.trees.loadTree(tree)) {
|
|
1870
|
+
const path = prefix + e.name;
|
|
1871
|
+
const o = others.get(e.name);
|
|
1872
|
+
const kind = e.mode & S_IFMT;
|
|
1873
|
+
if (kind === TREE_MODE) {
|
|
1874
|
+
await walk(e.id, o && (o.mode & S_IFMT) === TREE_MODE ? o.id : undefined, `${path}/`);
|
|
1875
|
+
} else if (kind !== GITLINK_MODE) {
|
|
1876
|
+
if (!harder && o && o.id === e.id && o.mode === e.mode) continue;
|
|
1877
|
+
out.push({ path, id: e.id, mode: e.mode });
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
await walk(parentTree, childTree, "");
|
|
1882
|
+
return out;
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/** git's `distribute_blame`: the entries found in parents queued to their origins */
|
|
1886
|
+
private distributeBlame(blamed: Entry | null, queue: CommitQueue): void {
|
|
1887
|
+
const ents: Entry[] = [];
|
|
1888
|
+
for (let e = blamed; e; e = e.next) ents.push(e);
|
|
1889
|
+
ents.sort((a, b) => a.suspect.seq - b.suspect.seq || a.sLno - b.sLno);
|
|
1890
|
+
let i = 0;
|
|
1891
|
+
while (i < ents.length) {
|
|
1892
|
+
const porigin = ents[i].suspect;
|
|
1893
|
+
let j = i;
|
|
1894
|
+
while (j + 1 < ents.length && ents[j + 1].suspect === porigin) {
|
|
1895
|
+
ents[j].next = ents[j + 1];
|
|
1896
|
+
j++;
|
|
1897
|
+
}
|
|
1898
|
+
ents[j].next = null;
|
|
1899
|
+
this.queueBlames(porigin, ents[i], queue);
|
|
1900
|
+
i = j + 1;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/** The diff options of every comparison (`sb->xdl_opts`) */
|
|
1905
|
+
private xdiffOptions(interner: LineInterner): XdiffOptions {
|
|
1906
|
+
return {
|
|
1907
|
+
interner,
|
|
1908
|
+
algorithm: this.algorithm,
|
|
1909
|
+
indentHeuristic: this.indentHeuristic,
|
|
1910
|
+
ignoreWhitespace: this.ignoreWhitespace,
|
|
1911
|
+
...this.diffOptions,
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
/** mailmap.c's read_mailmap: `.mailmap` (not in a bare repository), `mailmap.blob`, `mailmap.file` */
|
|
1916
|
+
private async loadMailmap(): Promise<Mailmap> {
|
|
1917
|
+
const config = RemoteConfigStore.from(this.workingCopy);
|
|
1918
|
+
return readRepositoryMailmap({
|
|
1919
|
+
config: (key) => config.value(key),
|
|
1920
|
+
worktree: this.worktreeAccess,
|
|
1921
|
+
environment: hostEnvironmentOf(this.workingCopy),
|
|
1922
|
+
readBlobNamed: async (name) => {
|
|
1923
|
+
const id = await this.revisionResolver()
|
|
1924
|
+
.resolve(name)
|
|
1925
|
+
.catch(() => undefined);
|
|
1926
|
+
return id ? this.readBlob(id).catch(() => undefined) : undefined;
|
|
1927
|
+
},
|
|
1928
|
+
});
|
|
657
1929
|
}
|
|
658
1930
|
|
|
659
1931
|
/** git's `pass_whole_blame` */
|
|
@@ -685,11 +1957,15 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
685
1957
|
if (st) queue.put(porigin.commitId, st.commit.committer.timestamp);
|
|
686
1958
|
}
|
|
687
1959
|
|
|
688
|
-
/**
|
|
1960
|
+
/**
|
|
1961
|
+
* git's `pass_blame_to_parent`; `ignoreDiffs` (an ignored commit's second pass) passes the
|
|
1962
|
+
* changed lines too, to the parent lines they resemble
|
|
1963
|
+
*/
|
|
689
1964
|
private async passBlameToParent(
|
|
690
1965
|
target: Origin,
|
|
691
1966
|
parent: Origin,
|
|
692
1967
|
queue: CommitQueue,
|
|
1968
|
+
ignoreDiffs = false,
|
|
693
1969
|
): Promise<void> {
|
|
694
1970
|
if (!target.suspects) return;
|
|
695
1971
|
const newdest: Slot = { next: null };
|
|
@@ -702,28 +1978,41 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
702
1978
|
const interner = this.lineInterner();
|
|
703
1979
|
if (fileP.interner !== interner) fileP = parent.lines = interner.text(fileP.content);
|
|
704
1980
|
if (fileO.interner !== interner) fileO = target.lines = interner.text(fileO.content);
|
|
705
|
-
const hunks = xdiffHunks(fileP, fileO,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
});
|
|
1981
|
+
const hunks = xdiffHunks(fileP, fileO, this.xdiffOptions(interner));
|
|
1982
|
+
// the parent's fingerprints are fresh for each pass (matching consumes them), the
|
|
1983
|
+
// target's kept while it passes blame
|
|
1984
|
+
const parentFps = ignoreDiffs ? lineFingerprints(fileP.content) : undefined;
|
|
1985
|
+
let targetFps: Fingerprint[] | undefined;
|
|
1986
|
+
if (ignoreDiffs) targetFps = target.fingerprints ??= lineFingerprints(fileO.content);
|
|
712
1987
|
for (const h of hunks) {
|
|
713
|
-
|
|
1988
|
+
const lineBlames =
|
|
1989
|
+
parentFps && targetFps && h.chg2 > 0
|
|
1990
|
+
? guessLineBlames(parentFps, targetFps, h.i2, h.i1 - h.i2, h.i2 + h.chg2, h.chg1)
|
|
1991
|
+
: undefined;
|
|
1992
|
+
blameChunk(d, h.i2, h.i1 - h.i2, h.i2 + h.chg2, parent, lineBlames);
|
|
714
1993
|
d.offset = h.i1 + h.chg1 - (h.i2 + h.chg2);
|
|
715
1994
|
}
|
|
716
1995
|
blameChunk(d, INT_MAX, d.offset, INT_MAX, parent);
|
|
717
1996
|
d.dstq.next = null;
|
|
718
1997
|
target.suspects = src.next;
|
|
719
|
-
|
|
1998
|
+
let passed = newdest.next;
|
|
1999
|
+
if (ignoreDiffs && passed) {
|
|
2000
|
+
// sort_blame_entries(compare_blame_suspect): one suspect, so by line (stable)
|
|
2001
|
+
const ents: Entry[] = [];
|
|
2002
|
+
for (let e: Entry | null = passed; e; e = e.next) ents.push(e);
|
|
2003
|
+
ents.sort((a, b) => a.sLno - b.sLno);
|
|
2004
|
+
for (let i = 0; i < ents.length; i++) ents[i].next = ents[i + 1] ?? null;
|
|
2005
|
+
passed = ents[0];
|
|
2006
|
+
}
|
|
2007
|
+
this.queueBlames(parent, passed, queue);
|
|
720
2008
|
}
|
|
721
2009
|
|
|
722
2010
|
/** git's `find_origin`: the parent's version at the same path, of the same kind */
|
|
723
2011
|
private async findOrigin(parentId: ObjectId, origin: Origin): Promise<Origin | undefined> {
|
|
724
2012
|
const parent = this.states.get(parentId);
|
|
725
2013
|
if (!parent) return undefined;
|
|
726
|
-
|
|
2014
|
+
const known = parent.originsByPath.get(origin.path);
|
|
2015
|
+
if (known) return known;
|
|
727
2016
|
const entry = await this.lookup(parent.commit.tree, origin.path);
|
|
728
2017
|
if (!entry || (entry.mode & S_IFMT) !== (origin.mode & S_IFMT)) return undefined;
|
|
729
2018
|
if (entry.id !== origin.blobId && (await this.isBig(entry.id))) return undefined;
|
|
@@ -744,7 +2033,9 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
744
2033
|
const before = new Map<string, { id: ObjectId; mode: number }>();
|
|
745
2034
|
const after = new Map<string, { id: ObjectId; mode: number }>();
|
|
746
2035
|
await this.collectBlobs(parent.commit.tree, "", before);
|
|
747
|
-
|
|
2036
|
+
if (origin.commitId === this.objectFormat.nullId && this.fakeFiles) {
|
|
2037
|
+
for (const [p, e] of this.fakeFiles) after.set(p, e);
|
|
2038
|
+
} else await this.collectBlobs(child.commit.tree, "", after);
|
|
748
2039
|
const sources = [];
|
|
749
2040
|
for (const [path, e] of before) {
|
|
750
2041
|
if (!after.has(path) && !(await this.isBig(e.id))) sources.push({ path, ...e });
|
|
@@ -759,7 +2050,7 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
759
2050
|
renameLimit: limit,
|
|
760
2051
|
minimumScore: Math.round((this.renameScore * GIT_MAX_SCORE) / 100),
|
|
761
2052
|
countLastSpan: this.renameCountLastSpan,
|
|
762
|
-
size: async (c) => this.
|
|
2053
|
+
size: async (c) => this.blobSize(c.id),
|
|
763
2054
|
load: async (c) => this.readBlob(c.id),
|
|
764
2055
|
},
|
|
765
2056
|
);
|
|
@@ -777,18 +2068,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
777
2068
|
private getOrigin(commitId: ObjectId, path: string): Origin {
|
|
778
2069
|
const st = this.states.get(commitId);
|
|
779
2070
|
if (!st) throw new Error(`commit ${commitId} not loaded`);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
l.next = o.next;
|
|
785
|
-
o.next = st.origins;
|
|
786
|
-
st.origins = o;
|
|
787
|
-
}
|
|
788
|
-
return o;
|
|
789
|
-
}
|
|
2071
|
+
const known = st.originsByPath.get(path);
|
|
2072
|
+
if (known) {
|
|
2073
|
+
moveOriginToFront(st, known);
|
|
2074
|
+
return known;
|
|
790
2075
|
}
|
|
791
2076
|
const o: Origin = {
|
|
2077
|
+
seq: this.originSeq++,
|
|
792
2078
|
commitId,
|
|
793
2079
|
path,
|
|
794
2080
|
blobId: "",
|
|
@@ -796,8 +2082,11 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
796
2082
|
suspects: null,
|
|
797
2083
|
guilty: false,
|
|
798
2084
|
next: st.origins,
|
|
2085
|
+
prev: null,
|
|
799
2086
|
};
|
|
2087
|
+
if (st.origins) st.origins.prev = o;
|
|
800
2088
|
st.origins = o;
|
|
2089
|
+
st.originsByPath.set(path, o);
|
|
801
2090
|
return o;
|
|
802
2091
|
}
|
|
803
2092
|
|
|
@@ -806,7 +2095,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
806
2095
|
if (known) return known;
|
|
807
2096
|
const commit = await this.commits.load(commitId).catch(() => undefined);
|
|
808
2097
|
if (!commit) return undefined;
|
|
809
|
-
const st: CommitState = {
|
|
2098
|
+
const st: CommitState = {
|
|
2099
|
+
commit,
|
|
2100
|
+
origins: null,
|
|
2101
|
+
originsByPath: new Map(),
|
|
2102
|
+
uninteresting:
|
|
2103
|
+
this.reverseUninteresting.has(commitId) || this.sinceUninteresting.has(commitId),
|
|
2104
|
+
};
|
|
810
2105
|
this.states.set(commitId, st);
|
|
811
2106
|
return st;
|
|
812
2107
|
}
|
|
@@ -832,7 +2127,13 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
832
2127
|
|
|
833
2128
|
/** Whether a blob is over the threshold (from its size, without reading it). */
|
|
834
2129
|
private async isBig(blobId: ObjectId): Promise<boolean> {
|
|
835
|
-
return (await this.
|
|
2130
|
+
return (await this.blobSize(blobId)) > this.bigFileThreshold;
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
/** A blob's size, the `--contents` buffer's too */
|
|
2134
|
+
private async blobSize(blobId: ObjectId): Promise<number> {
|
|
2135
|
+
const pretended = this.pretend.get(blobId);
|
|
2136
|
+
return pretended ? pretended.length : this.blobs.size(blobId);
|
|
836
2137
|
}
|
|
837
2138
|
|
|
838
2139
|
/**
|
|
@@ -840,6 +2141,8 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
840
2141
|
* comes (a resolved pack object) instead of copying it
|
|
841
2142
|
*/
|
|
842
2143
|
private async readBlob(blobId: ObjectId, shared = false): Promise<Uint8Array> {
|
|
2144
|
+
const pretended = this.pretend.get(blobId);
|
|
2145
|
+
if (pretended) return pretended;
|
|
843
2146
|
const chunks: Uint8Array[] = [];
|
|
844
2147
|
let total = 0;
|
|
845
2148
|
const content = await this.blobs.load(blobId);
|
|
@@ -890,13 +2193,17 @@ export class BlameCommand extends GitCommand<BlameResult> {
|
|
|
890
2193
|
}
|
|
891
2194
|
}
|
|
892
2195
|
|
|
893
|
-
/**
|
|
2196
|
+
/**
|
|
2197
|
+
* git's `blame_chunk`: lines before `tlno` go to the parent, `[tlno, same)` stay, unless
|
|
2198
|
+
* `lineBlames` (an ignored commit's guesses for `[tlno, same)`) passes them to the parent
|
|
2199
|
+
*/
|
|
894
2200
|
function blameChunk(
|
|
895
2201
|
d: { offset: number; dstq: Slot; srcq: Slot },
|
|
896
2202
|
tlno: number,
|
|
897
2203
|
offset: number,
|
|
898
2204
|
same: number,
|
|
899
2205
|
parent: Origin,
|
|
2206
|
+
lineBlames?: LineBlame[],
|
|
900
2207
|
): void {
|
|
901
2208
|
let e = d.srcq.next;
|
|
902
2209
|
let samep: Entry | null = null;
|
|
@@ -921,6 +2228,7 @@ function blameChunk(
|
|
|
921
2228
|
e = reverseBlame(diffp, e);
|
|
922
2229
|
samep = null;
|
|
923
2230
|
diffp = null;
|
|
2231
|
+
let ignoredp: Entry | null = null;
|
|
924
2232
|
while (e && e.sLno < same) {
|
|
925
2233
|
const next: Entry | null = e.next;
|
|
926
2234
|
if (e.sLno + e.numLines > same) {
|
|
@@ -928,14 +2236,67 @@ function blameChunk(
|
|
|
928
2236
|
n.next = samep;
|
|
929
2237
|
samep = n;
|
|
930
2238
|
}
|
|
931
|
-
|
|
932
|
-
|
|
2239
|
+
if (lineBlames) {
|
|
2240
|
+
// ignore_blame_entry: e carved into runs of adjacent lines of one side
|
|
2241
|
+
const base = e.sLno - tlno;
|
|
2242
|
+
const nrLines = e.numLines;
|
|
2243
|
+
let entryLen = 1;
|
|
2244
|
+
let cur: Entry | null = e;
|
|
2245
|
+
for (let i = 0; i < nrLines && cur; i++) {
|
|
2246
|
+
let after: Entry | null = null;
|
|
2247
|
+
if (i + 1 < nrLines) {
|
|
2248
|
+
const a = lineBlames[base + i];
|
|
2249
|
+
const b = lineBlames[base + i + 1];
|
|
2250
|
+
if (a.isParent === b.isParent && a.sLno + 1 === b.sLno) {
|
|
2251
|
+
entryLen++;
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
after = splitBlameAt(cur, entryLen, cur.suspect);
|
|
2255
|
+
}
|
|
2256
|
+
if (lineBlames[base + i].isParent) {
|
|
2257
|
+
cur.ignored = true;
|
|
2258
|
+
cur.suspect = parent;
|
|
2259
|
+
cur.sLno = lineBlames[base + i - entryLen + 1].sLno;
|
|
2260
|
+
cur.next = ignoredp;
|
|
2261
|
+
ignoredp = cur;
|
|
2262
|
+
} else {
|
|
2263
|
+
cur.unblamable = true;
|
|
2264
|
+
cur.next = diffp;
|
|
2265
|
+
diffp = cur;
|
|
2266
|
+
}
|
|
2267
|
+
cur = after;
|
|
2268
|
+
entryLen = 1;
|
|
2269
|
+
}
|
|
2270
|
+
} else {
|
|
2271
|
+
e.next = diffp;
|
|
2272
|
+
diffp = e;
|
|
2273
|
+
}
|
|
933
2274
|
e = next;
|
|
934
2275
|
}
|
|
2276
|
+
if (ignoredp) {
|
|
2277
|
+
// not sorted yet: the parent's list is sorted once every chunk is done
|
|
2278
|
+
d.dstq.next = reverseBlame(ignoredp, d.dstq.next);
|
|
2279
|
+
d.dstq = ignoredp;
|
|
2280
|
+
}
|
|
935
2281
|
d.srcq.next = reverseBlame(diffp, reverseBlame(samep, e));
|
|
936
2282
|
if (diffp) d.srcq = diffp;
|
|
937
2283
|
}
|
|
938
2284
|
|
|
2285
|
+
/** An identity mapped through the mailmap (`map_user`), the same object when nothing changes */
|
|
2286
|
+
function mapIdent(mailmap: Mailmap, ident: PersonIdent): PersonIdent {
|
|
2287
|
+
const m = mailmap.map(ident.name, ident.email);
|
|
2288
|
+
if (m.name === ident.name && m.email === ident.email) return ident;
|
|
2289
|
+
return { ...ident, name: m.name, email: m.email };
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
/** Two names compared as strcmp compares their bytes */
|
|
2293
|
+
function compareBytes(a: string, b: string): number {
|
|
2294
|
+
const x = encodeGitPath(a);
|
|
2295
|
+
const y = encodeGitPath(b);
|
|
2296
|
+
for (let i = 0; i < x.length && i < y.length; i++) if (x[i] !== y[i]) return x[i] - y[i];
|
|
2297
|
+
return x.length - y.length;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
939
2300
|
/** Lines as git counts them: LF-terminated, an unterminated last line one more */
|
|
940
2301
|
function countLines(content: Uint8Array): number {
|
|
941
2302
|
let n = 0;
|
|
@@ -960,6 +2321,44 @@ function algorithmValue(v: string | undefined): XdiffAlgorithm | undefined {
|
|
|
960
2321
|
return s === "myers" || s === "minimal" || s === "patience" || s === "histogram" ? s : undefined;
|
|
961
2322
|
}
|
|
962
2323
|
|
|
2324
|
+
/**
|
|
2325
|
+
* builtin/blame.c's `git_blame_config` for the output: `blame.date`, `blame.showEmail`,
|
|
2326
|
+
* `blame.blankBoundary`, `blame.coloring`, `color.blame.repeatedLines` and
|
|
2327
|
+
* `color.blame.highlightRecent`, read in config order as git reads them
|
|
2328
|
+
*/
|
|
2329
|
+
function blameOutputConfig(config: RemoteConfigStore): BlameOutputConfig {
|
|
2330
|
+
const out: BlameOutputConfig = {};
|
|
2331
|
+
const last = (key: string) => {
|
|
2332
|
+
const values = config.values(key);
|
|
2333
|
+
return values.length > 0 ? values[values.length - 1] : undefined;
|
|
2334
|
+
};
|
|
2335
|
+
const date = last("blame.date");
|
|
2336
|
+
if (date !== undefined) out.date = date;
|
|
2337
|
+
const email = last("blame.showEmail");
|
|
2338
|
+
if (email !== undefined) out.showEmail = boolValue(email) ?? false;
|
|
2339
|
+
const blank = last("blame.blankBoundary");
|
|
2340
|
+
if (blank !== undefined) out.blankBoundary = boolValue(blank) ?? false;
|
|
2341
|
+
const warnings: string[] = [];
|
|
2342
|
+
for (const value of config.values("blame.coloring")) {
|
|
2343
|
+
if (value === "repeatedLines") out.colorLines = true;
|
|
2344
|
+
else if (value === "highlightRecent") out.colorByAge = true;
|
|
2345
|
+
else if (value === "none") {
|
|
2346
|
+
out.colorLines = false;
|
|
2347
|
+
out.colorByAge = false;
|
|
2348
|
+
} else warnings.push(`warning: invalid value for 'blame.coloring': '${value}'`);
|
|
2349
|
+
}
|
|
2350
|
+
for (const value of config.values("color.blame.repeatedLines")) {
|
|
2351
|
+
const color = parseGitColor(value);
|
|
2352
|
+
if (color === undefined) {
|
|
2353
|
+
warnings.push(`warning: invalid value for 'color.blame.repeatedLines': '${value}'`);
|
|
2354
|
+
} else out.repeatedLinesColor = color;
|
|
2355
|
+
}
|
|
2356
|
+
const recent = last("color.blame.highlightRecent");
|
|
2357
|
+
if (recent !== undefined) out.highlightRecent = recent;
|
|
2358
|
+
if (warnings.length > 0) out.warnings = warnings;
|
|
2359
|
+
return out;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
963
2362
|
/**
|
|
964
2363
|
* Create a BlameResult from entries.
|
|
965
2364
|
*/
|