浏览代码

Changes search prefixes

Fixes issue with author searching
main
Eric Amodio 7 年前
父节点
当前提交
2a9b274920
共有 2 个文件被更改,包括 39 次插入31 次删除
  1. +25
    -25
      src/commands/showCommitSearch.ts
  2. +14
    -6
      src/gitService.ts

+ 25
- 25
src/commands/showCommitSearch.ts 查看文件

@ -1,17 +1,24 @@
'use strict';
import { commands, InputBoxOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands } from './common';
import { Git, GitService, GitUri } from '../gitService';
import { Git, GitRepoSearchBy, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, CommitsQuickPick } from '../quickPicks';
const searchByRegex = /^([@:#])/;
const searchByMap = new Map<string, GitRepoSearchBy>([
['@', GitRepoSearchBy.Author],
[':', GitRepoSearchBy.Files],
['#', GitRepoSearchBy.Sha]
]);
export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
constructor(private git: GitService) {
super(Commands.ShowCommitSearch);
}
async execute(editor: TextEditor, uri?: Uri, search?: string, searchBy?: undefined | 'author' | 'files' | 'message' | 'sha', goBackCommand?: CommandQuickPickItem) {
async execute(editor: TextEditor, uri?: Uri, search?: string, searchBy?: GitRepoSearchBy, goBackCommand?: CommandQuickPickItem) {
if (!(uri instanceof Uri)) {
if (!editor || !editor.document) return undefined;
uri = editor.document.uri;
@ -23,27 +30,20 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
search = await window.showInputBox({
value: search,
prompt: `Please enter a search string`,
placeHolder: `search by message, author (use a:<name>), files (use f:<pattern>), or sha (use s:<hash>)`
placeHolder: `search by message, author (use @<name>), files (use :<pattern>), or commit id (use #<sha>)`
} as InputBoxOptions);
if (search === undefined) return goBackCommand && goBackCommand.execute();
if (Git.isSha(search)) {
searchBy = 'sha';
}
else if (search.startsWith('a:')) {
searchBy = 'author';
search = search.substring((search[2] === ' ') ? 3 : 2);
}
else if (search.startsWith('f:')) {
searchBy = 'files';
search = search.substring((search[2] === ' ') ? 3 : 2);
const match = searchByRegex.exec(search);
if (match && match[1]) {
searchBy = searchByMap.get(match[1]);
search = search.substring((search[1] === ' ') ? 2 : 1);
}
else if (search.startsWith('s:')) {
searchBy = 'sha';
search = search.substring((search[2] === ' ') ? 3 : 2);
else if (Git.isSha(search)) {
searchBy = GitRepoSearchBy.Sha;
}
else {
searchBy = 'message';
searchBy = GitRepoSearchBy.Message;
}
}
@ -53,21 +53,21 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
let originalSearch: string;
let placeHolder: string;
switch (searchBy) {
case 'author':
originalSearch = `a:${search}`;
case GitRepoSearchBy.Author:
originalSearch = `@${search}`;
placeHolder = `commits with author matching '${search}'`;
break;
case 'files':
originalSearch = `f:${search}`;
case GitRepoSearchBy.Files:
originalSearch = `:${search}`;
placeHolder = `commits with files matching '${search}'`;
break;
case 'message':
case GitRepoSearchBy.Message:
originalSearch = search;
placeHolder = `commits with message matching '${search}'`;
break;
case 'sha':
originalSearch = `s:${search}`;
placeHolder = `commits with sha matching '${search}'`;
case GitRepoSearchBy.Sha:
originalSearch = `#${search}`;
placeHolder = `commits with id matching '${search}'`;
break;
}

+ 14
- 6
src/gitService.ts 查看文件

@ -48,6 +48,14 @@ enum RemoveCacheReason {
DocumentSaved
}
export type GitRepoSearchBy = 'author' | 'files' | 'message' | 'sha';
export const GitRepoSearchBy = {
Author: 'author' as GitRepoSearchBy,
Files: 'files' as GitRepoSearchBy,
Message: 'message' as GitRepoSearchBy,
Sha: 'sha' as GitRepoSearchBy
};
export class GitService extends Disposable {
private _onDidChangeGitCacheEmitter = new EventEmitter<void>();
@ -562,7 +570,7 @@ export class GitService extends Disposable {
}
}
async getLogForRepoSearch(repoPath: string, search: string, searchBy: 'author' | 'files' | 'message' | 'sha', maxCount?: number): Promise<IGitLog | undefined> {
async getLogForRepoSearch(repoPath: string, search: string, searchBy: GitRepoSearchBy, maxCount?: number): Promise<IGitLog | undefined> {
Logger.log(`getLogForRepoSearch('${repoPath}', ${search}, ${searchBy}, ${maxCount})`);
if (maxCount == null) {
@ -571,16 +579,16 @@ export class GitService extends Disposable {
let searchArgs: string[];
switch (searchBy) {
case 'author':
searchArgs = [`'--author='${search}`];
case GitRepoSearchBy.Author:
searchArgs = [`--author=${search}`];
break;
case 'files':
case GitRepoSearchBy.Files:
searchArgs = [`--`, `${search}`];
break;
case 'message':
case GitRepoSearchBy.Message:
searchArgs = [`--grep=${search}`];
break;
case 'sha':
case GitRepoSearchBy.Sha:
searchArgs = [search];
maxCount = 1;
break;

正在加载...
取消
保存