Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: tools/git/git-diff-ide.py

Issue 9562011: Add git diff python tool that outputs file:line in front of diff output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """
7 Invokes git diff [args...] and inserts file:line in front of each line of diff
8 output where possible.
9
10 Synopsis:
11 %prog [git diff args...]
12
13 Examples:
14 %prog
15 %prog HEAD
16 """
17
18 import subprocess
19 import sys
20
21
22 def GitShell(args, ignore_return=False):
23 """A shell invocation suitable for communicating with git. Returns
24 output as list of lines, raises exception on error.
25 """
26 job = subprocess.Popen(args,
27 shell=True,
28 stdout=subprocess.PIPE,
29 stderr=subprocess.STDOUT)
30 (out, err) = job.communicate()
31 if job.returncode != 0 and not ignore_return:
32 print out
33 raise Exception("Error %d running command %s" % (
34 job.returncode, args))
35 return out.split('\n')
36
37
38 def PrintGitDiff(extra_args):
39 """Outputs git diff extra_args with file:line inserted into relevant lines."""
40 current_file = '';
41 line_num = 0;
42 lines = GitShell('git diff %s' % ' '.join(extra_args))
43 for line in lines:
44 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.
45 line.startswith('index ') or \
46 line.startswith('--- '):
47 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.
48 continue
49 if line.startswith('+++ '):
50 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.
51 print line
52 continue
53 if line.startswith('@@ '):
54 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.
55 print line
56 continue
57 print current_file + ':' + repr(line_num) + ':' + line
58 if line.startswith(' ') or line.startswith('+'):
59 line_num += 1
60
61
62 def main():
63 PrintGitDiff(sys.argv[1:])
64
65
66 if __name__ == '__main__':
67 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698