Reworks branch parsing to include tracking info

Reworks current branch retrieval for better performance
This commit is contained in:
Eric Amodio
2017-09-04 01:32:43 -04:00
parent 2bba14260f
commit 5a2bd02402
5 changed files with 77 additions and 23 deletions

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