mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Add a pattern to the git BranchQuery (#99681)
* Add a pattern to the git BranchQuery * Add count, which makes getting refs even faster * Update order of args in getRefs to match for-each-ref doc
This commit is contained in:
parent
12b634ec05
commit
92164dd93d
2
extensions/git/src/api/git.d.ts
vendored
2
extensions/git/src/api/git.d.ts
vendored
|
@ -134,6 +134,8 @@ export interface CommitOptions {
|
|||
|
||||
export interface BranchQuery {
|
||||
readonly remote?: boolean;
|
||||
readonly pattern?: string;
|
||||
readonly count?: number;
|
||||
readonly contains?: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -1791,13 +1791,23 @@ export class Repository {
|
|||
.map(([ref]) => ({ name: ref, type: RefType.Head } as Branch));
|
||||
}
|
||||
|
||||
async getRefs(opts?: { sort?: 'alphabetically' | 'committerdate', contains?: string }): Promise<Ref[]> {
|
||||
const args = ['for-each-ref', '--format', '%(refname) %(objectname)'];
|
||||
async getRefs(opts?: { sort?: 'alphabetically' | 'committerdate', contains?: string, pattern?: string, count?: number }): Promise<Ref[]> {
|
||||
const args = ['for-each-ref'];
|
||||
|
||||
if (opts?.count) {
|
||||
args.push(`--count=${opts.count}`);
|
||||
}
|
||||
|
||||
if (opts && opts.sort && opts.sort !== 'alphabetically') {
|
||||
args.push('--sort', `-${opts.sort}`);
|
||||
}
|
||||
|
||||
args.push('--format', '%(refname) %(objectname)');
|
||||
|
||||
if (opts?.pattern) {
|
||||
args.push(opts.pattern);
|
||||
}
|
||||
|
||||
if (opts?.contains) {
|
||||
args.push('--contains', opts.contains);
|
||||
}
|
||||
|
@ -1920,7 +1930,7 @@ export class Repository {
|
|||
}
|
||||
|
||||
async getBranches(query: BranchQuery): Promise<Ref[]> {
|
||||
const refs = await this.getRefs({ contains: query.contains });
|
||||
const refs = await this.getRefs({ contains: query.contains, pattern: query.pattern ? `refs/${query.pattern}` : undefined, count: query.count });
|
||||
return refs.filter(value => (value.type !== RefType.Tag) && (query.remote || !value.remote));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue