Chromium Code Reviews| Index: git_common.py |
| diff --git a/git_common.py b/git_common.py |
| index 71db99a8489fea82219c43204384c80adc426927..0563d1db6b5bf2a987812c96a9aeb7beee6c1e2b 100644 |
| --- a/git_common.py |
| +++ b/git_common.py |
| @@ -27,6 +27,9 @@ import threading |
| import subprocess2 |
| +MERGE_BASE_TAG_FMT = "gitscripts.merge_base_for_%s" |
|
agable
2014/02/28 20:14:16
Ugly that some of these are using a gitscripts con
|
| + |
| + |
| class DEFAULT(object): |
| def __init__(self, constructor): |
| self.constructor = constructor |
| @@ -224,6 +227,11 @@ def branches(*args): |
| yield line.split()[-1] |
| +def clean_refs(): |
|
agable
2014/02/28 20:14:16
This is really only cleaning tags, not refs...
|
| + run('tag', '-d', |
| + *[t.strip() for t in run('tag', '-l', 'gitscripts.*').split()]) |
| + |
| + |
| def config_list(option, default=DEFAULT(list)): |
| try: |
| return run('config', '--get-all', option).split() |
| @@ -249,6 +257,10 @@ def parse_commitrefs(*commitrefs): |
| raise BadCommitRefException(commitrefs) |
| +def root(): |
| + return run('config', 'depot_tools.upstream') or 'origin/master' |
| + |
| + |
| def run(*cmd, **kwargs): |
| """Runs a git command. Returns stdout as a string. |
| @@ -276,6 +288,20 @@ def stream(*cmd, **kwargs): |
| return proc.stdout |
| +def get_or_create_merge_base_tag(branch, parent): |
| + tag = MERGE_BASE_TAG_FMT % hash_one(branch) |
| + tagval = None |
| + try: |
| + tagval = hash_one(tag) |
| + logging.debug('Found tagged merge-base for %s: %s', branch, tagval) |
| + except subprocess2.CalledProcessError: |
| + pass |
| + if not tagval: |
| + run('tag', '-m', tag, tag, run('merge-base', parent, branch)) |
| + tagval = hash_one(tag) |
| + return tagval+'^{}' # this lets rev-parse know this is actually a tag |
| + |
| + |
| def hash_one(reflike): |
| return run('rev-parse', reflike) |
| @@ -298,6 +324,16 @@ def intern_f(f, kind='blob'): |
| return ret |
| +def manual_merge_base_tag(branch, base): |
| + tag = MERGE_BASE_TAG_FMT % hash_one(branch) |
| + run('tag', '-f', '-m', tag, tag, hash_one(base)) |
| + |
| + |
| +def nuke_merge_base_tag(branch): |
|
agable
2014/02/28 20:14:16
s/nuke/remove/
|
| + tag = MERGE_BASE_TAG_FMT % hash_one(branch) |
| + run('tag', '-d', tag) |
| + |
| + |
| def tags(*args): |
| for line in run('tag', *args).splitlines(): |
| if line.startswith(NO_BRANCH): |