annotate examples/hg-interdiff @ 106:9cbc5d0db542

Finish off advanced MQ chapter (maybe).
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 23 Oct 2006 15:43:04 -0700
parents
children ba2334e2ba9a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4 # Copyright 2006 Bryan O'Sullivan <bos@serpentine.com>
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 import os, sys
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8 def walk(base):
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9 # yield all non-directories below the base path.
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10 for root, dirs, files in os.walk(base):
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 for f in files:
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12 path = os.path.join(root, f)
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13 yield path[len(base)+1:], path
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 # 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
16 files = dict(walk(sys.argv[1]))
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17 files.update(walk(sys.argv[2]))
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
18 files = files.keys()
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
19 files.sort()
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21 def name(base, f):
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
22 # 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
23 path = os.path.join(base, f)
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
24 if os.path.exists(path):
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25 return path
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 return '/dev/null'
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 ret = 0
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30 for f in files:
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 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
32 name(sys.argv[2], f))):
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33 ret = 1
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34
9cbc5d0db542 Finish off advanced MQ chapter (maybe).
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35 sys.exit(ret)