Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: git_common.py

Issue 212213004: Make mark-merge-base cap the marked merge base at the real merge-base. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: fix comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_common_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_common.py
diff --git a/git_common.py b/git_common.py
index 284c18cea4510761cbd226394fcfa1f71612b530..b938a25aed7430708cf41910871914c45b020255 100644
--- a/git_common.py
+++ b/git_common.py
@@ -245,6 +245,15 @@ def branches(*args):
yield line.split()[-1]
+def run_with_retcode(*cmd, **kwargs):
+ """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,24 @@ 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)
+
+ def is_ancestor(a, b):
+ return run_with_retcode('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 OLD pre-set merge-base for %s: %s', branch, base)
+ 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
« no previous file with comments | « no previous file | tests/git_common_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698