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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « git_map.py ('k') | git_nav_downstream.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 """
3 Provides a short mapping of all the branches in your local repo, organized by
4 their upstream ('tracking branch') layout. Example:
5
6 origin/master
7 cool_feature
8 dependent_feature
9 other_dependent_feature
10 other_feature
11
12 Branches are colorized as follows:
13 * Red - a remote branch (usually the root of all local branches)
14 * Cyan - a local branch which is the same as HEAD
15 * Note that multiple branches may be Cyan, if they are all on the same
16 commit, and you have that commit checked out.
17 * Green - a local branch
18 * Magenta - a placeholder for the '{NO UPSTREAM}' "branch". If you have
19 local branches which do not track any upstream, then you will see this.
20 """
21 import collections
22 import sys
23
24 from third_party import colorama
25 from third_party.colorama import Fore, Style
26
27 from git_common import current_branch, branches, upstream, hash_one, hash_multi
28
29 NO_UPSTREAM = '{NO UPSTREAM}'
30
31 def print_branch(cur, cur_hash, branch, branch_hashes, par_map, branch_map,
32 depth=0):
33 branch_hash = branch_hashes[branch]
34 if branch.startswith('origin'):
35 color = Fore.RED
36 elif branch == NO_UPSTREAM:
37 color = Fore.MAGENTA
38 elif branch_hash == cur_hash:
39 color = Fore.CYAN
40 else:
41 color = Fore.GREEN
42
43 if branch_hash == cur_hash:
44 color += Style.BRIGHT
45 else:
46 color += Style.NORMAL
47
48 print color + " "*depth + branch + (" *" if branch == cur else "")
49 for child in par_map.pop(branch, ()):
50 print_branch(cur, cur_hash, child, branch_hashes, par_map, branch_map,
51 depth=depth+1)
52
53
54 def main(argv):
55 colorama.init()
56 assert len(argv) == 1, "No arguments expected"
57 branch_map = {}
58 par_map = collections.defaultdict(list)
59 for branch in branches():
60 par = upstream(branch) or NO_UPSTREAM
61 branch_map[branch] = par
62 par_map[par].append(branch)
63
64 current = current_branch()
65 hashes = hash_multi(current, *branch_map.keys())
66 current_hash = hashes[0]
67 par_hashes = {k: hashes[i+1] for i, k in enumerate(branch_map.iterkeys())}
68 par_hashes[NO_UPSTREAM] = 0
69 while par_map:
70 for parent in par_map:
71 if parent not in branch_map:
72 if parent not in par_hashes:
73 par_hashes[parent] = hash_one(parent)
74 print_branch(current, current_hash, parent, par_hashes, par_map,
75 branch_map)
76 break
77
78
79 if __name__ == '__main__':
80 sys.exit(main(sys.argv))
81
OLDNEW
« 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