mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-24 09:45:39 -05:00
Reworks branch parsing to include tracking info
Reworks current branch retrieval for better performance
This commit is contained in:
24
src/git/parsers/branchParser.ts
Normal file
24
src/git/parsers/branchParser.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
import { GitBranch } from './../git';
|
||||
const branchWithTrackingRegex = /^(\*?)\s+(.+?)\s+([0-9,a-f]+)\s+(?:\[(.*?\/.*?)(?:\:|\]))?/gm;
|
||||
|
||||
export class GitBranchParser {
|
||||
|
||||
static parse(data: string, repoPath: string): GitBranch[] | undefined {
|
||||
if (!data) return undefined;
|
||||
|
||||
const branches: GitBranch[] = [];
|
||||
|
||||
let match: RegExpExecArray | null = null;
|
||||
do {
|
||||
match = branchWithTrackingRegex.exec(data);
|
||||
if (match == null) break;
|
||||
|
||||
branches.push(new GitBranch(repoPath, match[2], match[1] === '*', match[4]));
|
||||
} while (match != null);
|
||||
|
||||
if (!branches.length) return undefined;
|
||||
|
||||
return branches;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user