Skip to content

Commit 8a64a06

Browse files
committed
Fixes #716 - reworks diff w/ next
Disables commands for the deleted or missing sha Adds getNextDiffUris & getNextUri Renames getDiffWithPreviousForFile to getPreviousDiffUris Renames getPreviousRevisionUri to getPreviousUri
1 parent 223f811 commit 8a64a06

File tree

8 files changed

+387
-317
lines changed

8 files changed

+387
-317
lines changed

src/commands/diffLineWithPrevious.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
4646
// If the line is uncommitted, change the previous commit
4747
if (blame.commit.isUncommitted) {
4848
try {
49-
const previous = await Container.git.getPreviousRevisionUri(
49+
const previous = await Container.git.getPreviousUri(
5050
gitUri.repoPath!,
5151
gitUri,
5252
gitUri.sha,
@@ -77,35 +77,35 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
7777
Logger.error(
7878
ex,
7979
'DiffLineWithPreviousCommand',
80-
`getPreviousRevisionUri(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
80+
`getPreviousUri(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
8181
);
8282
return Messages.showGenericErrorMessage('Unable to open compare');
8383
}
8484
}
8585
}
8686

8787
try {
88-
const diffWith = await Container.git.getDiffWithPreviousForFile(
88+
const diffUris = await Container.git.getPreviousDiffUris(
8989
gitUri.repoPath!,
9090
gitUri,
9191
gitUri.sha,
9292
0,
9393
args.line
9494
);
9595

96-
if (diffWith === undefined || diffWith.previous === undefined) {
96+
if (diffUris === undefined || diffUris.previous === undefined) {
9797
return Messages.showCommitHasNoPreviousCommitWarningMessage();
9898
}
9999

100100
const diffArgs: DiffWithCommandArgs = {
101-
repoPath: diffWith.current.repoPath,
101+
repoPath: diffUris.current.repoPath,
102102
lhs: {
103-
sha: diffWith.previous.sha || '',
104-
uri: diffWith.previous.documentUri()
103+
sha: diffUris.previous.sha || '',
104+
uri: diffUris.previous.documentUri()
105105
},
106106
rhs: {
107-
sha: diffWith.current.sha || '',
108-
uri: diffWith.current.documentUri()
107+
sha: diffUris.current.sha || '',
108+
uri: diffUris.current.documentUri()
109109
},
110110
line: args.line,
111111
showOptions: args.showOptions
@@ -116,7 +116,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
116116
Logger.error(
117117
ex,
118118
'DiffLineWithPreviousCommand',
119-
`getDiffWithPreviousForFile(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
119+
`getPreviousDiffUris(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
120120
);
121121
return Messages.showGenericErrorMessage('Unable to open compare');
122122
}

src/commands/diffWithNext.ts

Lines changed: 28 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
33
import { Container } from '../container';
4-
import { GitLogCommit, GitService, GitStatusFile, GitUri } from '../git/gitService';
4+
import { GitLogCommit, GitUri } from '../git/gitService';
55
import { Logger } from '../logger';
66
import { Messages } from '../messages';
7-
import { Iterables } from '../system';
87
import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common';
98
import { DiffWithCommandArgs } from './diffWith';
109
import { UriComparer } from '../comparers';
@@ -52,101 +51,34 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
5251
args.line = editor == null ? 0 : editor.selection.active.line;
5352
}
5453

55-
const gitUri = await GitUri.fromUri(uri);
56-
let status: GitStatusFile | undefined;
57-
58-
if (args.commit === undefined || !(args.commit instanceof GitLogCommit) || args.range !== undefined) {
59-
try {
60-
const sha = args.commit === undefined ? gitUri.sha! : args.commit.sha;
61-
62-
if (GitService.isStagedUncommitted(sha)) {
63-
const diffArgs: DiffWithCommandArgs = {
64-
repoPath: gitUri.repoPath!,
65-
lhs: {
66-
sha: sha,
67-
uri: gitUri
68-
},
69-
rhs: {
70-
sha: '',
71-
uri: gitUri
72-
},
73-
line: args.line,
74-
showOptions: args.showOptions
75-
};
76-
return commands.executeCommand(Commands.DiffWith, diffArgs);
77-
}
78-
79-
let log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, {
80-
maxCount: sha !== undefined ? undefined : 2,
81-
range: args.range!,
82-
renames: true
83-
});
84-
if (log === undefined) {
85-
const fileName = await Container.git.findNextFileName(gitUri.repoPath!, gitUri.fsPath);
86-
if (fileName !== undefined) {
87-
log = await Container.git.getLogForFile(gitUri.repoPath, fileName, {
88-
maxCount: sha !== undefined ? undefined : 2,
89-
range: args.range!,
90-
renames: true
91-
});
92-
}
93-
94-
if (log === undefined) {
95-
return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
96-
}
97-
}
98-
99-
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());
100-
101-
// If the sha is missing or the file is uncommitted, treat it as a DiffWithWorking
102-
if (gitUri.sha === undefined) {
103-
status = await Container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
104-
if (status !== undefined) return commands.executeCommand(Commands.DiffWithWorking, uri);
105-
}
106-
}
107-
catch (ex) {
108-
Logger.error(ex, 'DiffWithNextCommand', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`);
109-
return Messages.showGenericErrorMessage('Unable to open compare');
110-
}
54+
const gitUri = args.commit !== undefined ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri);
55+
try {
56+
const diffUris = await Container.git.getNextDiffUris(gitUri.repoPath!, gitUri, gitUri.sha);
57+
58+
if (diffUris === undefined || diffUris.next === undefined) return undefined;
59+
60+
const diffArgs: DiffWithCommandArgs = {
61+
repoPath: diffUris.current.repoPath,
62+
lhs: {
63+
sha: diffUris.current.sha || '',
64+
uri: diffUris.current.documentUri()
65+
},
66+
rhs: {
67+
sha: diffUris.next.sha || '',
68+
uri: diffUris.next.documentUri()
69+
},
70+
line: args.line,
71+
showOptions: args.showOptions
72+
};
73+
return commands.executeCommand(Commands.DiffWith, diffArgs);
11174
}
112-
113-
if (args.commit.nextSha === undefined) {
114-
// Check if the file is staged
115-
status = status || (await Container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath));
116-
if (status !== undefined && status.indexStatus === 'M') {
117-
const diffArgs: DiffWithCommandArgs = {
118-
repoPath: args.commit.repoPath,
119-
lhs: {
120-
sha: args.commit.sha,
121-
uri: args.commit.uri
122-
},
123-
rhs: {
124-
sha: GitService.stagedUncommittedSha,
125-
uri: args.commit.uri
126-
},
127-
line: args.line,
128-
showOptions: args.showOptions
129-
};
130-
131-
return commands.executeCommand(Commands.DiffWith, diffArgs);
132-
}
133-
134-
return commands.executeCommand(Commands.DiffWithWorking, uri);
75+
catch (ex) {
76+
Logger.error(
77+
ex,
78+
'DiffWithNextCommand',
79+
`getNextDiffUris(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
80+
);
81+
return Messages.showGenericErrorMessage('Unable to open compare');
13582
}
136-
137-
const diffArgs: DiffWithCommandArgs = {
138-
repoPath: args.commit.repoPath,
139-
lhs: {
140-
sha: args.commit.sha,
141-
uri: args.commit.uri
142-
},
143-
rhs: {
144-
sha: args.commit.nextSha,
145-
uri: args.commit.nextUri
146-
},
147-
line: args.line,
148-
showOptions: args.showOptions
149-
};
150-
return commands.executeCommand(Commands.DiffWith, diffArgs);
15183
}
15284
}

src/commands/diffWithPrevious.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
5252

5353
const gitUri = args.commit !== undefined ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri);
5454
try {
55-
const diffWith = await Container.git.getDiffWithPreviousForFile(
55+
const diffUris = await Container.git.getPreviousDiffUris(
5656
gitUri.repoPath!,
5757
gitUri,
5858
gitUri.sha,
5959
// If we are in a diff editor, assume we are on the right side, and need to skip back 1 more revisions
6060
args.inDiffEditor ? 1 : 0
6161
);
6262

63-
if (diffWith === undefined || diffWith.previous === undefined) {
63+
if (diffUris === undefined || diffUris.previous === undefined) {
6464
return Messages.showCommitHasNoPreviousCommitWarningMessage();
6565
}
6666

6767
const diffArgs: DiffWithCommandArgs = {
68-
repoPath: diffWith.current.repoPath,
68+
repoPath: diffUris.current.repoPath,
6969
lhs: {
70-
sha: diffWith.previous.sha || '',
71-
uri: diffWith.previous.documentUri()
70+
sha: diffUris.previous.sha || '',
71+
uri: diffUris.previous.documentUri()
7272
},
7373
rhs: {
74-
sha: diffWith.current.sha || '',
75-
uri: diffWith.current.documentUri()
74+
sha: diffUris.current.sha || '',
75+
uri: diffUris.current.documentUri()
7676
},
7777
line: args.line,
7878
showOptions: args.showOptions
@@ -83,7 +83,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
8383
Logger.error(
8484
ex,
8585
'DiffWithPreviousCommand',
86-
`getDiffWithPreviousForFile(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
86+
`getPreviousDiffUris(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
8787
);
8888
return Messages.showGenericErrorMessage('Unable to open compare');
8989
}

0 commit comments

Comments
 (0)