annotate examples/hg-replay @ 697:7893b3824715

Add a top-level index page.
author Bryan O'Sullivan <bos@serpentine.com>
date Fri, 27 Mar 2009 00:01:58 -0700
parents d179d63ea018
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
1 #!/usr/bin/env python
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2 #
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
3 # Adapter for using interdiff with mercurial's extdiff extension.
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4 #
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5 # Copyright 2006 Bryan O'Sullivan <bos@serpentine.com>
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 #
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8 # the GNU General Public License, incorporated herein by reference.
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10 import os
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 import shutil
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12 import sys
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13 import tempfile
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 if len(sys.argv) < 4:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
16 print >> sys.stderr, ('usage: %s srcrepo destrepo cset-to-omit [...]' %
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17 os.path.basename(sys.argv[0]))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
18 sys.exit(1)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
19
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 srcrepo, destrepo = sys.argv[1], sys.argv[2]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21 omit = sys.argv[3:]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
22
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
23 changemap = {}
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
24 revs = []
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 parent = None
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
27
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28 sys.stdout.write('gathering history...')
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29 sys.stdout.flush()
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 for line in os.popen("hg --cwd %r log -r0:tip --template '{rev}:{node} {parents}\n'" % srcrepo):
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
32 changes = line.split()
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33 cset = changes[0].split(':')[1]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34 rev = len(revs)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35 changemap[cset] = rev
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 if len(changes) >= 2:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
37 p1 = int(changes[1].split(':', 1)[0])
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 if len(changes) == 3:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39 p2 = int(changes[2].split(':', 1)[0])
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 else:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41 p2 = None
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42 if len(changes) == 1:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43 p1 = parent
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44 revs.append((cset, p1, p2))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 parent = rev
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 sys.stdout.write(' %d revs\n' % len(revs))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 def findrev(r):
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50 try:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 i = int(r)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52 if str(i) == r:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53 rev = i
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54 if rev < 0:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
55 rev += len(revs)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 if rev < 0 or rev > len(revs):
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57 print >> sys.stderr, 'bad changeset: %r' % r
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 sys.exit(1)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 cset = revs[rev][0]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60 except ValueError:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61 cset = r
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
62 matches = [changemap[c] for c in changemap if c.startswith(cset)]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
63 if len(matches) != 1:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
64 print >> sys.stderr, 'bad changeset: %r' % r
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
65 sys.exit(1)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
66 rev = matches[0]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
67 return rev
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
68
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
69 def run(cmd):
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
70 print cmd
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
71 ret = os.system(cmd)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
72 if ret:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
73 print >> sys.stderr, 'failure:', cmd
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
74 sys.exit(1)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
75
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
76 omit = map(findrev, omit)
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
77 omit.sort()
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
78 newrevs = revs[:omit[0]]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
79 tip = len(newrevs) - 1
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
80 run('hg clone -q -r%s %r %r' % (tip, srcrepo, destrepo))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
81
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
82 os.environ['HGMERGE'] = 'true'
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
83
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
84 patchdir = tempfile.mkdtemp(prefix='replay.')
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
85 try:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
86 run('hg --cwd %r export --git -o %r%s%%R %d:tip' %
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
87 (srcrepo, patchdir, os.sep, omit[0]+1))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
88 for rev in xrange(omit[0], len(revs)):
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
89 if rev in omit:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
90 print 'omit', rev
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
91 newrevs.append((None, revs[rev][1], None))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
92 continue
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
93 _, p1, p2 = revs[rev]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
94 np1 = newrevs[p1][1]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
95 if tip != np1:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
96 run('hg --cwd %r update -q -C %s' % (destrepo, np1))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
97 np2 = None
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
98 if p2:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
99 np2 = newrevs[p2][1]
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
100 run('hg --cwd %r merge -q %s' % (destrepo, np2))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
101 print >> sys.stderr, 'XXX - cannot handle merges properly yet'
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
102 run('hg --cwd %r import -q -f %r%s%d' % (destrepo, patchdir, os.sep, rev))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
103 tip = len(newrevs) - 1
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
104 newrevs.append((None, tip, np2))
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
105 finally:
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
106 print 'cleaning up ...'
d179d63ea018 New example script attempts to replay history, omitting selected changes.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
107 #shutil.rmtree(patchdir)