# HG changeset patch # User Jeff Hammel # Date 1377271541 25200 # Node ID 84a865a880a8ddbf9df471dd750e35488aa1ab45 # Parent 95ba5770d2f05696cb47a75c23c3965dbf32f4ef a new way to view diffs based on sorted lines diff -r 95ba5770d2f0 -r 84a865a880a8 python/sortdiff.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/sortdiff.py Fri Aug 23 08:25:41 2013 -0700 @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import optparse +import os +import sys + +def main(args=sys.argv[1:]): + + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, description=__doc__) + options, args = parser.parse_args(args) + + lines = sys.stdin.readlines() + diff = {'+': set(), + '-': set()} + for line in lines: + for key, value in diff.items(): + if line.startswith(key): + value.add(line[1:].strip()) + + added = diff['+'].difference(diff['-']) + minus = diff['-'].difference(diff['+']) + + print '+++' + for line in sorted(added): + print line + print '---' + for line in sorted(minus): + print line + +if __name__ == '__main__': + main()