Skip to content
Snippets Groups Projects
Commit 6e364a57 authored by John Koleszar's avatar John Koleszar
Browse files

lint-hunks: better support for working tree

When run with no arguments, report warnings in the diff between the
working tree and HEAD. With arguments, report warnings in the diff
between the named commit and its parents.

Change-Id: Ie10dcdecb303edf8af51bad645cc11206a1fc26b
parent e9fd1eac
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ LONG_OPTIONS = ["help"] ...@@ -22,7 +22,7 @@ LONG_OPTIONS = ["help"]
TOPLEVEL_CMD = ["git", "rev-parse", "--show-toplevel"] TOPLEVEL_CMD = ["git", "rev-parse", "--show-toplevel"]
DIFF_CMD = ["git", "diff"] DIFF_CMD = ["git", "diff"]
DIFF_INDEX_CMD = ["git", "diff-index", "-u", "--cached", "HEAD", "--"] DIFF_INDEX_CMD = ["git", "diff-index", "-u", "HEAD", "--"]
SHOW_CMD = ["git", "show"] SHOW_CMD = ["git", "show"]
CPPLINT_FILTERS = ["-readability/casting", "-runtime/int"] CPPLINT_FILTERS = ["-readability/casting", "-runtime/int"]
...@@ -106,11 +106,20 @@ def main(argv=None): ...@@ -106,11 +106,20 @@ def main(argv=None):
for filename, affected_lines in file_affected_line_map.iteritems(): for filename, affected_lines in file_affected_line_map.iteritems():
if filename.split(".")[-1] not in ("c", "h", "cc"): if filename.split(".")[-1] not in ("c", "h", "cc"):
continue continue
show_cmd = SHOW_CMD + [":" + filename]
show = Subprocess(show_cmd, stdout=subprocess.PIPE) if args:
lint = Subprocess(cpplint_cmd, expected_returncode=(0, 1), # File contents come from git
stdin=show.stdout, stderr=subprocess.PIPE) show_cmd = SHOW_CMD + [args[0] + ":" + filename]
lint_out = lint.communicate()[1] show = Subprocess(show_cmd, stdout=subprocess.PIPE)
lint = Subprocess(cpplint_cmd, expected_returncode=(0, 1),
stdin=show.stdout, stderr=subprocess.PIPE)
lint_out = lint.communicate()[1]
else:
# File contents come from the working tree
lint = Subprocess(cpplint_cmd, expected_returncode=(0, 1),
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
stdin = open(os.path.join(tl, filename)).read()
lint_out = lint.communicate(stdin)[1]
for line in lint_out.split("\n"): for line in lint_out.split("\n"):
fields = line.split(":") fields = line.split(":")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment