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