Index: tools/git/git-diff-ide.py |
diff --git a/tools/git/git-diff-ide.py b/tools/git/git-diff-ide.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..e270afe502e4156824598fde552eaf2b2ea355d7 |
--- /dev/null |
+++ b/tools/git/git-diff-ide.py |
@@ -0,0 +1,67 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+""" |
+ Invokes git diff [args...] and inserts file:line in front of each line of diff |
+ output where possible. |
+ |
+Synopsis: |
+ %prog [git diff args...] |
+ |
+Examples: |
+ %prog |
+ %prog HEAD |
+""" |
+ |
+import subprocess |
+import sys |
+ |
+ |
+def GitShell(args, ignore_return=False): |
+ """A shell invocation suitable for communicating with git. Returns |
+ output as list of lines, raises exception on error. |
+ """ |
+ job = subprocess.Popen(args, |
+ shell=True, |
+ stdout=subprocess.PIPE, |
+ stderr=subprocess.STDOUT) |
+ (out, err) = job.communicate() |
+ if job.returncode != 0 and not ignore_return: |
+ print out |
+ raise Exception("Error %d running command %s" % ( |
+ job.returncode, args)) |
+ return out.split('\n') |
+ |
+ |
+def PrintGitDiff(extra_args): |
+ """Outputs git diff extra_args with file:line inserted into relevant lines.""" |
+ current_file = ''; |
+ line_num = 0; |
+ lines = GitShell('git diff %s' % ' '.join(extra_args)) |
+ for line in lines: |
+ if line.startswith('diff ') or \ |
Nico
2012/03/01 21:57:13
if (foo or
bar):
is preferred over \
jbates
2012/03/01 22:26:00
Done.
|
+ line.startswith('index ') or \ |
+ line.startswith('--- '): |
+ print line |
Nico
2012/03/01 21:57:13
Maybe it's easier to understand what's going on if
jbates
2012/03/01 22:26:00
Done.
|
+ continue |
+ if line.startswith('+++ '): |
+ current_file = line[4:] if line[4] == '/' else line[6:] |
Nico
2012/03/01 21:57:13
# Handle:
# +++ b/third_party/libxml/src/pattern.c
jbates
2012/03/01 22:26:00
Done.
|
+ print line |
+ continue |
+ if line.startswith('@@ '): |
+ line_num = int(line.split()[2][1:].split(',')[0]) |
Nico
2012/03/01 21:57:13
# Handle:
# @@ -305,7 +305,8 @@ xmlNewPatParserCon
jbates
2012/03/01 22:26:00
Done.
|
+ print line |
+ continue |
+ print current_file + ':' + repr(line_num) + ':' + line |
+ if line.startswith(' ') or line.startswith('+'): |
+ line_num += 1 |
+ |
+ |
+def main(): |
+ PrintGitDiff(sys.argv[1:]) |
+ |
+ |
+if __name__ == '__main__': |
+ main() |