Skip to content

Commit b5640fd

Browse files
committed
Overhauls uri handling
Fixes #220 - Open revision results in empty file Fixes SO many bugs
1 parent 21927a7 commit b5640fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+700
-412
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
99
- Adds progress indicator to the `Show Stashed Changes` command (`gitlens.showQuickStashList`)
1010
- Adds progress indicator to the `Apply Stashed Changes` command (`gitlens.stashApply`)
1111

12+
### Changed
13+
- Overhauls the internal way GitLens deals with Uris and revisions should be far more robust and lead to many fewer edge-case issues
14+
15+
### Fixed
16+
- Fixes [#220](https://github.com/eamodio/vscode-gitlens/issues/220) - Open Revision quick pick results in empty file
17+
- Fixes so, SO, many bugs through the refactor/overhaul of GitLens' Uri handling
18+
1219
## [6.3.0] - 2017-11-30
1320
### Added
1421
- Adds support for files with staged changes

src/annotations/annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Annotations {
4949
annotationType = FileAnnotationType.Gutter;
5050
}
5151

52-
const uri = GitService.toGitContentUri(commit.previousSha, commit.previousUri.fsPath, commit.repoPath);
52+
const uri = GitUri.toRevisionUri(commit.previousSha, commit.previousUri.fsPath, commit.repoPath);
5353
const line = window.activeTextEditor!.selection.active.line;
5454

5555
commandBar += `[\`${GlyphChars.SquareWithTopShadow}\`](${OpenFileRevisionCommand.getMarkdownCommandArgs(uri, annotationType || FileAnnotationType.Gutter, line)} "Blame Previous Revision") `;

src/commands/closeUnchangedFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
3333
const status = await this.git.getStatusForRepo(repoPath);
3434
if (status === undefined) return window.showWarningMessage(`Unable to close unchanged files`);
3535

36-
args.uris = status.files.map(f => f.Uri);
36+
args.uris = status.files.map(f => f.uri);
3737
}
3838

3939
if (args.uris.length === 0) return commands.executeCommand(BuiltInCommands.CloseAllEditors);

src/commands/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export async function openEditor(uri: Uri, options?: TextDocumentShowOptions): P
297297
};
298298

299299
if (uri instanceof GitUri) {
300-
uri = Uri.file(uri.fsPath);
300+
uri = uri.fileUri(false);
301301
}
302302

303303
const document = await workspace.openTextDocument(uri);

src/commands/diffWith.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, Commands } from './common';
44
import { BuiltInCommands, GlyphChars } from '../constants';
5-
import { GitCommit, GitService } from '../gitService';
5+
import { GitCommit, GitService, GitUri } from '../gitService';
66
import { Logger } from '../logger';
77
import * as path from 'path';
88

@@ -90,6 +90,15 @@ export class DiffWithCommand extends ActiveEditorCommand {
9090
if (args.repoPath === undefined || args.lhs === undefined || args.rhs === undefined) return undefined;
9191

9292
try {
93+
// If the shas aren't resolved (e.g. a2d24f^), resolve them
94+
if (GitService.isResolveRequired(args.lhs.sha)) {
95+
args.lhs.sha = await this.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri);
96+
}
97+
98+
if (GitService.isResolveRequired(args.rhs.sha)) {
99+
args.rhs.sha = await this.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri);
100+
}
101+
93102
const [lhs, rhs] = await Promise.all([
94103
this.git.getVersionedFile(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha),
95104
this.git.getVersionedFile(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha)
@@ -104,19 +113,26 @@ export class DiffWithCommand extends ActiveEditorCommand {
104113

105114
let rhsPrefix = '';
106115
if (rhs === undefined) {
107-
rhsPrefix = 'deleted in ';
116+
rhsPrefix = GitService.isUncommitted(args.rhs.sha)
117+
? ' (deleted)'
118+
: 'deleted in ';
108119
}
109120
else if (lhs === undefined || args.lhs.sha === GitService.deletedSha) {
110121
rhsPrefix = 'added in ';
111122
}
112123

113-
if (args.lhs.title === undefined && lhs !== undefined && args.lhs.sha !== GitService.deletedSha) {
124+
let lhsPrefix = '';
125+
if (lhs === undefined && args.rhs.sha === '') {
126+
lhsPrefix = 'deleted in ';
127+
}
128+
129+
if (args.lhs.title === undefined && args.lhs.sha !== GitService.deletedSha && (lhs !== undefined || lhsPrefix !== '')) {
114130
const suffix = GitService.shortenSha(args.lhs.sha) || '';
115-
args.lhs.title = `${path.basename(args.lhs.uri.fsPath)}${suffix !== '' ? ` (${suffix})` : ''}`;
131+
args.lhs.title = `${path.basename(args.lhs.uri.fsPath)}${suffix !== '' ? ` (${lhsPrefix}${suffix})` : ''}`;
116132
}
117133
if (args.rhs.title === undefined && args.rhs.sha !== GitService.deletedSha) {
118134
const suffix = GitService.shortenSha(args.rhs.sha) || '';
119-
args.rhs.title = `${path.basename(args.rhs.uri.fsPath)}${suffix !== '' ? ` (${rhsPrefix}${suffix})` : ''}`;
135+
args.rhs.title = `${path.basename(args.rhs.uri.fsPath)}${suffix !== '' ? ` (${rhsPrefix}${suffix})` : rhsPrefix}`;
120136
}
121137

122138
const title = (args.lhs.title !== undefined && args.rhs.title !== undefined)
@@ -125,10 +141,10 @@ export class DiffWithCommand extends ActiveEditorCommand {
125141

126142
return await commands.executeCommand(BuiltInCommands.Diff,
127143
lhs === undefined
128-
? GitService.toGitContentUri(GitService.deletedSha, args.lhs.uri.fsPath, args.repoPath)
144+
? GitUri.toRevisionUri(GitService.deletedSha, args.lhs.uri.fsPath, args.repoPath)
129145
: Uri.file(lhs),
130146
rhs === undefined
131-
? GitService.toGitContentUri(GitService.deletedSha, args.rhs.uri.fsPath, args.repoPath)
147+
? GitUri.toRevisionUri(GitService.deletedSha, args.rhs.uri.fsPath, args.repoPath)
132148
: Uri.file(rhs),
133149
title,
134150
args.showOptions);

src/commands/diffWithPrevious.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { commands, Range, TextDocumentShowOptions, TextEditor, Uri, window } fro
44
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
55
import { DiffWithCommandArgs } from './diffWith';
66
import { DiffWithWorkingCommandArgs } from './diffWithWorking';
7-
import { GitCommit, GitCommitType, GitService, GitUri } from '../gitService';
7+
import { GitCommit, GitService, GitUri } from '../gitService';
88
import { Logger } from '../logger';
99
import { Messages } from '../messages';
1010

@@ -33,7 +33,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
3333
args.line = editor === undefined ? 0 : editor.selection.active.line;
3434
}
3535

36-
if (args.commit === undefined || args.commit.type !== GitCommitType.File || args.range !== undefined) {
36+
if (args.commit === undefined || !args.commit.isFile || args.range !== undefined) {
3737
const gitUri = await GitUri.fromUri(uri, this.git);
3838

3939
try {

src/commands/externalDiff.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ export class ExternalDiffCommand extends Command {
105105

106106
for (const file of status.files) {
107107
if (file.indexStatus === 'M') {
108-
args.files.push(new ExternalDiffFile(file.Uri, true));
108+
args.files.push(new ExternalDiffFile(file.uri, true));
109109
}
110110

111111
if (file.workTreeStatus === 'M') {
112-
args.files.push(new ExternalDiffFile(file.Uri, false));
112+
args.files.push(new ExternalDiffFile(file.uri, false));
113113
}
114114
}
115115
}

src/commands/openChangedFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
3232
if (status === undefined) return window.showWarningMessage(`Unable to open changed files`);
3333

3434
args.uris = Arrays.filterMap(status.files,
35-
f => f.status !== 'D' ? f.Uri : undefined);
35+
f => f.status !== 'D' ? f.uri : undefined);
3636
}
3737

3838
for (const uri of args.uris) {

src/commands/openCommitInRemote.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
import { commands, TextEditor, Uri, window } from 'vscode';
33
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithCommit } from './common';
4-
import { GitBlameCommit, GitService, GitUri } from '../gitService';
4+
import { GitService, GitUri } from '../gitService';
55
import { Logger } from '../logger';
66
import { Messages } from '../messages';
77
import { OpenInRemoteCommandArgs } from './openInRemote';
@@ -56,7 +56,12 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
5656
let commit = blame.commit;
5757
// If the line is uncommitted, find the previous commit
5858
if (commit.isUncommitted) {
59-
commit = new GitBlameCommit(commit.repoPath, commit.previousSha!, commit.previousFileName!, commit.author, commit.date, commit.message, []);
59+
commit = commit.with({
60+
sha: commit.previousSha,
61+
fileName: commit.previousFileName,
62+
previousSha: null,
63+
previousFileName: null
64+
});
6065
}
6166

6267
args.sha = commit.sha;

src/commands/showCommitSearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
139139
if (pick instanceof CommandQuickPickItem) return pick.execute();
140140

141141
return commands.executeCommand(Commands.ShowQuickCommitDetails,
142-
new GitUri(pick.commit.uri, pick.commit),
142+
pick.commit.toGitUri(),
143143
{
144144
sha: pick.commit.sha,
145145
commit: pick.commit,

0 commit comments

Comments
 (0)