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

Unified Diff: git_map_branches.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_map.py ('k') | git_nav_downstream.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_map_branches.py
diff --git a/git_map_branches.py b/git_map_branches.py
new file mode 100755
index 0000000000000000000000000000000000000000..5fde84b282408f8ec7afcb938f2a40800d1050e7
--- /dev/null
+++ b/git_map_branches.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+"""
+Provides a short mapping of all the branches in your local repo, organized by
+their upstream ('tracking branch') layout. Example:
+
+origin/master
+ cool_feature
+ dependent_feature
+ other_dependent_feature
+ other_feature
+
+Branches are colorized as follows:
+ * Red - a remote branch (usually the root of all local branches)
+ * Cyan - a local branch which is the same as HEAD
+ * Note that multiple branches may be Cyan, if they are all on the same
+ commit, and you have that commit checked out.
+ * Green - a local branch
+ * Magenta - a placeholder for the '{NO UPSTREAM}' "branch". If you have
+ local branches which do not track any upstream, then you will see this.
+"""
+import collections
+import sys
+
+from third_party import colorama
+from third_party.colorama import Fore, Style
+
+from git_common import current_branch, branches, upstream, hash_one, hash_multi
+
+NO_UPSTREAM = '{NO UPSTREAM}'
+
+def print_branch(cur, cur_hash, branch, branch_hashes, par_map, branch_map,
+ depth=0):
+ branch_hash = branch_hashes[branch]
+ if branch.startswith('origin'):
+ color = Fore.RED
+ elif branch == NO_UPSTREAM:
+ color = Fore.MAGENTA
+ elif branch_hash == cur_hash:
+ color = Fore.CYAN
+ else:
+ color = Fore.GREEN
+
+ if branch_hash == cur_hash:
+ color += Style.BRIGHT
+ else:
+ color += Style.NORMAL
+
+ print color + " "*depth + branch + (" *" if branch == cur else "")
+ for child in par_map.pop(branch, ()):
+ print_branch(cur, cur_hash, child, branch_hashes, par_map, branch_map,
+ depth=depth+1)
+
+
+def main(argv):
+ colorama.init()
+ assert len(argv) == 1, "No arguments expected"
+ branch_map = {}
+ par_map = collections.defaultdict(list)
+ for branch in branches():
+ par = upstream(branch) or NO_UPSTREAM
+ branch_map[branch] = par
+ par_map[par].append(branch)
+
+ current = current_branch()
+ hashes = hash_multi(current, *branch_map.keys())
+ current_hash = hashes[0]
+ par_hashes = {k: hashes[i+1] for i, k in enumerate(branch_map.iterkeys())}
+ par_hashes[NO_UPSTREAM] = 0
+ while par_map:
+ for parent in par_map:
+ if parent not in branch_map:
+ if parent not in par_hashes:
+ par_hashes[parent] = hash_one(parent)
+ print_branch(current, current_hash, parent, par_hashes, par_map,
+ branch_map)
+ break
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+
« no previous file with comments | « git_map.py ('k') | git_nav_downstream.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698