Chromium Code Reviews| Index: git_map.py |
| diff --git a/git_map.py b/git_map.py |
| index 22e02e74b6f411e223eeb54f5608e9af24fed3ec..abbc3b104f1ae03f3dfa571f8fce72daf9dda4d9 100755 |
| --- a/git_map.py |
| +++ b/git_map.py |
| @@ -4,8 +4,8 @@ |
| # found in the LICENSE file. |
| """ |
| -Provides an augmented `git log --graph` view. In particular, it also annotates |
| -commits with branches + tags that point to them. Items are colorized as follows: |
| +Enhances `git log --graph` view with information on commit branches + tags that |
| +point to them. Items are colorized as follows: |
| * Cyan - Currently checked out branch |
| * Green - Local branch |
| * Red - Remote branches |
| @@ -19,7 +19,7 @@ import sys |
| import subprocess2 |
| from git_common import current_branch, branches, tags, get_config_list, GIT_EXE |
| -from git_common import get_or_create_merge_base, root |
| +from git_common import get_or_create_merge_base, root, ROOT, IS_WIN |
| from third_party import colorama |
| @@ -38,6 +38,10 @@ RESET = colorama.Fore.RESET + colorama.Back.RESET + colorama.Style.RESET_ALL |
| BRIGHT_RED = '\x1b[1;31m' |
| def main(argv): |
| + if '-h' in argv or '--help' in argv: |
| + sys.stdout.write(__doc__) |
| + return 0 |
| + |
| map_extra = get_config_list('depot_tools.map_extra') |
| fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s' |
| log_proc = subprocess2.Popen( |
| @@ -47,6 +51,18 @@ def main(argv): |
| stdout=subprocess2.PIPE, |
| shell=False) |
| + # prepare pager |
| + less = 'less' |
| + if IS_WIN: |
| + with open(ROOT + '\\git.bat') as r: |
| + for line in r: |
| + start = line.find('%~dp0') |
| + if start != -1: |
| + GIT_DIR = line[start+5:line.find('\cmd')] |
| + less = ROOT + '\\' + GIT_DIR + '\\usr\\bin\\less' |
| + break |
| + less_proc = subprocess2.Popen([less, '-R'], stdin=subprocess2.PIPE) |
|
iannucci
2016/07/19 01:07:55
please make this a separate CL.
That said, this a
|
| + |
| current = current_branch() |
| all_branches = set(branches()) |
| merge_base_map = {b: get_or_create_merge_base(b) for b in all_branches} |
| @@ -100,10 +116,13 @@ def main(argv): |
| line = "%s%s%s" % (line[:start-1], branches_str, line[end+5:]) |
| if head_marker: |
| line = line.replace('*', head_marker, 1) |
| - sys.stdout.write(line) |
| + less_proc.stdin.write(line) |
| except (IOError, KeyboardInterrupt): |
| pass |
| finally: |
| + # wait for less to exit |
| + less_proc.stdin.close() |
| + less_proc.wait() |
| sys.stderr.close() |
| sys.stdout.close() |
| return 0 |