summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2012-10-18 14:34:53 -0700
committerJohn Koleszar <jkoleszar@google.com>2012-10-19 12:31:16 -0700
commit6e364a57c0bf7477b35284e7acbcf776e1d5ec3e (patch)
tree79317ebdc439781f8602a8073ff3eb349221627f /tools
parente9fd1eace1c9b35733fa988d2f661fb16548e899 (diff)
downloadlibvpx-6e364a57c0bf7477b35284e7acbcf776e1d5ec3e.tar.gz
libvpx-6e364a57c0bf7477b35284e7acbcf776e1d5ec3e.tar.bz2
libvpx-6e364a57c0bf7477b35284e7acbcf776e1d5ec3e.zip
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
Diffstat (limited to 'tools')
-rwxr-xr-xtools/lint-hunks.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/tools/lint-hunks.py b/tools/lint-hunks.py
index 312fab138..b15a69143 100755
--- a/tools/lint-hunks.py
+++ b/tools/lint-hunks.py
@@ -22,7 +22,7 @@ LONG_OPTIONS = ["help"]
TOPLEVEL_CMD = ["git", "rev-parse", "--show-toplevel"]
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"]
CPPLINT_FILTERS = ["-readability/casting", "-runtime/int"]
@@ -106,11 +106,20 @@ def main(argv=None):
for filename, affected_lines in file_affected_line_map.iteritems():
if filename.split(".")[-1] not in ("c", "h", "cc"):
continue
- show_cmd = SHOW_CMD + [":" + filename]
- 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]
+
+ if args:
+ # File contents come from git
+ show_cmd = SHOW_CMD + [args[0] + ":" + filename]
+ 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"):
fields = line.split(":")