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

Side by Side Diff: git_short_map.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: rebase and add better way to run python git extensions 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
agable 2014/02/28 19:54:58 I'd call this 'git-map-branches', not 'git-short-m
iannucci 2014/03/06 00:18:39 Done
2 import collections
3 import sys
4
5 from third_party import colorama
6 from third_party.colorama import Fore, Style
7
8 from git_common import current_branch, branches, upstream, hash_one, hash_multi
9
10
11 def print_branch(cur, cur_hash, branch, branch_hashes, par_map, branch_map,
12 depth=0):
13 branch_hash = branch_hashes[branch]
14 if branch.startswith('origin'):
15 color = Fore.RED
16 elif branch_hash == cur_hash:
17 color = Fore.CYAN
18 else:
19 color = Fore.GREEN
20
21 if branch_hash == cur_hash:
22 color += Style.BRIGHT
23 else:
24 color += Style.NORMAL
25
26 print color + " "*depth + branch + (" *" if branch == cur else "")
27 for child in par_map.pop(branch, ()):
28 print_branch(cur, cur_hash, child, branch_hashes, par_map, branch_map,
29 depth=depth+1)
30
31
32 def main(argv):
33 colorama.init()
34 assert len(argv) == 1, "No arguments expected"
35 branch_map = {}
36 par_map = collections.defaultdict(list)
37 for branch in branches():
38 par = upstream(branch)
39 branch_map[branch] = par
40 par_map[par].append(branch)
41
42 current = current_branch()
43 hashes = hash_multi(current, *branch_map.keys())
44 current_hash = hashes[0]
45 par_hashes = {k: hashes[i+1] for i, k in enumerate(branch_map.iterkeys())}
46 while par_map:
47 for parent in par_map:
48 if parent not in branch_map:
49 if parent not in par_hashes:
50 par_hashes[parent] = hash_one(parent)
51 print_branch(current, current_hash, parent, par_hashes, par_map,
52 branch_map)
53 break
54
55
56 if __name__ == '__main__':
57 sys.exit(main(sys.argv))
58
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698