Mercurial > hgbook
comparison contrib/hg-interdiff @ 721:2180358c32c4
Move some files to contrib
author | Dongsheng Song <dongsheng.song@gmail.com> |
---|---|
date | Thu, 12 Mar 2009 15:40:40 +0800 |
parents | examples/hg-interdiff@f992b16d18a1 |
children |
comparison
equal
deleted
inserted
replaced
720:1ef7708b3b7f | 721:2180358c32c4 |
---|---|
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. | |
9 | |
10 import os, sys | |
11 | |
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 | |
21 | |
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() | |
27 | |
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' | |
37 | |
38 ret = 0 | |
39 | |
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 | |
44 | |
45 sys.exit(ret) |