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

Unified Diff: git_common.py

Issue 1559943003: Added git hyper-blame, a tool that skips unwanted commits in git blame. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Respond to review. Created 4 years, 11 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-hyper-blame ('k') | git_dates.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_common.py
diff --git a/git_common.py b/git_common.py
index 506365257ecd63556258f4656350cd3240142f2d..d571f820b7de02bd4bd3814716912d89dffa7f3d 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:
+ command.append('-p')
+ if revision is not None:
+ command.append(revision)
+ 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():
+ """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.
+ """
+ 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]
« no previous file with comments | « git-hyper-blame ('k') | git_dates.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698