Chromium Code Reviews| Index: git_common.py |
| diff --git a/git_common.py b/git_common.py |
| index 284c18cea4510761cbd226394fcfa1f71612b530..d87fc3aef903c46e2c2dcd2db3e2217e48badeb7 100644 |
| --- a/git_common.py |
| +++ b/git_common.py |
| @@ -245,6 +245,15 @@ def branches(*args): |
| yield line.split()[-1] |
| +def check(*cmd, **kwargs): |
|
agable
2014/03/26 21:00:09
Again with your overly terse naming.
iannucci
2014/03/26 21:26:38
Done.
|
| + """Run a command but only return the status code.""" |
| + try: |
| + run(*cmd, **kwargs) |
| + return 0 |
| + except subprocess2.CalledProcessError as cpe: |
| + return cpe.returncode |
| + |
| + |
| def config(option, default=None): |
| try: |
| return run('config', '--get', option) or default |
| @@ -322,16 +331,23 @@ def get_or_create_merge_base(branch, parent=None): |
| If parent is supplied, it's used instead of calling upstream(branch). |
| """ |
| base = branch_config(branch, 'base') |
| + parent = parent or upstream(branch) |
| + actual_merge_base = run('merge-base', parent, branch) |
| + |
| + is_ancestor = lambda a, b: check('merge-base', '--is-ancestor', a, b) == 0 |
| + |
| if base: |
| - try: |
| - run('merge-base', '--is-ancestor', base, branch) |
| - logging.debug('Found pre-set merge-base for %s: %s', branch, base) |
| - except subprocess2.CalledProcessError: |
| + if not is_ancestor(base, branch): |
| logging.debug('Found WRONG pre-set merge-base for %s: %s', branch, base) |
| base = None |
| + elif is_ancestor(base, actual_merge_base): |
| + logging.debug('Found ANCIENT pre-set merge-base for %s: %s', branch, base) |
|
agable
2014/03/26 21:00:09
Ancient? Could be off by just one commit made a co
iannucci
2014/03/26 21:26:38
Done.
|
| + base = None |
| + else: |
| + logging.debug('Found pre-set merge-base for %s: %s', branch, base) |
| if not base: |
| - base = run('merge-base', parent or upstream(branch), branch) |
| + base = actual_merge_base |
| manual_merge_base(branch, base) |
| return base |