|
@ -35,72 +35,70 @@ export interface SearchPattern { |
|
|
matchRegex?: boolean; |
|
|
matchRegex?: boolean; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export namespace SearchPattern { |
|
|
|
|
|
const normalizeSearchOperatorsMap = new Map<SearchOperators, SearchOperators>([ |
|
|
|
|
|
['', 'message:'], |
|
|
|
|
|
['=:', 'message:'], |
|
|
|
|
|
['message:', 'message:'], |
|
|
|
|
|
['@:', 'author:'], |
|
|
|
|
|
['author:', 'author:'], |
|
|
|
|
|
['#:', 'commit:'], |
|
|
|
|
|
['commit:', 'commit:'], |
|
|
|
|
|
['?:', 'file:'], |
|
|
|
|
|
['file:', 'file:'], |
|
|
|
|
|
['~:', 'change:'], |
|
|
|
|
|
['change:', 'change:'], |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
export function getKeyForSearchPattern(search: SearchPattern) { |
|
|
|
|
|
return `${search.pattern}|${search.matchAll ? 'A' : ''}${search.matchCase ? 'C' : ''}${ |
|
|
|
|
|
search.matchRegex ? 'R' : '' |
|
|
|
|
|
}`;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const searchOperationRegex = |
|
|
|
|
|
/(?:(?<op>=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:)\s?(?<value>".+?"|\S+\b}?))|(?<text>\S+)(?!(?:=|message|@|author|#|commit|\?|file|~|change):)/gi; |
|
|
|
|
|
|
|
|
export function getSearchPatternFromCommit(ref: string): string; |
|
|
|
|
|
export function getSearchPatternFromCommit(commit: GitRevisionReference): string; |
|
|
|
|
|
export function getSearchPatternFromCommit(refOrCommit: string | GitRevisionReference) { |
|
|
|
|
|
return `#:${typeof refOrCommit === 'string' ? GitRevision.shorten(refOrCommit) : refOrCommit.name}`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function fromCommit(ref: string): string; |
|
|
|
|
|
export function fromCommit(commit: GitRevisionReference): string; |
|
|
|
|
|
export function fromCommit(refOrCommit: string | GitRevisionReference) { |
|
|
|
|
|
return `#:${typeof refOrCommit === 'string' ? GitRevision.shorten(refOrCommit) : refOrCommit.name}`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function getSearchPatternFromCommits(refs: string[]): string; |
|
|
|
|
|
export function getSearchPatternFromCommits(commits: GitRevisionReference[]): string; |
|
|
|
|
|
export function getSearchPatternFromCommits(refsOrCommits:
(string | GitRevisionReference)[]) { |
|
|
|
|
|
return refsOrCommits.map(r => `#:${typeof r === 'string' ? GitRevision.shorten(r) : r.name}`).join(' '); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function fromCommits(refs: string[]): string; |
|
|
|
|
|
export function fromCommits(commits: GitRevisionReference[]): string; |
|
|
|
|
|
export function fromCommits(refsOrCommits: (string | GitRevisionReference)[]) { |
|
|
|
|
|
return refsOrCommits.map(r => `#:${typeof r === 'string' ? GitRevision.shorten(r) : r.name}`).join(' '); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const normalizeSearchOperatorsMap = new Map<SearchOperators, SearchOperators>([ |
|
|
|
|
|
['', 'message:'], |
|
|
|
|
|
['=:', 'message:'], |
|
|
|
|
|
['message:', 'message:'], |
|
|
|
|
|
['@:', 'author:'], |
|
|
|
|
|
['author:', 'author:'], |
|
|
|
|
|
['#:', 'commit:'], |
|
|
|
|
|
['commit:', 'commit:'], |
|
|
|
|
|
['?:', 'file:'], |
|
|
|
|
|
['file:', 'file:'], |
|
|
|
|
|
['~:', 'change:'], |
|
|
|
|
|
['change:', 'change:'], |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
export function parseSearchOperations(search: string): Map<string, string[]> { |
|
|
|
|
|
const operations = new Map<string, string[]>(); |
|
|
|
|
|
|
|
|
const searchOperationRegex = |
|
|
|
|
|
/(?:(?<op>=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:)\s?(?<value>".+?"|\S+\b}?))|(?<text>\S+)(?!(?:=|message|@|author|#|commit|\?|file|~|change):)/gi; |
|
|
|
|
|
|
|
|
let op: SearchOperators | undefined; |
|
|
|
|
|
let value: string | undefined; |
|
|
|
|
|
let text: string | undefined; |
|
|
|
|
|
|
|
|
export function parseSearchOperations(search: string): Map<string, string[]> { |
|
|
|
|
|
const operations = new Map<string, string[]>(); |
|
|
|
|
|
|
|
|
let match; |
|
|
|
|
|
do { |
|
|
|
|
|
match = searchOperationRegex.exec(search); |
|
|
|
|
|
if (match?.groups == null) break; |
|
|
|
|
|
|
|
|
let op: SearchOperators | undefined; |
|
|
|
|
|
let value: string | undefined; |
|
|
|
|
|
let text: string | undefined; |
|
|
|
|
|
|
|
|
op = normalizeSearchOperatorsMap.get(match.groups.op as SearchOperators); |
|
|
|
|
|
({ value, text } = match.groups); |
|
|
|
|
|
|
|
|
let match; |
|
|
|
|
|
do { |
|
|
|
|
|
match = searchOperationRegex.exec(search); |
|
|
|
|
|
if (match?.groups == null) break; |
|
|
|
|
|
|
|
|
if (text) { |
|
|
|
|
|
op = GitRevision.isSha(text) ? 'commit:' : 'message:'; |
|
|
|
|
|
value = text; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
op = normalizeSearchOperatorsMap.get(match.groups.op as SearchOperators); |
|
|
|
|
|
({ value, text } = match.groups); |
|
|
|
|
|
|
|
|
if (op && value) { |
|
|
|
|
|
const values = operations.get(op); |
|
|
|
|
|
if (values == null) { |
|
|
|
|
|
operations.set(op, [value]); |
|
|
|
|
|
} else { |
|
|
|
|
|
values.push(value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} while (match != null); |
|
|
|
|
|
|
|
|
if (text) { |
|
|
|
|
|
op = GitRevision.isSha(text) ? 'commit:' : 'message:'; |
|
|
|
|
|
value = text; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return operations; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (op && value) { |
|
|
|
|
|
const values = operations.get(op); |
|
|
|
|
|
if (values == null) { |
|
|
|
|
|
operations.set(op, [value]); |
|
|
|
|
|
} else { |
|
|
|
|
|
values.push(value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} while (match != null); |
|
|
|
|
|
|
|
|
export function toKey(search: SearchPattern) { |
|
|
|
|
|
return `${search.pattern}|${search.matchAll ? 'A' : ''}${search.matchCase ? 'C' : ''}${ |
|
|
|
|
|
search.matchRegex ? 'R' : '' |
|
|
|
|
|
}`;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return operations; |
|
|
} |
|
|
} |