def GitHash(wc_dir): """Finds the current commit hash of the wc_dir.""" retval, text = chromium_utils.GetStatusOutput( [GitExe(), 'rev-parse', 'HEAD'], cwd=wc_dir) if retval or 'fatal: Not a git repository' in text: raise NotGitWorkingCopy(wc_dir) return text.strip()
def GitOrSubversion(wc_dir): """Returns the VCS for the given directory. Returns: 'svn' if the directory is a valid svn repo 'git' if the directory is a valid git repo root None otherwise """ ret, out = chromium_utils.GetStatusOutput([SubversionExe(), 'info', wc_dir]) if not ret and 'is not a working copy' not in out: return 'svn' ret, out = chromium_utils.GetStatusOutput( [GitExe(), 'rev-parse', '--is-inside-work-tree'], cwd=wc_dir) if not ret and 'fatal: Not a git repository' not in out: return 'git' return None
def ScrapeSVNInfoRevision(wc_dir, regexp): """Runs 'svn info' on a working copy and applies the supplied regex and returns the matched group as an int. regexp can be either a compiled regex or a string regex. throws NotSVNWorkingCopy if wc_dir is not in a working copy. throws InvalidSVNRevision if matched group is not alphanumeric. """ if isinstance(regexp, (str, unicode)): regexp = re.compile(regexp) retval, svn_info = chromium_utils.GetStatusOutput([SubversionExe(), 'info', wc_dir]) if retval or 'is not a working copy' in svn_info: raise NotSVNWorkingCopy(wc_dir) text = regexp.sub(r'\1', svn_info) if text.isalnum(): return int(text) else: raise InvalidSVNRevision(text)