Skip to content

Commit 318f769

Browse files
committed
Fixes view commands that open the working file
Fixes quickpick commands that open the working file Neither of these cases worked with renamed files
1 parent e6d6ee7 commit 318f769

File tree

8 files changed

+216
-165
lines changed

8 files changed

+216
-165
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88

99
## Fixed
1010

11-
- Fixes the _Show Stashed Changes_ (`gitlens.showQuickStashList`) command with multiple repositories
11+
- Fixes issues with the _Open File_, _Open Files_, _Open All Changes with Working Tree_, and _Apply Changes_ commands in the views not working with renamed files
12+
- Fixes issues with the _Open File_, _Open Files_, and _Apply Changes_ command in the quick pick menus not working with renamed files
13+
- Fixes issues with the _Show Stashed Changes_ (`gitlens.showQuickStashList`) command and multiple repositories
1214

1315
## [9.7.3] - 2019-05-11
1416

src/commands/openWorkingFile.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand {
3030
if (args.uri == null) {
3131
uri = getCommandUri(uri, editor);
3232
if (uri == null) return undefined;
33+
}
34+
else {
35+
uri = args.uri;
36+
}
3337

34-
args.uri = await GitUri.fromUri(uri);
35-
if (args.uri instanceof GitUri && args.uri.sha) {
36-
const workingUri = await Container.git.getWorkingUri(args.uri.repoPath!, args.uri);
37-
if (workingUri === undefined) {
38-
return window.showWarningMessage(
39-
'Unable to open working file. File could not be found in the working tree'
40-
);
41-
}
42-
43-
args.uri = new GitUri(workingUri, args.uri.repoPath);
38+
args.uri = await GitUri.fromUri(uri);
39+
if (args.uri instanceof GitUri && args.uri.sha) {
40+
const workingUri = await Container.git.getWorkingUri(args.uri.repoPath!, args.uri);
41+
if (workingUri === undefined) {
42+
return window.showWarningMessage(
43+
'Unable to open working file. File could not be found in the working tree'
44+
);
4445
}
46+
47+
args.uri = new GitUri(workingUri, args.uri.repoPath);
4548
}
4649

4750
if (args.line !== undefined && args.line !== 0) {

src/git/parsers/logParser.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const diffRangeRegex = /^@@ -(\d+?),(\d+?) \+(\d+?),(\d+?) @@/;
1313

1414
export const fileStatusRegex = /(\S)\S*\t([^\t\n]+)(?:\t(.+))?/;
1515
const logFileSimpleRegex = /^<r> (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm;
16+
const logFileSimpleRenamedRegex = /^<r> (\S+)\s*(.*)$/s;
17+
const logFileSimpleRenamedFilesRegex = /^(\S)\S*\t([^\t\n]+)(?:\t(.+)?)$/gm;
1618

1719
// Using %x00 codes because some shells seem to try to expand things if not
1820
const lb = '%x3c'; // `%x${'<'.charCodeAt(0).toString(16)}`;
@@ -412,56 +414,75 @@ export class GitLogParser {
412414
skip--;
413415
}
414416

415-
let match;
416417
let ref;
418+
let diffFile;
419+
let diffRenamed;
420+
let status;
417421
let file;
418-
let status: GitFileStatus | undefined;
422+
let renamed;
423+
424+
let match: RegExpExecArray | null;
419425
do {
420426
match = logFileSimpleRegex.exec(data);
421427
if (match == null) break;
422428

423429
if (skip-- > 0) continue;
424430

425-
ref = ` ${match[1]}`.substr(1);
431+
[, ref, diffFile, diffRenamed, status, file, renamed] = match;
432+
426433
if (lineRef === ref) {
427434
skip++;
428435

429436
continue;
430437
}
431438

432-
file = ` ${match[3] || match[2] || match[6] || match[5]}`.substr(1);
433-
status = match[4] ? (` ${match[4]}`.substr(1) as GitFileStatus) : undefined;
439+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
440+
file = ` ${diffRenamed || diffFile || renamed || file}`.substr(1);
441+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
442+
status = status == null || status.length === 0 ? undefined : ` ${status}`.substr(1);
434443
} while (skip >= 0);
435444

436445
// Ensure the regex state is reset
437446
logFileSimpleRegex.lastIndex = 0;
438447

439-
return [ref, file, status];
448+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
449+
return [` ${ref}`.substr(1), file, status as GitFileStatus | undefined];
440450
}
441451

442452
@debug({ args: false })
443453
static parseSimpleRenamed(
444454
data: string,
445455
originalFileName: string
446456
): [string | undefined, string | undefined, GitFileStatus | undefined] {
447-
let match;
448-
let ref;
457+
let match = logFileSimpleRenamedRegex.exec(data);
458+
if (match == null) return [undefined, undefined, undefined];
459+
460+
const [, ref, files] = match;
461+
462+
let status;
449463
let file;
450-
let status: GitFileStatus | undefined;
464+
let renamed;
465+
451466
do {
452-
match = logFileSimpleRegex.exec(data);
467+
match = logFileSimpleRenamedFilesRegex.exec(files);
453468
if (match == null) break;
454469

455-
if (originalFileName !== (match[2] || match[5])) continue;
470+
[, status, file, renamed] = match;
456471

457-
ref = ` ${match[1]}`.substr(1);
458-
file = ` ${match[3] || match[2] || match[6] || match[5]}`.substr(1);
459-
status = match[4] ? (` ${match[4]}`.substr(1) as GitFileStatus) : undefined;
472+
if (originalFileName !== file) continue;
473+
474+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
475+
file = ` ${renamed || file}`.substr(1);
476+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
477+
status = status == null || status.length === 0 ? undefined : ` ${status}`.substr(1);
478+
479+
break;
460480
} while (match != null);
461481

462482
// Ensure the regex state is reset
463-
logFileSimpleRegex.lastIndex = 0;
483+
logFileSimpleRenamedFilesRegex.lastIndex = 0;
464484

465-
return [ref, file, status];
485+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
486+
return [` ${ref}`.substr(1), file, status as GitFileStatus | undefined];
466487
}
467488
}

src/quickpicks/commitFileQuickPick.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
'use strict';
22
import * as paths from 'path';
3-
import { QuickPickItem, Uri, window } from 'vscode';
3+
import { commands, QuickPickItem, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
44
import {
55
Commands,
66
CopyMessageToClipboardCommandArgs,
77
CopyShaToClipboardCommandArgs,
88
DiffWithPreviousCommandArgs,
99
DiffWithWorkingCommandArgs,
1010
openEditor,
11+
OpenWorkingFileCommandArgs,
1112
ShowQuickCommitDetailsCommandArgs,
1213
ShowQuickCommitFileDetailsCommandArgs,
1314
ShowQuickFileHistoryCommandArgs
1415
} from '../commands';
1516
import { GlyphChars } from '../constants';
1617
import { Container } from '../container';
1718
import { GitLog, GitLogCommit, GitService, GitUri, RemoteResourceType } from '../git/gitService';
18-
import { KeyCommand, KeyNoopCommand } from '../keyboard';
19+
import { KeyCommand, KeyNoopCommand, Keys } from '../keyboard';
1920
import { Strings } from '../system';
20-
import {
21-
CommandQuickPickItem,
22-
getQuickPickIgnoreFocusOut,
23-
KeyCommandQuickPickItem,
24-
OpenFileCommandQuickPickItem
25-
} from './commonQuickPicks';
21+
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem } from './commonQuickPicks';
2622
import { OpenRemotesCommandQuickPickItem } from './remotesQuickPick';
2723

2824
export class ApplyCommitFileChangesCommandQuickPickItem extends CommandQuickPickItem {
@@ -41,28 +37,50 @@ export class ApplyCommitFileChangesCommandQuickPickItem extends CommandQuickPick
4137

4238
async execute(): Promise<{} | undefined> {
4339
const uri = this.commit.toGitUri();
44-
void (await openEditor(uri, { preserveFocus: true, preview: false }));
40+
41+
// Open the working file to ensure undo will work
42+
const args: OpenWorkingFileCommandArgs = {
43+
uri: uri,
44+
showOptions: { preserveFocus: true, preview: false }
45+
};
46+
void (await commands.executeCommand(Commands.OpenWorkingFile, undefined, args));
4547

4648
void (await Container.git.applyChangesToWorkingFile(uri));
4749

4850
return undefined;
4951
}
5052
}
5153

52-
export class OpenCommitFileCommandQuickPickItem extends OpenFileCommandQuickPickItem {
53-
constructor(commit: GitLogCommit, item?: QuickPickItem) {
54-
const uri = GitUri.resolveToUri(commit.fileName, commit.repoPath);
54+
export class OpenCommitFileCommandQuickPickItem extends CommandQuickPickItem {
55+
constructor(private readonly _commit: GitLogCommit, item?: QuickPickItem) {
5556
super(
56-
uri,
5757
item || {
5858
label: '$(file-symlink-file) Open File',
59-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${paths.basename(commit.fileName)}`
59+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} ${paths.basename(_commit.fileName)}`
6060
}
6161
);
6262
}
63+
64+
execute(options?: TextDocumentShowOptions): Thenable<TextEditor | undefined> {
65+
const uri = this._commit.toGitUri();
66+
const args: OpenWorkingFileCommandArgs = {
67+
uri: uri,
68+
showOptions: options
69+
};
70+
return commands.executeCommand(Commands.OpenWorkingFile, undefined, args);
71+
}
72+
73+
onDidPressKey(key: Keys): Thenable<{} | undefined> {
74+
return this.execute({
75+
preserveFocus: true,
76+
preview: false
77+
});
78+
}
6379
}
6480

65-
export class OpenCommitFileRevisionCommandQuickPickItem extends OpenFileCommandQuickPickItem {
81+
export class OpenCommitFileRevisionCommandQuickPickItem extends CommandQuickPickItem {
82+
private readonly _uri: Uri;
83+
6684
constructor(commit: GitLogCommit, item?: QuickPickItem) {
6785
let description: string;
6886
let uri: Uri;
@@ -78,13 +96,26 @@ export class OpenCommitFileRevisionCommandQuickPickItem extends OpenFileCommandQ
7896
GlyphChars.Space
7997
}$(git-commit) ${commit.shortSha}`;
8098
}
99+
81100
super(
82-
uri,
83101
item || {
84102
label: '$(file-symlink-file) Open Revision',
85103
description: description
86104
}
87105
);
106+
107+
this._uri = uri;
108+
}
109+
110+
execute(options?: TextDocumentShowOptions): Thenable<TextEditor | undefined> {
111+
return openEditor(this._uri, options);
112+
}
113+
114+
onDidPressKey(key: Keys): Thenable<{} | undefined> {
115+
return this.execute({
116+
preserveFocus: true,
117+
preview: false
118+
});
88119
}
89120
}
90121

0 commit comments

Comments
 (0)