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

Unified Diff: git_common.py

Issue 240203005: Implement git-drover. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address feedback Created 6 years, 8 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 | « git_cache.py ('k') | git_drover.py » ('j') | git_drover.py » ('J')
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 6952c1ee318765ebe40622ec9a7b5d10334c888f..2266502838f11080ec6eb968edecafc0e14f538a 100644
--- a/git_common.py
+++ b/git_common.py
@@ -30,6 +30,8 @@ import threading
import subprocess2
+import git_cache
+
GIT_EXE = 'git.bat' if sys.platform.startswith('win') else 'git'
TEST_MODE = False
@@ -215,9 +217,10 @@ def once(function):
"""@Decorates |function| so that it only performs its action once, no matter
how many times the decorated |function| is called."""
def _inner_gen():
- yield function()
+ ret = function()
+ yield ret
while True:
- yield
+ yield ret
return _inner_gen().next
@@ -275,6 +278,23 @@ def run_with_retcode(*cmd, **kwargs):
return cpe.returncode
+def cached_fetch(commits):
+ m = git_cache.Mirror.from_repo('.')
+ if m:
+ m.populate(fetch_specs=commits)
+ else:
+ for commit in commits:
+ run('fetch', 'origin', commit)
+
+
+def check(*args, **kwargs):
+ try:
+ run(*args, **kwargs)
+ return True
+ except subprocess2.CalledProcessError:
+ return False
+
+
def config(option, default=None):
try:
return run('config', '--get', option) or default
@@ -375,6 +395,14 @@ def get_or_create_merge_base(branch, parent=None):
return base
+def get_remote_url(remote):
+ m = git_cache.Mirror.from_repo('.')
+ if m:
+ return m.url
+
+ return config('remote.%s.url' % remote)
+
+
def hash_multi(*reflike):
return run('rev-parse', *reflike).splitlines()
@@ -512,9 +540,12 @@ def run_with_stderr(*cmd, **kwargs):
kwargs.setdefault('stdout', subprocess2.PIPE)
kwargs.setdefault('stderr', subprocess2.PIPE)
autostrip = kwargs.pop('autostrip', True)
+ verbose = kwargs.pop('verbose', False)
indata = kwargs.pop('indata', None)
cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
+ if verbose:
+ print "running `%s`" % (cmd,)
proc = subprocess2.Popen(cmd, **kwargs)
ret, err = proc.communicate(indata)
retcode = proc.wait()
@@ -657,3 +688,7 @@ def upstream(branch):
branch+'@{upstream}')
except subprocess2.CalledProcessError:
return None
+
+
+def verify_commit(commit):
+ return check('rev-parse', '--quiet', '--verify', '%s^{commit}' % commit)
« no previous file with comments | « git_cache.py ('k') | git_drover.py » ('j') | git_drover.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698