|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|