Chromium Code Reviews| Index: git_common.py |
| diff --git a/git_common.py b/git_common.py |
| index 506365257ecd63556258f4656350cd3240142f2d..5dd42b01d35caa2e0c5b80627e234f875e0c9e0b 100644 |
| --- a/git_common.py |
| +++ b/git_common.py |
| @@ -281,6 +281,16 @@ def once(function): |
| ## Git functions |
| +def blame(filename, revision=None, porcelain=False, *args): |
| + command = ['blame'] |
| + if porcelain: # pragma: no cover |
|
iannucci
2016/01/29 19:29:25
why not covered?
Matt Giuca
2016/02/01 03:51:06
Testing porcelain was a lot of work, and covered i
|
| + command.append('-p') |
| + if revision is not None: |
| + command.append(revision) |
|
iannucci
2016/01/29 19:29:25
may want to consider -w and -M options
Matt Giuca
2016/02/01 03:51:06
I think we could consider that in a future version
|
| + command.extend(['--', filename]) |
| + return run(*command) |
| + |
| + |
| def branch_config(branch, option, default=None): |
| return config('branch.%s.%s' % (branch, option), default=default) |
| @@ -546,10 +556,39 @@ def remove_merge_base(branch): |
| del_branch_config(branch, 'base-upstream') |
| +def repo_root(): # pragma: no cover |
|
iannucci
2016/01/29 19:29:25
?
Matt Giuca
2016/02/01 03:51:06
I didn't think it would be easy to test this since
|
| + """Returns the absolute path to the repository root.""" |
| + return run('rev-parse', '--show-toplevel') |
| + |
| + |
| def root(): |
| return config('depot-tools.upstream', 'origin/master') |
| +@contextlib.contextmanager |
| +def less(): # pragma: no cover |
| + """Runs 'less' as context manager yielding its stdin as a PIPE. |
| + |
| + Automatically checks if sys.stdout is a non-TTY stream. If so, it avoids |
| + running less and just yields sys.stdout. |
| + """ |
|
iannucci
2016/01/29 19:29:25
does this work on windows?
Generally stuff in dep
Matt Giuca
2016/02/01 03:51:06
Tested on Windows; works perfectly, except for an
|
| + if not sys.stdout.isatty(): |
| + yield sys.stdout |
| + return |
| + |
| + # Run with the same options that git uses (see setup_pager in git repo). |
| + # -F: Automatically quit if the output is less than one screen. |
| + # -R: Don't escape ANSI color codes. |
| + # -X: Don't clear the screen before starting. |
| + cmd = ('less', '-FRX') |
| + try: |
| + proc = subprocess2.Popen(cmd, stdin=subprocess2.PIPE) |
| + yield proc.stdin |
| + finally: |
| + proc.stdin.close() |
| + proc.wait() |
| + |
| + |
| def run(*cmd, **kwargs): |
| """The same as run_with_stderr, except it only returns stdout.""" |
| return run_with_stderr(*cmd, **kwargs)[0] |