Skip to content

Commit e3b76ad

Browse files
committed
Fixes file loading for merge commits
Refactors fileset model to maintain the filtered set of files (if any) - Allows for more flexibility in the future for displaying search results
1 parent 034b1a3 commit e3b76ad

File tree

18 files changed

+240
-210
lines changed

18 files changed

+240
-210
lines changed

src/commands/diffWithRevisionFrom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
5656
{
5757
empty: `No stashes with '${gitUri.getFormattedFileName()}' found`,
5858
// Stashes should always come with files, so this should be fine (but protect it just in case)
59-
filter: c => c.fileset?.files.some(f => f.path === path || f.originalPath === path) ?? true,
59+
filter: c => c.anyFiles?.some(f => f.path === path || f.originalPath === path) ?? true,
6060
},
6161
);
6262
if (pick == null) return;

src/commands/git/show.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class ShowGitCommand extends QuickCommand<State> {
175175
assertsStateStepCommit(state);
176176

177177
if (state.counter < 3) {
178-
if (state.reference.fileset?.files == null || state.reference.fileset?.filtered) {
178+
if (!state.reference.hasFullDetails({ allowFilteredFiles: true })) {
179179
await state.reference.ensureFullDetails();
180180
}
181181

src/commands/openFileAtRevisionFrom.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand {
5353
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
5454
'Choose a stash to compare with',
5555
// Stashes should always come with files, so this should be fine (but protect it just in case)
56-
{ filter: c => c.fileset?.files.some(f => f.path === path || f.originalPath === path) ?? true },
56+
{
57+
filter: c => c.anyFiles?.some(f => f.path === path || f.originalPath === path) ?? true,
58+
},
5759
);
5860
if (pick == null) return;
5961

src/commands/quickCommand.steps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ export function* showCommitOrStashFilesStep<
23532353
hint: `Click to see ${isStash(state.reference) ? 'stash' : 'commit'} actions`,
23542354
}),
23552355
createQuickPickSeparator('Files'),
2356-
...(state.reference.fileset?.files.map(
2356+
...(state.reference.anyFiles?.map(
23572357
fs => new CommitFileQuickPickItem(state.reference, fs, options?.picked === fs.path),
23582358
) ?? []),
23592359
] as (CommitFilesQuickPickItem | CommitFileQuickPickItem)[],

src/commands/showQuickCommitFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
128128

129129
const path = args.commit?.file?.path ?? gitUri.fsPath;
130130
if (isCommit(args.commit)) {
131-
if (args.commit.fileset?.files == null || args.commit.fileset?.filtered) {
131+
if (!args.commit.hasFullDetails({ allowFilteredFiles: true })) {
132132
await args.commit.ensureFullDetails();
133133
}
134134
}

src/env/node/git/sub-providers/commits.ts

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
CommitsLogParser,
3232
CommitsWithFilesLogParser,
3333
ParsedCommit,
34+
ParsedStash,
3435
} from '../../../../git/parsers/logParser';
3536
import {
3637
getCommitsLogParser,
@@ -185,11 +186,7 @@ export class CommitsGitSubProvider implements GitCommitsSubProvider {
185186
f.status as GitFileStatus,
186187
f.originalPath,
187188
undefined,
188-
{
189-
additions: f.additions,
190-
deletions: f.deletions,
191-
changes: 0,
192-
},
189+
{ additions: f.additions, deletions: f.deletions, changes: 0 },
193190
),
194191
);
195192

@@ -1255,35 +1252,36 @@ function createCommit(
12551252
);
12561253
}
12571254

1258-
function createCommitFileset(
1255+
export function createCommitFileset(
12591256
container: Container,
1260-
c: ParsedCommit,
1257+
c: ParsedCommit | ParsedStash,
12611258
repoPath: string,
12621259
pathspec: string | undefined,
12631260
): GitCommitFileset {
1264-
return {
1265-
files:
1266-
c.files?.map(
1267-
f =>
1268-
new GitFileChange(
1269-
container,
1270-
repoPath,
1271-
f.path,
1272-
f.status as GitFileStatus,
1273-
f.originalPath,
1274-
undefined,
1275-
{
1276-
additions: f.additions ?? 0,
1277-
deletions: f.deletions ?? 0,
1278-
changes: 0,
1279-
},
1280-
undefined,
1281-
f.range ? { startLine: f.range.startLine, endLine: f.range.endLine } : undefined,
1282-
),
1283-
) ?? [],
1284-
filtered: Boolean(pathspec),
1285-
pathspec: pathspec,
1286-
};
1261+
// If the files are missing or it's a merge commit without files or pathspec, then consider the files unloaded
1262+
if (c.files == null || (!c.files.length && pathspec == null && c.parents.includes(' '))) {
1263+
return {
1264+
files: undefined,
1265+
filtered: pathspec ? { files: undefined, pathspec: pathspec } : undefined,
1266+
};
1267+
}
1268+
1269+
const files = c.files.map(
1270+
f =>
1271+
new GitFileChange(
1272+
container,
1273+
repoPath,
1274+
f.path,
1275+
f.status as GitFileStatus,
1276+
f.originalPath,
1277+
undefined,
1278+
{ additions: f.additions ?? 0, deletions: f.deletions ?? 0, changes: 0 },
1279+
undefined,
1280+
f.range ? { startLine: f.range.startLine, endLine: f.range.endLine } : undefined,
1281+
),
1282+
);
1283+
1284+
return pathspec ? { files: undefined, filtered: { files: files, pathspec: pathspec } } : { files: files };
12871285
}
12881286

12891287
function getGitStartEnd(range: Range): [number, number] {
@@ -1326,15 +1324,19 @@ async function parseCommits(
13261324
if (stash != null) {
13271325
if (commits.has(stash.sha)) {
13281326
countStashChildCommits++;
1329-
} else {
1327+
} else if (allowFilteredFiles) {
13301328
commits.set(
13311329
stash.sha,
1332-
stash.with(
1333-
allowFilteredFiles
1334-
? { fileset: createCommitFileset(container, c, repoPath, pathspec) }
1335-
: {},
1336-
),
1330+
stash.with({
1331+
fileset: {
1332+
...createCommitFileset(container, c, repoPath, pathspec),
1333+
// Add the full stash files back into the fileset
1334+
files: stash.fileset?.files,
1335+
},
1336+
}),
13371337
);
1338+
} else {
1339+
commits.set(stash.sha, stash);
13381340
}
13391341
continue;
13401342
}
@@ -1366,15 +1368,19 @@ async function parseCommits(
13661368
if (stash != null) {
13671369
if (commits.has(stash.sha)) {
13681370
countStashChildCommits++;
1369-
} else {
1371+
} else if (allowFilteredFiles) {
13701372
commits.set(
13711373
stash.sha,
1372-
stash.with(
1373-
allowFilteredFiles
1374-
? { fileset: createCommitFileset(container, c, repoPath, pathspec) }
1375-
: {},
1376-
),
1374+
stash.with({
1375+
fileset: {
1376+
...createCommitFileset(container, c, repoPath, pathspec),
1377+
// Add the full stash files back into the fileset
1378+
files: stash.fileset?.files,
1379+
},
1380+
}),
13771381
);
1382+
} else {
1383+
commits.set(stash.sha, stash);
13781384
}
13791385
continue;
13801386
}

src/env/node/git/sub-providers/stash.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getSettledValue } from '../../../../system/promise';
2424
import type { Git } from '../git';
2525
import { maxGitCliLength } from '../git';
2626
import { RunError } from '../shell.errors';
27+
import { createCommitFileset } from './commits';
2728

2829
const stashSummaryRegex =
2930
// eslint-disable-next-line no-control-regex
@@ -382,11 +383,11 @@ export function convertStashesToStdin(stashOrStashes: GitStash | Map<string, Git
382383
}
383384

384385
function createStash(container: Container, s: ParsedStash, repoPath: string): GitStashCommit {
386+
let message = s.summary.trim();
387+
385388
let onRef;
386389
let summary;
387-
let message;
388-
389-
const match = stashSummaryRegex.exec(s.summary);
390+
const match = stashSummaryRegex.exec(message);
390391
if (match?.groups != null) {
391392
onRef = match.groups.onref;
392393
summary = match.groups.summary.trim();
@@ -398,35 +399,20 @@ function createStash(container: Container, s: ParsedStash, repoPath: string): Gi
398399
} else {
399400
message = summary;
400401
}
401-
} else {
402-
message = s.summary.trim();
403402
}
404403

404+
const index = message.indexOf('\n');
405+
405406
return new GitCommit(
406407
container,
407408
repoPath,
408409
s.sha,
409410
new GitCommitIdentity('You', undefined, new Date((s.authorDate as unknown as number) * 1000)),
410411
new GitCommitIdentity('You', undefined, new Date((s.committedDate as unknown as number) * 1000)),
411-
message.split('\n', 1)[0] ?? '',
412-
s.parents.split(' '),
412+
index !== -1 ? message.substring(0, index) : message,
413+
s.parents.split(' ') ?? [],
413414
message,
414-
{
415-
files:
416-
s.files?.map(
417-
f =>
418-
new GitFileChange(
419-
container,
420-
repoPath,
421-
f.path,
422-
f.status as GitFileStatus,
423-
f.originalPath,
424-
undefined,
425-
{ additions: f.additions ?? 0, deletions: f.deletions ?? 0, changes: 0 },
426-
),
427-
) ?? [],
428-
filtered: false,
429-
},
415+
createCommitFileset(container, s, repoPath, undefined),
430416
s.stats,
431417
undefined,
432418
undefined,

src/git/actions/commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ export async function openOnlyChangedFiles(container: Container, files: GitFile[
769769
export async function openOnlyChangedFiles(container: Container, commitOrFiles: GitCommit | GitFile[]): Promise<void> {
770770
let files;
771771
if (isCommit(commitOrFiles)) {
772-
if (commitOrFiles.fileset?.files == null || commitOrFiles.fileset?.filtered) {
772+
if (commitOrFiles.hasFullDetails()) {
773773
await commitOrFiles.ensureFullDetails();
774774
}
775775

0 commit comments

Comments
 (0)