Mercurial > hgbook
annotate examples/hg-interdiff @ 640:67b96bca5769
finished revision of daily.tex
author | Javier Rojas <jerojasro@devnull.li> |
---|---|
date | Thu, 29 Jan 2009 22:59:04 -0500 |
parents | f992b16d18a1 |
children |
rev | line source |
---|---|
106
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 # |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 # Adapter for using interdiff with mercurial's extdiff extension. |
127
ba2334e2ba9a
Add explicit license to hg-interdiff script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
106
diff
changeset
|
4 # |
106
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 # Copyright 2006 Bryan O'Sullivan <bos@serpentine.com> |
127
ba2334e2ba9a
Add explicit license to hg-interdiff script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
106
diff
changeset
|
6 # |
ba2334e2ba9a
Add explicit license to hg-interdiff script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
106
diff
changeset
|
7 # This software may be used and distributed according to the terms of |
ba2334e2ba9a
Add explicit license to hg-interdiff script.
Bryan O'Sullivan <bos@serpentine.com>
parents:
106
diff
changeset
|
8 # the GNU General Public License, incorporated herein by reference. |
106
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 import os, sys |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 def walk(base): |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 # yield all non-directories below the base path. |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 for root, dirs, files in os.walk(base): |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 for f in files: |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 path = os.path.join(root, f) |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 yield path[len(base)+1:], path |
286
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
18 else: |
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
19 if os.path.isfile(base): |
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
20 yield '', base |
106
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
21 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
22 # create list of unique file names under both directories. |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 files = dict(walk(sys.argv[1])) |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 files.update(walk(sys.argv[2])) |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 files = files.keys() |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
26 files.sort() |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 def name(base, f): |
286
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
29 if f: |
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
30 path = os.path.join(base, f) |
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
31 else: |
f992b16d18a1
hg-interdiff: handle single-file diffs
Nicholas Riley <njriley@uiuc.edu>
parents:
127
diff
changeset
|
32 path = base |
106
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 # interdiff requires two files; use /dev/null if one is missing. |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 if os.path.exists(path): |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
35 return path |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
36 return '/dev/null' |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 ret = 0 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 for f in files: |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
41 if os.system('interdiff "%s" "%s"' % (name(sys.argv[1], f), |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 name(sys.argv[2], f))): |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 ret = 1 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
44 |
9cbc5d0db542
Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 sys.exit(ret) |