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

Unified Diff: git_common.py

Issue 184113002: Add git-map and git-short-map to depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@new_branch
Patch Set: Make it work on windows 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 | « git-nav-upstream ('k') | git_map.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 1215d9cd41d44385f98583c884188b006b8561f1..c1e4f0bac0ba4df6ef6d3d4226117cc92e43b939 100644
--- a/git_common.py
+++ b/git_common.py
@@ -199,6 +199,25 @@ class ProgressPrinter(object):
del self._thread
+def branches(*args):
+ NO_BRANCH = ('* (no branch)', '* (detached from ')
+ for line in run('branch', *args).splitlines():
+ if line.startswith(NO_BRANCH):
+ continue
+ yield line.split()[-1]
+
+
+def config_list(option):
+ try:
+ return run('config', '--get-all', option).split()
+ except subprocess2.CalledProcessError:
+ return []
+
+
+def current_branch():
+ return run('rev-parse', '--abbrev-ref', 'HEAD')
+
+
def parse_commitrefs(*commitrefs):
"""Returns binary encoded commit hashes for one or more commitrefs.
@@ -208,7 +227,7 @@ def parse_commitrefs(*commitrefs):
* 'cool_branch~2'
"""
try:
- return map(binascii.unhexlify, hashes(*commitrefs))
+ return map(binascii.unhexlify, hash_multi(*commitrefs))
except subprocess2.CalledProcessError:
raise BadCommitRefException(commitrefs)
@@ -231,7 +250,11 @@ def run(*cmd, **kwargs):
return ret
-def hashes(*reflike):
+def hash_one(reflike):
+ return run('rev-parse', reflike)
+
+
+def hash_multi(*reflike):
return run('rev-parse', *reflike).splitlines()
@@ -249,6 +272,10 @@ def intern_f(f, kind='blob'):
return ret
+def tags(*args):
+ return run('tag', *args).splitlines()
+
+
def tree(treeref, recurse=False):
"""Returns a dict representation of a git tree object.
@@ -286,6 +313,14 @@ def tree(treeref, recurse=False):
return ret
+def upstream(branch):
+ try:
+ return run('rev-parse', '--abbrev-ref', '--symbolic-full-name',
+ branch+'@{upstream}')
+ except subprocess2.CalledProcessError:
+ return None
+
+
def mktree(treedict):
"""Makes a git tree object and returns its hash.
« no previous file with comments | « git-nav-upstream ('k') | git_map.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698