@gitkraken/core-gitlens 0.38.2 → 0.38.4
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/CHANGELOG.md +24 -1
- package/dist/git/parsers/diffParser.d.ts +25 -0
- package/dist/git/parsers/diffParser.js +169 -23
- package/dist/git/parsers/diffParser.js.map +1 -1
- package/dist/git/providers/diff.d.ts +10 -0
- package/dist/git/providers/revision.d.ts +8 -1
- package/dist/git-cli/parsers/blameParser.js +25 -5
- package/dist/git-cli/parsers/blameParser.js.map +1 -1
- package/dist/git-cli/parsers/logParser.js +28 -18
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/parsers/statusParser.d.ts +5 -1
- package/dist/git-cli/parsers/statusParser.js +17 -6
- package/dist/git-cli/parsers/statusParser.js.map +1 -1
- package/dist/git-cli/parsers/treeParser.js +5 -3
- package/dist/git-cli/parsers/treeParser.js.map +1 -1
- package/dist/git-cli/parsers/worktreeParser.js +1 -41
- package/dist/git-cli/parsers/worktreeParser.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +2 -0
- package/dist/git-cli/providers/diff.js +10 -7
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/revision.d.ts +3 -1
- package/dist/git-cli/providers/revision.js +10 -5
- package/dist/git-cli/providers/revision.js.map +1 -1
- package/dist/git-cli/providers/status.js +1 -0
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/plus/git-github/providers/github/revision.d.ts +3 -1
- package/dist/plus/git-github/providers/github/revision.js +1 -1
- package/dist/plus/git-github/providers/github/revision.js.map +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +2 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +23 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/models.d.ts +1 -0
- package/dist/plus/integrations/authentication/models.js.map +1 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +4 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/integrationService.js +7 -1
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +1 -0
- package/dist/plus/integrations/models/integration.js +8 -0
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issuesIntegration.d.ts +5 -0
- package/dist/plus/integrations/models/issuesIntegration.js +33 -1
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +3 -2
- package/dist/plus/integrations/providers/jira.js +36 -17
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/linear.d.ts +1 -0
- package/dist/plus/integrations/providers/linear.js +40 -17
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +6 -3
- package/dist/plus/integrations/providers/utils/discoveryCache.js +12 -6
- package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
- package/dist/utils/string.d.ts +15 -0
- package/dist/utils/string.js +61 -1
- package/dist/utils/string.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Uri } from "../../utils/uri.js";
|
|
2
2
|
import { GitStatus } from "../../git/models/status.js";
|
|
3
3
|
//#region ../git-cli/src/parsers/statusParser.d.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Parses `git status --porcelain[=v2]` output. `-z` output (every record ends with NUL, so a name is exactly as it is on
|
|
6
|
+
* disk) is told by its NUL; without `-z` git C-quotes a name holding a `"`, `\`, tab or newline, which is read as written.
|
|
7
|
+
* Without `getUri`, each file builds its uri on first read rather than during the parse
|
|
8
|
+
*/
|
|
5
9
|
export declare function parseGitStatus(data: string, repoPath: string, porcelainVersion: number, getUri?: (path: string) => Uri): GitStatus | undefined;
|
|
6
10
|
/**
|
|
7
11
|
* Folds `status --ignored=matching --untracked-files=all` records of new untracked folders into the entries that
|
|
@@ -7,6 +7,7 @@ import _usingCtx from "../../_virtual/@oxc-project+runtime/helpers/esm/usingCtx.
|
|
|
7
7
|
const aheadStatusV1Regex = /(?:ahead ([0-9]+))/;
|
|
8
8
|
const behindStatusV1Regex = /(?:behind ([0-9]+))/;
|
|
9
9
|
const quoteRegex = /"/g;
|
|
10
|
+
const renameStatusV1Regex = /[RC]/;
|
|
10
11
|
const submoduleCharCode = "S".charCodeAt(0);
|
|
11
12
|
/** Returns the index just after the `n`th space, or -1 if the line has fewer than `n` spaces. */
|
|
12
13
|
function indexAfterNthSpace(line, n) {
|
|
@@ -17,7 +18,11 @@ function indexAfterNthSpace(line, n) {
|
|
|
17
18
|
}
|
|
18
19
|
return index + 1;
|
|
19
20
|
}
|
|
20
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Parses `git status --porcelain[=v2]` output. `-z` output (every record ends with NUL, so a name is exactly as it is on
|
|
23
|
+
* disk) is told by its NUL; without `-z` git C-quotes a name holding a `"`, `\`, tab or newline, which is read as written.
|
|
24
|
+
* Without `getUri`, each file builds its uri on first read rather than during the parse
|
|
25
|
+
*/
|
|
21
26
|
function parseGitStatus(data, repoPath, porcelainVersion, getUri) {
|
|
22
27
|
try {
|
|
23
28
|
var _usingCtx$1 = _usingCtx();
|
|
@@ -29,12 +34,13 @@ function parseGitStatus(data, repoPath, porcelainVersion, getUri) {
|
|
|
29
34
|
sw?.stop({ suffix: ` no data` });
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
|
-
const
|
|
37
|
+
const nullTerminated = data.includes("\0");
|
|
38
|
+
const lines = data.split(nullTerminated ? "\0" : "\n").filter((i) => Boolean(i));
|
|
33
39
|
if (lines.length === 0) {
|
|
34
40
|
sw?.stop({ suffix: ` parsed no files` });
|
|
35
41
|
return;
|
|
36
42
|
}
|
|
37
|
-
const status = porcelainVersion < 2 ? parseStatusV1(lines, repoPath, getUri) : parseStatusV2(lines, repoPath, getUri);
|
|
43
|
+
const status = porcelainVersion < 2 ? parseStatusV1(lines, repoPath, getUri, nullTerminated) : parseStatusV2(lines, repoPath, getUri, nullTerminated);
|
|
38
44
|
sw?.stop({ suffix: ` parsed ${status.files.length} files` });
|
|
39
45
|
return status;
|
|
40
46
|
} catch (_) {
|
|
@@ -43,7 +49,7 @@ function parseGitStatus(data, repoPath, porcelainVersion, getUri) {
|
|
|
43
49
|
_usingCtx$1.d();
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
|
-
function parseStatusV1(lines, repoPath, getUri) {
|
|
52
|
+
function parseStatusV1(lines, repoPath, getUri, nullTerminated) {
|
|
47
53
|
let branch;
|
|
48
54
|
const files = [];
|
|
49
55
|
const state = {
|
|
@@ -74,7 +80,8 @@ function parseStatusV1(lines, repoPath, getUri) {
|
|
|
74
80
|
} else {
|
|
75
81
|
const rawStatus = line.substring(0, 2);
|
|
76
82
|
const fileName = line.substring(3);
|
|
77
|
-
if (
|
|
83
|
+
if (nullTerminated && renameStatusV1Regex.test(rawStatus)) files.push(parseStatusFile(repoPath, rawStatus, fileName, getUri, lines[++position]));
|
|
84
|
+
else if (!nullTerminated && (rawStatus.startsWith("R") || rawStatus.startsWith("C"))) {
|
|
78
85
|
const [file1, file2] = fileName.replace(quoteRegex, "").split(" -> ");
|
|
79
86
|
files.push(parseStatusFile(repoPath, rawStatus, file2.trim(), getUri, file1.trim()));
|
|
80
87
|
} else files.push(parseStatusFile(repoPath, rawStatus, fileName, getUri));
|
|
@@ -86,7 +93,7 @@ function parseStatusV1(lines, repoPath, getUri) {
|
|
|
86
93
|
state
|
|
87
94
|
} : void 0);
|
|
88
95
|
}
|
|
89
|
-
function parseStatusV2(lines, repoPath, getUri) {
|
|
96
|
+
function parseStatusV2(lines, repoPath, getUri, nullTerminated) {
|
|
90
97
|
let branch;
|
|
91
98
|
const files = [];
|
|
92
99
|
let sha;
|
|
@@ -142,6 +149,10 @@ function parseStatusV2(lines, repoPath, getUri) {
|
|
|
142
149
|
previousOid: parts[6]
|
|
143
150
|
};
|
|
144
151
|
}
|
|
152
|
+
if (nullTerminated) {
|
|
153
|
+
files.push(parseStatusFile(repoPath, line.substring(2, 4), line.substring(pathStart), getUri, lines[++position], submodule));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
145
156
|
const tab = line.indexOf(" ", pathStart);
|
|
146
157
|
files.push(parseStatusFile(repoPath, line.substring(2, 4), tab === -1 ? line.substring(pathStart) : line.substring(pathStart, tab), getUri, tab === -1 ? void 0 : line.substring(tab + 1), submodule));
|
|
147
158
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statusParser.js","names":[],"sources":["../../../../git-cli/src/parsers/statusParser.ts"],"sourcesContent":["import { GitStatus } from '@gitlens/git/models/status.js';\nimport { GitStatusFile } from '@gitlens/git/models/statusFile.js';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport type { Uri } from '@gitlens/utils/uri.js';\n\nconst aheadStatusV1Regex = /(?:ahead ([0-9]+))/;\nconst behindStatusV1Regex = /(?:behind ([0-9]+))/;\nconst quoteRegex = /\"/g;\nconst submoduleCharCode = 'S'.charCodeAt(0);\n\n/** Returns the index just after the `n`th space, or -1 if the line has fewer than `n` spaces. */\nfunction indexAfterNthSpace(line: string, n: number): number {\n\tlet index = -1;\n\tfor (let i = 0; i < n; i++) {\n\t\tindex = line.indexOf(' ', index + 1);\n\t\tif (index === -1) return -1;\n\t}\n\n\treturn index + 1;\n}\n\n/** Without `getUri`, each file builds its uri on first read rather than during the parse */\nexport function parseGitStatus(\n\tdata: string,\n\trepoPath: string,\n\tporcelainVersion: number,\n\tgetUri?: (path: string) => Uri,\n): GitStatus | undefined {\n\tusing sw = maybeStopWatch(`Git.parseStatus(${repoPath}, v=${porcelainVersion})`, {\n\t\tlog: { onlyExit: true, level: 'debug' },\n\t});\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn undefined;\n\t}\n\n\tconst lines = data.split('\\n').filter(<T>(i?: T): i is T => Boolean(i));\n\tif (lines.length === 0) {\n\t\tsw?.stop({ suffix: ` parsed no files` });\n\t\treturn undefined;\n\t}\n\n\tconst status =\n\t\tporcelainVersion < 2 ? parseStatusV1(lines, repoPath, getUri) : parseStatusV2(lines, repoPath, getUri);\n\n\tsw?.stop({ suffix: ` parsed ${status.files.length} files` });\n\n\treturn status;\n}\n\nfunction parseStatusV1(lines: string[], repoPath: string, getUri: ((path: string) => Uri) | undefined): GitStatus {\n\tlet branch: string | undefined;\n\tconst files = [];\n\tconst state = {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t};\n\tlet upstream;\n\tlet missing = false;\n\n\tlet position = -1;\n\twhile (++position < lines.length) {\n\t\tconst line = lines[position];\n\t\t// Header\n\t\tif (line.startsWith('##')) {\n\t\t\tconst lineParts = line.split(' ');\n\t\t\t[branch, upstream] = lineParts[1].split('...');\n\t\t\tif (lineParts.length > 2) {\n\t\t\t\tconst upstreamStatus = lineParts.slice(2).join(' ');\n\t\t\t\tif (upstreamStatus === '[gone]') {\n\t\t\t\t\tmissing = true;\n\t\t\t\t\tstate.ahead = 0;\n\t\t\t\t\tstate.behind = 0;\n\t\t\t\t} else {\n\t\t\t\t\tconst aheadStatus = aheadStatusV1Regex.exec(upstreamStatus);\n\t\t\t\t\tstate.ahead = aheadStatus == null ? 0 : Number(aheadStatus[1]) || 0;\n\n\t\t\t\t\tconst behindStatus = behindStatusV1Regex.exec(upstreamStatus);\n\t\t\t\t\tstate.behind = behindStatus == null ? 0 : Number(behindStatus[1]) || 0;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst rawStatus = line.substring(0, 2);\n\t\t\tconst fileName = line.substring(3);\n\t\t\tif (rawStatus.startsWith('R') || rawStatus.startsWith('C')) {\n\t\t\t\tconst [file1, file2] = fileName.replace(quoteRegex, '').split(' -> ');\n\t\t\t\tfiles.push(parseStatusFile(repoPath, rawStatus, file2.trim(), getUri, file1.trim()));\n\t\t\t} else {\n\t\t\t\tfiles.push(parseStatusFile(repoPath, rawStatus, fileName, getUri));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn new GitStatus(\n\t\tnormalizePath(repoPath),\n\t\tbranch ?? '',\n\t\t'',\n\t\tfiles,\n\t\tupstream ? { name: upstream, missing: missing, state: state } : undefined,\n\t);\n}\n\nfunction parseStatusV2(lines: string[], repoPath: string, getUri: ((path: string) => Uri) | undefined): GitStatus {\n\tlet branch: string | undefined;\n\tconst files = [];\n\tlet sha: string | undefined;\n\tconst state = {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t};\n\tlet missing = true;\n\tlet upstream;\n\n\tlet position = -1;\n\twhile (++position < lines.length) {\n\t\tconst line = lines[position];\n\t\t// Headers\n\t\tif (line.startsWith('#')) {\n\t\t\tconst lineParts = line.split(' ');\n\t\t\tswitch (lineParts[1]) {\n\t\t\t\tcase 'branch.oid':\n\t\t\t\t\tsha = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.head':\n\t\t\t\t\tbranch = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.upstream':\n\t\t\t\t\tupstream = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.ab':\n\t\t\t\t\tmissing = false;\n\t\t\t\t\tstate.ahead = Number(lineParts[2].substring(1));\n\t\t\t\t\tstate.behind = Number(lineParts[3].substring(1));\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (line[0]) {\n\t\t\t\tcase '1': {\n\t\t\t\t\t// normal: 1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 8);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\t// <sub> starts with 'S' if submodule, 'N' if not\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[7], previousOid: parts[6] };\n\t\t\t\t\t}\n\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\tline.substring(pathStart),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '2': {\n\t\t\t\t\t// rename: 2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path>\\t<origPath>\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 9);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[7], previousOid: parts[6] };\n\t\t\t\t\t}\n\n\t\t\t\t\tconst tab = line.indexOf('\\t', pathStart);\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\ttab === -1 ? line.substring(pathStart) : line.substring(pathStart, tab),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\ttab === -1 ? undefined : line.substring(tab + 1),\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'u': {\n\t\t\t\t\t// unmerged: u <XY> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 10);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[9], previousOid: parts[7] };\n\t\t\t\t\t}\n\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\tline.substring(pathStart),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '?': // untracked\n\t\t\t\t\tfiles.push(parseStatusFile(repoPath, '??', line.substring(2), getUri));\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn new GitStatus(\n\t\tnormalizePath(repoPath),\n\t\tbranch ?? '',\n\t\tsha ?? '',\n\t\tfiles,\n\t\tupstream ? { name: upstream, missing: missing, state: state } : undefined,\n\t);\n}\n\nfunction parseStatusFile(\n\trepoPath: string,\n\trawStatus: string,\n\tfileName: string,\n\tgetUri: ((path: string) => Uri) | undefined,\n\toriginalFileName?: string,\n\tsubmodule?: { readonly oid: string; readonly previousOid?: string },\n): GitStatusFile {\n\tlet x = !rawStatus.startsWith('.') ? rawStatus[0].trim() : undefined;\n\tif (x == null || x.length === 0) {\n\t\tx = undefined;\n\t}\n\n\tlet y = undefined;\n\tif (rawStatus.length > 1) {\n\t\ty = rawStatus[1] !== '.' ? rawStatus[1].trim() : undefined;\n\t\tif (y == null || y.length === 0) {\n\t\t\ty = undefined;\n\t\t}\n\t}\n\n\treturn new GitStatusFile(repoPath, x, y, fileName, getUri?.(fileName), originalFileName, submodule);\n}\n\n/**\n * Folds `status --ignored=matching --untracked-files=all` records of new untracked folders into the entries that\n * `--ignored=traditional --untracked-files=normal` reports. Inside a new untracked folder nothing is tracked, so a\n * folder holding no untracked content is wholly ignored, and is reported in place of the ignored paths beneath it.\n */\nexport function foldMatchingIgnored(records: Iterable<string>): string[] {\n\tconst dirty = new Set<string>();\n\tconst ignored: string[] = [];\n\n\tfor (const record of records) {\n\t\tif (record.length < 4) continue;\n\n\t\tif (record.startsWith('!! ')) {\n\t\t\tignored.push(record.substring(3));\n\t\t} else if (record.startsWith('?? ')) {\n\t\t\tconst path = record.substring(3);\n\t\t\tfor (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {\n\t\t\t\tdirty.add(path.substring(0, i + 1));\n\t\t\t}\n\t\t}\n\t}\n\n\tconst entries = new Set<string>();\n\tfor (const path of ignored) {\n\t\tlet entry = path;\n\t\tfor (let i = path.indexOf('/'); i !== -1 && i + 1 < path.length; i = path.indexOf('/', i + 1)) {\n\t\t\tconst folder = path.substring(0, i + 1);\n\t\t\tif (!dirty.has(folder)) {\n\t\t\t\tentry = folder;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tentries.add(entry);\n\t}\n\treturn [...entries];\n}\n"],"mappings":";;;;;;AAMA,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,aAAa;AACnB,MAAM,oBAAoB,IAAI,WAAW,CAAC;;AAG1C,SAAS,mBAAmB,MAAc,GAAmB;CAC5D,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EAC3B,QAAQ,KAAK,QAAQ,KAAK,QAAQ,CAAC;EACnC,IAAI,UAAU,IAAI,OAAO;CAC1B;CAEA,OAAO,QAAQ;AAChB;;AAGA,SAAgB,eACf,MACA,UACA,kBACA,QACwB;;;EACxB,MAAM,KAAA,YAAA,EAAK,eAAe,mBAAmB,SAAS,MAAM,iBAAiB,IAAI,EAChF,KAAK;GAAE,UAAU;GAAM,OAAO;EAAQ,EACvC,CAAC,CAAA;EACD,IAAI,CAAC,MAAM;GACV,IAAI,KAAK,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M,GAAG;IACvB,QAAQ;IACR;GACD;EACD;EACA,QAAQ,IAAI,KAAK;CAClB;CACA,OAAO,CAAC,GAAG,OAAO;AACnB"}
|
|
1
|
+
{"version":3,"file":"statusParser.js","names":[],"sources":["../../../../git-cli/src/parsers/statusParser.ts"],"sourcesContent":["import { GitStatus } from '@gitlens/git/models/status.js';\nimport { GitStatusFile } from '@gitlens/git/models/statusFile.js';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport type { Uri } from '@gitlens/utils/uri.js';\n\nconst aheadStatusV1Regex = /(?:ahead ([0-9]+))/;\nconst behindStatusV1Regex = /(?:behind ([0-9]+))/;\nconst quoteRegex = /\"/g;\nconst renameStatusV1Regex = /[RC]/;\nconst submoduleCharCode = 'S'.charCodeAt(0);\n\n/** Returns the index just after the `n`th space, or -1 if the line has fewer than `n` spaces. */\nfunction indexAfterNthSpace(line: string, n: number): number {\n\tlet index = -1;\n\tfor (let i = 0; i < n; i++) {\n\t\tindex = line.indexOf(' ', index + 1);\n\t\tif (index === -1) return -1;\n\t}\n\n\treturn index + 1;\n}\n\n/**\n * Parses `git status --porcelain[=v2]` output. `-z` output (every record ends with NUL, so a name is exactly as it is on\n * disk) is told by its NUL; without `-z` git C-quotes a name holding a `\"`, `\\`, tab or newline, which is read as written.\n * Without `getUri`, each file builds its uri on first read rather than during the parse\n */\nexport function parseGitStatus(\n\tdata: string,\n\trepoPath: string,\n\tporcelainVersion: number,\n\tgetUri?: (path: string) => Uri,\n): GitStatus | undefined {\n\tusing sw = maybeStopWatch(`Git.parseStatus(${repoPath}, v=${porcelainVersion})`, {\n\t\tlog: { onlyExit: true, level: 'debug' },\n\t});\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn undefined;\n\t}\n\n\tconst nullTerminated = data.includes('\\0');\n\tconst lines = data.split(nullTerminated ? '\\0' : '\\n').filter(<T>(i?: T): i is T => Boolean(i));\n\tif (lines.length === 0) {\n\t\tsw?.stop({ suffix: ` parsed no files` });\n\t\treturn undefined;\n\t}\n\n\tconst status =\n\t\tporcelainVersion < 2\n\t\t\t? parseStatusV1(lines, repoPath, getUri, nullTerminated)\n\t\t\t: parseStatusV2(lines, repoPath, getUri, nullTerminated);\n\n\tsw?.stop({ suffix: ` parsed ${status.files.length} files` });\n\n\treturn status;\n}\n\nfunction parseStatusV1(\n\tlines: string[],\n\trepoPath: string,\n\tgetUri: ((path: string) => Uri) | undefined,\n\tnullTerminated: boolean,\n): GitStatus {\n\tlet branch: string | undefined;\n\tconst files = [];\n\tconst state = {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t};\n\tlet upstream;\n\tlet missing = false;\n\n\tlet position = -1;\n\twhile (++position < lines.length) {\n\t\tconst line = lines[position];\n\t\t// Header\n\t\tif (line.startsWith('##')) {\n\t\t\tconst lineParts = line.split(' ');\n\t\t\t[branch, upstream] = lineParts[1].split('...');\n\t\t\tif (lineParts.length > 2) {\n\t\t\t\tconst upstreamStatus = lineParts.slice(2).join(' ');\n\t\t\t\tif (upstreamStatus === '[gone]') {\n\t\t\t\t\tmissing = true;\n\t\t\t\t\tstate.ahead = 0;\n\t\t\t\t\tstate.behind = 0;\n\t\t\t\t} else {\n\t\t\t\t\tconst aheadStatus = aheadStatusV1Regex.exec(upstreamStatus);\n\t\t\t\t\tstate.ahead = aheadStatus == null ? 0 : Number(aheadStatus[1]) || 0;\n\n\t\t\t\t\tconst behindStatus = behindStatusV1Regex.exec(upstreamStatus);\n\t\t\t\t\tstate.behind = behindStatus == null ? 0 : Number(behindStatus[1]) || 0;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst rawStatus = line.substring(0, 2);\n\t\t\tconst fileName = line.substring(3);\n\t\t\tif (nullTerminated && renameStatusV1Regex.test(rawStatus)) {\n\t\t\t\t// `XY <to>` and then `<from>` as a record of its own, which git writes for a rename in the working\n\t\t\t\t// tree (` R`) as well as in the index\n\t\t\t\tfiles.push(parseStatusFile(repoPath, rawStatus, fileName, getUri, lines[++position]));\n\t\t\t} else if (!nullTerminated && (rawStatus.startsWith('R') || rawStatus.startsWith('C'))) {\n\t\t\t\tconst [file1, file2] = fileName.replace(quoteRegex, '').split(' -> ');\n\t\t\t\tfiles.push(parseStatusFile(repoPath, rawStatus, file2.trim(), getUri, file1.trim()));\n\t\t\t} else {\n\t\t\t\tfiles.push(parseStatusFile(repoPath, rawStatus, fileName, getUri));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn new GitStatus(\n\t\tnormalizePath(repoPath),\n\t\tbranch ?? '',\n\t\t'',\n\t\tfiles,\n\t\tupstream ? { name: upstream, missing: missing, state: state } : undefined,\n\t);\n}\n\nfunction parseStatusV2(\n\tlines: string[],\n\trepoPath: string,\n\tgetUri: ((path: string) => Uri) | undefined,\n\tnullTerminated: boolean,\n): GitStatus {\n\tlet branch: string | undefined;\n\tconst files = [];\n\tlet sha: string | undefined;\n\tconst state = {\n\t\tahead: 0,\n\t\tbehind: 0,\n\t};\n\tlet missing = true;\n\tlet upstream;\n\n\tlet position = -1;\n\twhile (++position < lines.length) {\n\t\tconst line = lines[position];\n\t\t// Headers\n\t\tif (line.startsWith('#')) {\n\t\t\tconst lineParts = line.split(' ');\n\t\t\tswitch (lineParts[1]) {\n\t\t\t\tcase 'branch.oid':\n\t\t\t\t\tsha = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.head':\n\t\t\t\t\tbranch = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.upstream':\n\t\t\t\t\tupstream = lineParts[2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'branch.ab':\n\t\t\t\t\tmissing = false;\n\t\t\t\t\tstate.ahead = Number(lineParts[2].substring(1));\n\t\t\t\t\tstate.behind = Number(lineParts[3].substring(1));\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tswitch (line[0]) {\n\t\t\t\tcase '1': {\n\t\t\t\t\t// normal: 1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 8);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\t// <sub> starts with 'S' if submodule, 'N' if not\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[7], previousOid: parts[6] };\n\t\t\t\t\t}\n\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\tline.substring(pathStart),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '2': {\n\t\t\t\t\t// rename: 2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path>\\t<origPath> (`<path>\\0<origPath>` with -z)\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 9);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[7], previousOid: parts[6] };\n\t\t\t\t\t}\n\n\t\t\t\t\tif (nullTerminated) {\n\t\t\t\t\t\t// `<path>` and then `<origPath>` as a record of its own\n\t\t\t\t\t\tfiles.push(\n\t\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\t\tline.substring(pathStart),\n\t\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\t\tlines[++position],\n\t\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst tab = line.indexOf('\\t', pathStart);\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\ttab === -1 ? line.substring(pathStart) : line.substring(pathStart, tab),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\ttab === -1 ? undefined : line.substring(tab + 1),\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'u': {\n\t\t\t\t\t// unmerged: u <XY> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>\n\t\t\t\t\tconst pathStart = indexAfterNthSpace(line, 10);\n\t\t\t\t\tif (pathStart === -1) break;\n\n\t\t\t\t\tlet submodule;\n\t\t\t\t\tif (line.charCodeAt(5) === submoduleCharCode) {\n\t\t\t\t\t\tconst parts = line.split(' ');\n\t\t\t\t\t\tsubmodule = { oid: parts[9], previousOid: parts[7] };\n\t\t\t\t\t}\n\n\t\t\t\t\tfiles.push(\n\t\t\t\t\t\tparseStatusFile(\n\t\t\t\t\t\t\trepoPath,\n\t\t\t\t\t\t\tline.substring(2, 4),\n\t\t\t\t\t\t\tline.substring(pathStart),\n\t\t\t\t\t\t\tgetUri,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tsubmodule,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase '?': // untracked\n\t\t\t\t\tfiles.push(parseStatusFile(repoPath, '??', line.substring(2), getUri));\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn new GitStatus(\n\t\tnormalizePath(repoPath),\n\t\tbranch ?? '',\n\t\tsha ?? '',\n\t\tfiles,\n\t\tupstream ? { name: upstream, missing: missing, state: state } : undefined,\n\t);\n}\n\nfunction parseStatusFile(\n\trepoPath: string,\n\trawStatus: string,\n\tfileName: string,\n\tgetUri: ((path: string) => Uri) | undefined,\n\toriginalFileName?: string,\n\tsubmodule?: { readonly oid: string; readonly previousOid?: string },\n): GitStatusFile {\n\tlet x = !rawStatus.startsWith('.') ? rawStatus[0].trim() : undefined;\n\tif (x == null || x.length === 0) {\n\t\tx = undefined;\n\t}\n\n\tlet y = undefined;\n\tif (rawStatus.length > 1) {\n\t\ty = rawStatus[1] !== '.' ? rawStatus[1].trim() : undefined;\n\t\tif (y == null || y.length === 0) {\n\t\t\ty = undefined;\n\t\t}\n\t}\n\n\treturn new GitStatusFile(repoPath, x, y, fileName, getUri?.(fileName), originalFileName, submodule);\n}\n\n/**\n * Folds `status --ignored=matching --untracked-files=all` records of new untracked folders into the entries that\n * `--ignored=traditional --untracked-files=normal` reports. Inside a new untracked folder nothing is tracked, so a\n * folder holding no untracked content is wholly ignored, and is reported in place of the ignored paths beneath it.\n */\nexport function foldMatchingIgnored(records: Iterable<string>): string[] {\n\tconst dirty = new Set<string>();\n\tconst ignored: string[] = [];\n\n\tfor (const record of records) {\n\t\tif (record.length < 4) continue;\n\n\t\tif (record.startsWith('!! ')) {\n\t\t\tignored.push(record.substring(3));\n\t\t} else if (record.startsWith('?? ')) {\n\t\t\tconst path = record.substring(3);\n\t\t\tfor (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {\n\t\t\t\tdirty.add(path.substring(0, i + 1));\n\t\t\t}\n\t\t}\n\t}\n\n\tconst entries = new Set<string>();\n\tfor (const path of ignored) {\n\t\tlet entry = path;\n\t\tfor (let i = path.indexOf('/'); i !== -1 && i + 1 < path.length; i = path.indexOf('/', i + 1)) {\n\t\t\tconst folder = path.substring(0, i + 1);\n\t\t\tif (!dirty.has(folder)) {\n\t\t\t\tentry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
-
line = line.trim();
|
|
24
|
+
for (const line of singleEntry ? data.split("\0") : iterateByDelimiter(data, "\0")) {
|
|
26
25
|
if (!line) continue;
|
|
27
|
-
|
|
26
|
+
startIndex = line.indexOf(" ");
|
|
27
|
+
if (startIndex === -1) continue;
|
|
28
|
+
metadata = line.substring(0, startIndex);
|
|
29
|
+
path = line.substring(startIndex + 1);
|
|
28
30
|
startIndex = metadata.indexOf(" ");
|
|
29
31
|
if (startIndex === -1) continue;
|
|
30
32
|
startIndex++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeParser.js","names":[],"sources":["../../../../git-cli/src/parsers/treeParser.ts"],"sourcesContent":["import type { GitTreeEntry, GitTreeType } from '@gitlens/git/models/tree.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport { iterateByDelimiter } from '@gitlens/utils/string.js';\n\nexport function parseGitTree(data: string | undefined, ref: string, singleEntry: boolean): GitTreeEntry[] {\n\tusing sw = maybeStopWatch(`Git.parseTree`, { log: { onlyExit: true, level: 'debug' } });\n\n\tconst trees: GitTreeEntry[] = [];\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn trees;\n\t}\n\n\t// Format: <mode> <type> <oid> <size>\\t<path
|
|
1
|
+
{"version":3,"file":"treeParser.js","names":[],"sources":["../../../../git-cli/src/parsers/treeParser.ts"],"sourcesContent":["import type { GitTreeEntry, GitTreeType } from '@gitlens/git/models/tree.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport { iterateByDelimiter } from '@gitlens/utils/string.js';\n\nexport function parseGitTree(data: string | undefined, ref: string, singleEntry: boolean): GitTreeEntry[] {\n\tusing sw = maybeStopWatch(`Git.parseTree`, { log: { onlyExit: true, level: 'debug' } });\n\n\tconst trees: GitTreeEntry[] = [];\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn trees;\n\t}\n\n\t// Format (`-z`, so a path is as it is on disk rather than C-quoted): <mode> <type> <oid> <size>\\t<path>\\0\n\n\tlet metadata: string;\n\tlet oid: string;\n\tlet size: number;\n\tlet type: GitTreeType;\n\tlet path: string;\n\n\tlet startIndex: number;\n\tlet endIndex: number;\n\n\t// Avoid generator if we are only parsing a single entry\n\tfor (const line of singleEntry ? data.split('\\0') : iterateByDelimiter(data, '\\0')) {\n\t\tif (!line) continue;\n\n\t\t// The first tab ends the metadata; a path can hold tabs itself\n\t\tstartIndex = line.indexOf('\\t');\n\t\tif (startIndex === -1) continue;\n\n\t\tmetadata = line.substring(0, startIndex);\n\t\tpath = line.substring(startIndex + 1);\n\n\t\t// Skip mode\n\t\tstartIndex = metadata.indexOf(' ');\n\t\tif (startIndex === -1) continue;\n\n\t\t// Parse type\n\t\tstartIndex++;\n\t\tendIndex = metadata.indexOf(' ', startIndex);\n\t\tif (endIndex === -1) continue;\n\n\t\ttype = metadata.substring(startIndex, endIndex) as GitTreeType;\n\n\t\t// Parse oid\n\t\tstartIndex = endIndex + 1;\n\t\tendIndex = metadata.indexOf(' ', startIndex);\n\t\tif (endIndex === -1) continue;\n\n\t\toid = metadata.substring(startIndex, endIndex);\n\n\t\t// Parse size\n\t\tstartIndex = endIndex + 1;\n\n\t\tsize = parseInt(metadata.substring(startIndex), 10);\n\n\t\ttrees.push({ ref: ref, oid: oid, path: path || '', size: isNaN(size) ? 0 : size, type: type || 'blob' });\n\t}\n\n\tsw?.stop({ suffix: ` parsed ${trees.length} trees` });\n\n\treturn trees;\n}\n"],"mappings":";;;;AAIA,SAAgB,aAAa,MAA0B,KAAa,aAAsC;;;EACzG,MAAM,KAAA,YAAA,EAAK,eAAe,iBAAiB,EAAE,KAAK;GAAE,UAAU;GAAM,OAAO;EAAQ,EAAE,CAAC,CAAA;EAEtF,MAAM,QAAwB,CAAC;EAC/B,IAAI,CAAC,MAAM;GACV,IAAI,KAAK,EAAE,QAAQ,WAAW,CAAC;GAC/B,OAAO;EACR;EAIA,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EAEJ,IAAI;EACJ,IAAI;EAGJ,KAAK,MAAM,QAAQ,cAAc,KAAK,MAAM,IAAI,IAAI,mBAAmB,MAAM,IAAI,GAAG;GACnF,IAAI,CAAC,MAAM;GAGX,aAAa,KAAK,QAAQ,GAAI;GAC9B,IAAI,eAAe,IAAI;GAEvB,WAAW,KAAK,UAAU,GAAG,UAAU;GACvC,OAAO,KAAK,UAAU,aAAa,CAAC;GAGpC,aAAa,SAAS,QAAQ,GAAG;GACjC,IAAI,eAAe,IAAI;GAGvB;GACA,WAAW,SAAS,QAAQ,KAAK,UAAU;GAC3C,IAAI,aAAa,IAAI;GAErB,OAAO,SAAS,UAAU,YAAY,QAAQ;GAG9C,aAAa,WAAW;GACxB,WAAW,SAAS,QAAQ,KAAK,UAAU;GAC3C,IAAI,aAAa,IAAI;GAErB,MAAM,SAAS,UAAU,YAAY,QAAQ;GAG7C,aAAa,WAAW;GAExB,OAAO,SAAS,SAAS,UAAU,UAAU,GAAG,EAAE;GAElD,MAAM,KAAK;IAAO;IAAU;IAAK,MAAM,QAAQ;IAAI,MAAM,MAAM,IAAI,IAAI,IAAI;IAAM,MAAM,QAAQ;GAAO,CAAC;EACxG;EAEA,IAAI,KAAK,EAAE,QAAQ,WAAW,MAAM,OAAO,QAAQ,CAAC;EAEpD,OAAO;;;;;;AACR"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { iterateByDelimiter } from "../../utils/string.js";
|
|
1
|
+
import { iterateByDelimiter, unquoteCString } from "../../utils/string.js";
|
|
2
2
|
import { fileUri } from "../../utils/uri.js";
|
|
3
3
|
import { normalizePath } from "../../utils/path.js";
|
|
4
4
|
import { maybeStopWatch } from "../../utils/stopwatch.js";
|
|
@@ -72,46 +72,6 @@ function parseGitWorktrees(data, repoPath, branches, getWorkspaceFolder) {
|
|
|
72
72
|
_usingCtx$1.d();
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const cEscapes = {
|
|
76
|
-
a: 7,
|
|
77
|
-
b: 8,
|
|
78
|
-
f: 12,
|
|
79
|
-
n: 10,
|
|
80
|
-
r: 13,
|
|
81
|
-
t: 9,
|
|
82
|
-
v: 11,
|
|
83
|
-
"\\": 92,
|
|
84
|
-
"\"": 34
|
|
85
|
-
};
|
|
86
|
-
/** Reverses Git's C-style quoting (`"a\nb"`, `\303\251` octal UTF-8 bytes); returns unquoted values as-is */
|
|
87
|
-
function unquoteCString(value) {
|
|
88
|
-
if (!value.startsWith("\"")) return value;
|
|
89
|
-
const end = value.length > 1 && value.endsWith("\"") ? value.length - 1 : value.length;
|
|
90
|
-
const encoder = new TextEncoder();
|
|
91
|
-
const bytes = [];
|
|
92
|
-
let i = 1;
|
|
93
|
-
while (i < end) {
|
|
94
|
-
if (value[i] !== "\\" || i + 1 >= end) {
|
|
95
|
-
const cp = String.fromCodePoint(value.codePointAt(i));
|
|
96
|
-
bytes.push(...encoder.encode(cp));
|
|
97
|
-
i += cp.length;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const next = value[i + 1];
|
|
101
|
-
if (next >= "0" && next <= "7") {
|
|
102
|
-
let j = i + 1;
|
|
103
|
-
while (j < i + 4 && j < end && value[j] >= "0" && value[j] <= "7") j++;
|
|
104
|
-
bytes.push(Number.parseInt(value.substring(i + 1, j), 8) & 255);
|
|
105
|
-
i = j;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const code = cEscapes[next];
|
|
109
|
-
if (code != null) bytes.push(code);
|
|
110
|
-
else bytes.push(...encoder.encode(next));
|
|
111
|
-
i += 2;
|
|
112
|
-
}
|
|
113
|
-
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
114
|
-
}
|
|
115
75
|
//#endregion
|
|
116
76
|
export { parseGitWorktrees };
|
|
117
77
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktreeParser.js","names":[],"sources":["../../../../git-cli/src/parsers/worktreeParser.ts"],"sourcesContent":["import type { GitBranch } from '@gitlens/git/models/branch.js';\nimport type { WorkspaceFolderResolver } from '@gitlens/git/models/worktree.js';\nimport { GitWorktree } from '@gitlens/git/models/worktree.js';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport { iterateByDelimiter } from '@gitlens/utils/string.js';\nimport { fileUri } from '@gitlens/utils/uri.js';\n\ninterface WorktreeEntry {\n\tpath: string;\n\tsha?: string;\n\tbranch?: string;\n\tbare: boolean;\n\tdetached: boolean;\n\tlocked?: boolean | string;\n\tprunable?: boolean | string;\n}\n\nexport function parseGitWorktrees(\n\tdata: string | undefined,\n\trepoPath: string,\n\tbranches: GitBranch[],\n\tgetWorkspaceFolder?: WorkspaceFolderResolver,\n): GitWorktree[] {\n\tusing sw = maybeStopWatch(`Git.parseWorktrees(${repoPath})`, { log: { onlyExit: true, level: 'debug' } });\n\n\tconst worktrees: GitWorktree[] = [];\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn worktrees;\n\t}\n\n\tif (repoPath != null) {\n\t\trepoPath = normalizePath(repoPath);\n\t}\n\n\tlet entry: Partial<WorktreeEntry> | undefined = undefined;\n\tlet line: string;\n\tlet index: number;\n\tlet key: string;\n\tlet value: string;\n\tlet main = true; // the first worktree is the main worktree\n\n\tfor (line of iterateByDelimiter(data, '\\n')) {\n\t\tindex = line.indexOf(' ');\n\t\tif (index === -1) {\n\t\t\tkey = line;\n\t\t\tvalue = '';\n\t\t} else {\n\t\t\tkey = line.substring(0, index);\n\t\t\tvalue = line.substring(index + 1);\n\t\t}\n\n\t\tif (!key && entry != null) {\n\t\t\t// oxlint-disable-next-line no-loop-func\n\t\t\tconst branch = entry.branch ? branches?.find(b => b.name === entry!.branch) : undefined;\n\t\t\tconst uri = fileUri(entry.path!);\n\n\t\t\tworktrees.push(\n\t\t\t\tnew GitWorktree(\n\t\t\t\t\tmain,\n\t\t\t\t\tentry.bare ? 'bare' : entry.detached ? 'detached' : 'branch',\n\t\t\t\t\trepoPath,\n\t\t\t\t\turi,\n\t\t\t\t\tentry.locked ?? false,\n\t\t\t\t\tentry.prunable ?? false,\n\t\t\t\t\tentry.sha,\n\t\t\t\t\tbranch,\n\t\t\t\t\tgetWorkspaceFolder?.(uri),\n\t\t\t\t\tentry.branch,\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tentry = undefined;\n\t\t\tmain = false;\n\t\t\tcontinue;\n\t\t}\n\n\t\tentry ??= {};\n\n\t\tswitch (key) {\n\t\t\tcase 'worktree':\n\t\t\t\tentry.path = value;\n\t\t\t\tbreak;\n\t\t\tcase 'bare':\n\t\t\t\tentry.bare = true;\n\t\t\t\tbreak;\n\t\t\tcase 'HEAD':\n\t\t\t\tentry.sha = value;\n\t\t\t\tbreak;\n\t\t\tcase 'branch':\n\t\t\t\t// A HEAD pointing outside `refs/heads/` names no branch\n\t\t\t\tif (value.startsWith('refs/heads/')) {\n\t\t\t\t\tentry.branch = value.substring(11);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'detached':\n\t\t\t\tentry.detached = true;\n\t\t\t\tbreak;\n\t\t\t// `value` is the whole reason, which is only present when the locker/Git provides one (Git < 2.31\n\t\t\t// prints a bare `locked` regardless). Without `-z`, a reason with unusual characters (e.g. newlines)\n\t\t\t// comes through C-quoted, with UTF-8 bytes as octal escapes unless `core.quotePath` is off (as core runs it)\n\t\t\tcase 'locked':\n\t\t\t\tentry.locked = unquoteCString(value.trim()) || true;\n\t\t\t\tbreak;\n\t\t\tcase 'prunable':\n\t\t\t\tentry.prunable = unquoteCString(value.trim()) || true;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tsw?.stop({ suffix: ` parsed ${worktrees.length} worktrees` });\n\n\treturn worktrees;\n}\n
|
|
1
|
+
{"version":3,"file":"worktreeParser.js","names":[],"sources":["../../../../git-cli/src/parsers/worktreeParser.ts"],"sourcesContent":["import type { GitBranch } from '@gitlens/git/models/branch.js';\nimport type { WorkspaceFolderResolver } from '@gitlens/git/models/worktree.js';\nimport { GitWorktree } from '@gitlens/git/models/worktree.js';\nimport { normalizePath } from '@gitlens/utils/path.js';\nimport { maybeStopWatch } from '@gitlens/utils/stopwatch.js';\nimport { iterateByDelimiter, unquoteCString } from '@gitlens/utils/string.js';\nimport { fileUri } from '@gitlens/utils/uri.js';\n\ninterface WorktreeEntry {\n\tpath: string;\n\tsha?: string;\n\tbranch?: string;\n\tbare: boolean;\n\tdetached: boolean;\n\tlocked?: boolean | string;\n\tprunable?: boolean | string;\n}\n\nexport function parseGitWorktrees(\n\tdata: string | undefined,\n\trepoPath: string,\n\tbranches: GitBranch[],\n\tgetWorkspaceFolder?: WorkspaceFolderResolver,\n): GitWorktree[] {\n\tusing sw = maybeStopWatch(`Git.parseWorktrees(${repoPath})`, { log: { onlyExit: true, level: 'debug' } });\n\n\tconst worktrees: GitWorktree[] = [];\n\tif (!data) {\n\t\tsw?.stop({ suffix: ` no data` });\n\t\treturn worktrees;\n\t}\n\n\tif (repoPath != null) {\n\t\trepoPath = normalizePath(repoPath);\n\t}\n\n\tlet entry: Partial<WorktreeEntry> | undefined = undefined;\n\tlet line: string;\n\tlet index: number;\n\tlet key: string;\n\tlet value: string;\n\tlet main = true; // the first worktree is the main worktree\n\n\tfor (line of iterateByDelimiter(data, '\\n')) {\n\t\tindex = line.indexOf(' ');\n\t\tif (index === -1) {\n\t\t\tkey = line;\n\t\t\tvalue = '';\n\t\t} else {\n\t\t\tkey = line.substring(0, index);\n\t\t\tvalue = line.substring(index + 1);\n\t\t}\n\n\t\tif (!key && entry != null) {\n\t\t\t// oxlint-disable-next-line no-loop-func\n\t\t\tconst branch = entry.branch ? branches?.find(b => b.name === entry!.branch) : undefined;\n\t\t\tconst uri = fileUri(entry.path!);\n\n\t\t\tworktrees.push(\n\t\t\t\tnew GitWorktree(\n\t\t\t\t\tmain,\n\t\t\t\t\tentry.bare ? 'bare' : entry.detached ? 'detached' : 'branch',\n\t\t\t\t\trepoPath,\n\t\t\t\t\turi,\n\t\t\t\t\tentry.locked ?? false,\n\t\t\t\t\tentry.prunable ?? false,\n\t\t\t\t\tentry.sha,\n\t\t\t\t\tbranch,\n\t\t\t\t\tgetWorkspaceFolder?.(uri),\n\t\t\t\t\tentry.branch,\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tentry = undefined;\n\t\t\tmain = false;\n\t\t\tcontinue;\n\t\t}\n\n\t\tentry ??= {};\n\n\t\tswitch (key) {\n\t\t\tcase 'worktree':\n\t\t\t\tentry.path = value;\n\t\t\t\tbreak;\n\t\t\tcase 'bare':\n\t\t\t\tentry.bare = true;\n\t\t\t\tbreak;\n\t\t\tcase 'HEAD':\n\t\t\t\tentry.sha = value;\n\t\t\t\tbreak;\n\t\t\tcase 'branch':\n\t\t\t\t// A HEAD pointing outside `refs/heads/` names no branch\n\t\t\t\tif (value.startsWith('refs/heads/')) {\n\t\t\t\t\tentry.branch = value.substring(11);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'detached':\n\t\t\t\tentry.detached = true;\n\t\t\t\tbreak;\n\t\t\t// `value` is the whole reason, which is only present when the locker/Git provides one (Git < 2.31\n\t\t\t// prints a bare `locked` regardless). Without `-z`, a reason with unusual characters (e.g. newlines)\n\t\t\t// comes through C-quoted, with UTF-8 bytes as octal escapes unless `core.quotePath` is off (as core runs it)\n\t\t\tcase 'locked':\n\t\t\t\tentry.locked = unquoteCString(value.trim()) || true;\n\t\t\t\tbreak;\n\t\t\tcase 'prunable':\n\t\t\t\tentry.prunable = unquoteCString(value.trim()) || true;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tsw?.stop({ suffix: ` parsed ${worktrees.length} worktrees` });\n\n\treturn worktrees;\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,kBACf,MACA,UACA,UACA,oBACgB;;;EAChB,MAAM,KAAA,YAAA,EAAK,eAAe,sBAAsB,SAAS,IAAI,EAAE,KAAK;GAAE,UAAU;GAAM,OAAO;EAAQ,EAA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K;GAEnD;EACD;EAEA,IAAI,KAAK,EAAE,QAAQ,WAAW,UAAU,OAAO,YAAY,CAAC;EAE5D,OAAO;;;;;;AACR"}
|
|
@@ -31,6 +31,7 @@ export declare class DiffGitSubProvider implements GitDiffSubProvider {
|
|
|
31
31
|
renames?: boolean;
|
|
32
32
|
similarityThreshold?: number;
|
|
33
33
|
uris?: (string | Uri)[];
|
|
34
|
+
paths?: string[];
|
|
34
35
|
errors?: GitErrorHandling;
|
|
35
36
|
}, _cancellation?: AbortSignal): Promise<GitDiff | undefined>;
|
|
36
37
|
getParsedDiff(repoPath: string, to: string, from?: string, options?: {
|
|
@@ -39,6 +40,7 @@ export declare class DiffGitSubProvider implements GitDiffSubProvider {
|
|
|
39
40
|
renames?: boolean;
|
|
40
41
|
similarityThreshold?: number;
|
|
41
42
|
uris?: (string | Uri)[];
|
|
43
|
+
paths?: string[];
|
|
42
44
|
errors?: GitErrorHandling;
|
|
43
45
|
}, cancellation?: AbortSignal): Promise<ParsedGitDiff | undefined>;
|
|
44
46
|
getDiffFiles(repoPath: string, contents: string, _cancellation?: AbortSignal): Promise<GitDiffFiles | undefined>;
|
|
@@ -57,6 +57,8 @@ var DiffGitSubProvider = class {
|
|
|
57
57
|
}
|
|
58
58
|
async getDiff(repoPath, to, from, options, _cancellation) {
|
|
59
59
|
const scope = getScopedLogger();
|
|
60
|
+
const literalPaths = options?.paths;
|
|
61
|
+
if (literalPaths != null && !literalPaths.length) return void 0;
|
|
60
62
|
const args = [`-U${options?.context ?? 3}`, "--no-ext-diff"];
|
|
61
63
|
if (options?.renames === true) {
|
|
62
64
|
const similarityThreshold = options.similarityThreshold ?? this.context.config?.commits.similarityThreshold;
|
|
@@ -75,19 +77,20 @@ var DiffGitSubProvider = class {
|
|
|
75
77
|
}
|
|
76
78
|
const hasFrom = from != null;
|
|
77
79
|
from = prepareToFromDiffArgs(to, from, args, options?.notation);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
paths = new Set(options.uris.map((p) => this.provider.getRelativePath(p, repoPath)));
|
|
80
|
+
if (literalPaths == null && options?.uris) {
|
|
81
|
+
const paths = new Set(options.uris.map((p) => this.provider.getRelativePath(p, repoPath)));
|
|
81
82
|
args.push("--", ...paths);
|
|
82
83
|
}
|
|
83
|
-
let
|
|
84
|
+
let contents;
|
|
84
85
|
try {
|
|
85
|
-
|
|
86
|
+
const runOptions = {
|
|
86
87
|
cwd: repoPath,
|
|
87
88
|
configs: await this.git.getDiffReadConfigs(),
|
|
88
89
|
errors: "throw",
|
|
89
90
|
env: options?.index?.env
|
|
90
|
-
}
|
|
91
|
+
};
|
|
92
|
+
if (literalPaths != null) contents = (await Promise.all(Array.from(batchLiteralPathspecs(literalPaths, ["diff", ...args]), (batch) => this.git.run(runOptions, "diff", ...args, "--", ...batch)))).map((r) => r.stdout).join("");
|
|
93
|
+
else contents = (await this.git.run(runOptions, "diff", ...args, args.includes("--") ? void 0 : "--")).stdout;
|
|
91
94
|
} catch (ex) {
|
|
92
95
|
if (isHead(from) && await isUnbornHeadFailure(this.provider, repoPath, ex)) {
|
|
93
96
|
const emptyTree = await this.provider.revision.getEmptyTreeSha(repoPath);
|
|
@@ -110,7 +113,7 @@ var DiffGitSubProvider = class {
|
|
|
110
113
|
return;
|
|
111
114
|
}
|
|
112
115
|
return {
|
|
113
|
-
contents
|
|
116
|
+
contents,
|
|
114
117
|
from,
|
|
115
118
|
to,
|
|
116
119
|
notation: options?.notation
|