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

Unified Diff: git_hyper_blame.py

Issue 1697423004: git hyper-blame: Added automatically ignoring revs from a file. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Avoid too-long line. Created 4 years, 10 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 | « no previous file | man/html/git-hyper-blame.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_hyper_blame.py
diff --git a/git_hyper_blame.py b/git_hyper_blame.py
index 5a7daa0cf56b2db00fb5c98b391f7572fa62ed0c..b9965a7a69e7c606097e93632d03f6d64c38023e 100755
--- a/git_hyper_blame.py
+++ b/git_hyper_blame.py
@@ -22,6 +22,9 @@ import git_dates
logging.getLogger().setLevel(logging.INFO)
+DEFAULT_IGNORE_FILE_NAME = '.git-blame-ignore-revs'
+
+
class Commit(object):
"""Info about a commit."""
def __init__(self, commithash):
@@ -323,12 +326,25 @@ def hyper_blame(ignored, filename, revision='HEAD', out=sys.stdout,
return 0
+
+def parse_ignore_file(ignore_file):
+ for line in ignore_file:
+ line = line.split('#', 1)[0].strip()
+ if line:
+ yield line
+
+
def main(args, stdout=sys.stdout, stderr=sys.stderr):
parser = argparse.ArgumentParser(
prog='git hyper-blame',
description='git blame with support for ignoring certain commits.')
parser.add_argument('-i', metavar='REVISION', action='append', dest='ignored',
default=[], help='a revision to ignore')
+ parser.add_argument('--ignore-file', metavar='FILE',
+ type=argparse.FileType('r'), dest='ignore_file',
+ help='a file containing a list of revisions to ignore')
+ parser.add_argument('--no-default-ignores', dest='no_default_ignores',
+ help='Do not ignore commits from .git-blame-ignore-revs.')
parser.add_argument('revision', nargs='?', default='HEAD', metavar='REVISION',
help='revision to look at')
parser.add_argument('filename', metavar='FILE', help='filename to blame')
@@ -349,14 +365,21 @@ def main(args, stdout=sys.stdout, stderr=sys.stderr):
filename = os.path.normpath(filename)
filename = os.path.normcase(filename)
+ ignored_list = list(args.ignored)
+ if not args.no_default_ignores and os.path.exists(DEFAULT_IGNORE_FILE_NAME):
+ with open(DEFAULT_IGNORE_FILE_NAME) as ignore_file:
+ ignored_list.extend(parse_ignore_file(ignore_file))
+
+ if args.ignore_file:
+ ignored_list.extend(parse_ignore_file(args.ignore_file))
+
ignored = set()
- for c in args.ignored:
+ for c in ignored_list:
try:
ignored.add(git_common.hash_one(c))
except subprocess2.CalledProcessError as e:
- # Custom error message (the message from git-rev-parse is inappropriate).
- stderr.write('fatal: unknown revision \'%s\'.\n' % c)
- return e.returncode
+ # Custom warning string (the message from git-rev-parse is inappropriate).
+ stderr.write('warning: unknown revision \'%s\'.\n' % c)
return hyper_blame(ignored, filename, args.revision, out=stdout, err=stderr)
« no previous file with comments | « no previous file | man/html/git-hyper-blame.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698