def hg_id(repo, args=None, rev=None): args = args or [] if rev: args.extend(['-r', str(rev)]) cmd = ('hg', 'id', '--repository', repo) + tuple(args) if cmd not in _HG_ID_CACHE: result = tools.get_command_output(cmd, quiet=True) if not result: logging.critical('Call failed: "%s". Check path and revision.' % ' '.join(cmd)) _HG_ID_CACHE[cmd] = result return _HG_ID_CACHE[cmd]
def get_common_ancestor(repo, rev1, rev2='default'): """ Return the global changeset id of the greatest common ancestor of revisions *rev1* and *rev2* in *repo*. If *rev2* is omitted return the revision at which *rev1* was branched off the default branch. Note that if *rev1* has been merged into the default branch, this method returns *rev1*. """ long_rev = tools.get_command_output( ['hg', '-R', repo, 'debugancestor', str(rev1), str(rev2)]) if not long_rev: logging.critical('%s or %s is not part of the repo at %s.' % (rev1, rev2, repo)) number, hexcode = long_rev.split(':') return get_global_rev(repo, rev=hexcode)