提交 6bca8751 authored 作者: Josh Bleecher Snyder's avatar Josh Bleecher Snyder

Add yet another option for how to run the check_whitespace hook:…

Add yet another option for how to run the check_whitespace hook: incremental-with-patch. The idea is: If a file was clean, block commits that make it unclean. If it wasn't clean, don't block, but still propose a patch to clean it up. This may not work for folks using an hg gui. Thanks to Fred for the suggestion.
上级 4d2769d2
...@@ -159,7 +159,13 @@ def main(argv=None): ...@@ -159,7 +159,13 @@ def main(argv=None):
action="store_const", action="store_const",
default=False, default=False,
const=True, const=True,
help="only check indentation if the file was previously correctly indented (or is new)" help="only block on newly introduced indentation problems; ignore all others"
)
parser.add_argument("-p", "--incremental-with-patch",
action="store_const",
default=False,
const=True,
help="only block on newly introduced indentation problems; propose a patch for all others"
) )
parser.add_argument("-s", "--skip-after-failure", parser.add_argument("-s", "--skip-after-failure",
action="store_const", action="store_const",
...@@ -203,16 +209,21 @@ def main(argv=None): ...@@ -203,16 +209,21 @@ def main(argv=None):
else: else:
# parsing succeeded, it is safe to check indentation # parsing succeeded, it is safe to check indentation
if not args.no_indentation: if not args.no_indentation:
if args.incremental and filename in changed_filenames: was_clean = None # unknown
# only check it if it was clean before # only calculate was_clean if it will matter to us
old_file_contents = get_file_contents(filename, revision=parent_commit()) if args.incremental or args.incremental_with_patch:
check_indentation = get_correct_indentation_diff(old_file_contents, "") is None if filename in changed_filenames:
else: old_file_contents = get_file_contents(filename, revision=parent_commit())
check_indentation = True was_clean = get_correct_indentation_diff(old_file_contents, "") is None
else:
was_clean = True # by default -- it was newly added and thus had no prior problems
check_indentation = was_clean or not args.incremental
if check_indentation: if check_indentation:
indentation_diff = get_correct_indentation_diff(code, filename) indentation_diff = get_correct_indentation_diff(code, filename)
if indentation_diff is not None: if indentation_diff is not None:
block_commit = True if was_clean or not args.incremental_with_patch:
block_commit = True
diffs.append(indentation_diff) diffs.append(indentation_diff)
print >> sys.stderr, "%s is not correctly indented" % filename print >> sys.stderr, "%s is not correctly indented" % filename
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论