hgbook

annotate examples/hg-interdiff @ 599:9e8e5292acaa

Generate a nice readable index.
author Bryan O'Sullivan <bos@serpentine.com>
date Fri Mar 27 00:41:15 2009 -0700 (2009-03-27)
parents ba2334e2ba9a
children
rev   line source
bos@106 1 #!/usr/bin/env python
bos@106 2 #
bos@106 3 # Adapter for using interdiff with mercurial's extdiff extension.
bos@127 4 #
bos@106 5 # Copyright 2006 Bryan O'Sullivan <bos@serpentine.com>
bos@127 6 #
bos@127 7 # This software may be used and distributed according to the terms of
bos@127 8 # the GNU General Public License, incorporated herein by reference.
bos@106 9
bos@106 10 import os, sys
bos@106 11
bos@106 12 def walk(base):
bos@106 13 # yield all non-directories below the base path.
bos@106 14 for root, dirs, files in os.walk(base):
bos@106 15 for f in files:
bos@106 16 path = os.path.join(root, f)
bos@106 17 yield path[len(base)+1:], path
njriley@286 18 else:
njriley@286 19 if os.path.isfile(base):
njriley@286 20 yield '', base
bos@106 21
bos@106 22 # create list of unique file names under both directories.
bos@106 23 files = dict(walk(sys.argv[1]))
bos@106 24 files.update(walk(sys.argv[2]))
bos@106 25 files = files.keys()
bos@106 26 files.sort()
bos@106 27
bos@106 28 def name(base, f):
njriley@286 29 if f:
njriley@286 30 path = os.path.join(base, f)
njriley@286 31 else:
njriley@286 32 path = base
bos@106 33 # interdiff requires two files; use /dev/null if one is missing.
bos@106 34 if os.path.exists(path):
bos@106 35 return path
bos@106 36 return '/dev/null'
bos@106 37
bos@106 38 ret = 0
bos@106 39
bos@106 40 for f in files:
bos@106 41 if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f),
bos@106 42 name(sys.argv[2], f))):
bos@106 43 ret = 1
bos@106 44
bos@106 45 sys.exit(ret)