comparison python/sortdiff.py @ 499:84a865a880a8

a new way to view diffs based on sorted lines
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 23 Aug 2013 08:25:41 -0700
parents
children
comparison
equal deleted inserted replaced
498:95ba5770d2f0 499:84a865a880a8
1 #!/usr/bin/env python
2
3 import optparse
4 import os
5 import sys
6
7 def main(args=sys.argv[1:]):
8
9 usage = '%prog [options]'
10 parser = optparse.OptionParser(usage=usage, description=__doc__)
11 options, args = parser.parse_args(args)
12
13 lines = sys.stdin.readlines()
14 diff = {'+': set(),
15 '-': set()}
16 for line in lines:
17 for key, value in diff.items():
18 if line.startswith(key):
19 value.add(line[1:].strip())
20
21 added = diff['+'].difference(diff['-'])
22 minus = diff['-'].difference(diff['+'])
23
24 print '+++'
25 for line in sorted(added):
26 print line
27 print '---'
28 for line in sorted(minus):
29 print line
30
31 if __name__ == '__main__':
32 main()