diff --git a/git_hyper_blame.py b/git_hyper_blame.py index 5a7daa0cf..b9965a7a6 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) diff --git a/man/html/git-hyper-blame.html b/man/html/git-hyper-blame.html index 62f7cc82a..c123d81b0 100644 --- a/man/html/git-hyper-blame.html +++ b/man/html/git-hyper-blame.html @@ -755,7 +755,8 @@ git-hyper-blame(1) Manual Page
git hyper-blame [-i <rev> [-i <rev> …]] [<rev>] [--] <file>+
git hyper-blame [-i <rev> [-i <rev> …]] [--ignore-file=<file>] + [--no-default-ignores] [<rev>] [--] <file>
Follows the normal blame
syntax: annotates <file>
with the revision that
last modified each line. Optional <rev>
specifies the revision of <file>
to
start from.
Automatically looks for a file called .git-blame-ignore-revs
in the repository
+root directory. This file has the same syntax as the --ignore-file
argument,
+and any commits mentioned in this file are added to the ignore list.
+ A file containing a list of revisions to ignore. Can have comments beginning
+ with #
.
+
+ Do not ignore commits from the .git-blame-ignore-revs
file.
+
-There is currently no way to pass the ignore list as a file. -
-
-It should be possible for a git repository to configure an automatic list of
- commits to ignore (like .gitignore
), so that project owners can maintain a
- list of "big change" commits that are ignored by hyper-blame by default.
-