annotate hgext/convert/hg.py @ 20378:9616b03113ce

convert: add tagmap logic Previously, there was no way to rewrite tags on the fly while converting. Now, we add similar logic to branchmap to provide a way to map old tags to new tags. Currently, this is not enabled since there is not yet a command-line option.
author Sean Farley <sean.michael.farley@gmail.com>
date Wed, 22 Jan 2014 15:40:17 -0600
parents 5842d63cfe56
children d7e78e6d97bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8250
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
1 # hg.py - hg backend for convert extension
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
2 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
4 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10086
diff changeset
6 # GNU General Public License version 2 or any later version.
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
7
5556
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
8 # Notes for hg->hg conversion:
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
9 #
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
10 # * Old versions of Mercurial didn't trim the whitespace from the ends
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
11 # of commit messages, but new versions do. Changesets created by
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
12 # those older versions, then converted, may thus have different
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
13 # hashes for changesets that are otherwise identical.
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
14 #
8596
a58a95e523aa convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents: 8495
diff changeset
15 # * Using "--config convert.hg.saverev=true" will make the source
a58a95e523aa convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents: 8495
diff changeset
16 # identifier to be stored in the converted revision. This will cause
a58a95e523aa convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents: 8495
diff changeset
17 # the converted revision to have a different identity than the
a58a95e523aa convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents: 8495
diff changeset
18 # source.
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
19
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
20
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
21 import os, time, cStringIO
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
22 from mercurial.i18n import _
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 6210
diff changeset
23 from mercurial.node import bin, hex, nullid
19891
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
24 from mercurial import hg, util, context, bookmarks, error, scmutil
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
25
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
26 from common import NoRepo, commit, converter_source, converter_sink
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
27
20372
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
28 import re
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
29 sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
30
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
31 class mercurial_sink(converter_sink):
4763
8e9d3faec270 convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
32 def __init__(self, ui, path):
5440
b4ae8535f834 convert: add default constructor for converter_sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5439
diff changeset
33 converter_sink.__init__(self, ui, path)
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
34 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
35 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
5260
be4835ad9a85 convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents: 5195
diff changeset
36 self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
37 self.lastbranch = None
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
38 if os.path.isdir(path) and len(os.listdir(path)) > 0:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
39 try:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
40 self.repo = hg.repository(self.ui, path)
5918
1716c8a0bd09 convert: mercurial sink must be local
Patrick Mezard <pmezard@gmail.com>
parents: 5522
diff changeset
41 if not self.repo.local():
10938
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10282
diff changeset
42 raise NoRepo(_('%s is not a local Mercurial repository')
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10282
diff changeset
43 % path)
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
44 except error.RepoError, err:
8206
cce63ef1045b ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents: 8112
diff changeset
45 ui.traceback()
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
46 raise NoRepo(err.args[0])
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
47 else:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
48 try:
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
49 ui.status(_('initializing destination %s repository\n') % path)
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
50 self.repo = hg.repository(self.ui, path, create=True)
5918
1716c8a0bd09 convert: mercurial sink must be local
Patrick Mezard <pmezard@gmail.com>
parents: 5522
diff changeset
51 if not self.repo.local():
10938
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10282
diff changeset
52 raise NoRepo(_('%s is not a local Mercurial repository')
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10282
diff changeset
53 % path)
5441
71e7c86adcb7 convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents: 5440
diff changeset
54 self.created.append(path)
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7874
diff changeset
55 except error.RepoError:
8206
cce63ef1045b ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents: 8112
diff changeset
56 ui.traceback()
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
57 raise NoRepo(_("could not create hg repository %s as sink")
10938
02d6149a480b convert: write "repository" instead of "repo"
Martin Geisler <mg@lazybytes.net>
parents: 10282
diff changeset
58 % path)
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
59 self.lock = None
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
60 self.wlock = None
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
61 self.filemapmode = False
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
62
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
63 def before(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9432
diff changeset
64 self.ui.debug('run hg sink pre-conversion action\n')
5052
a11e8a181bd5 convert: fix locking order
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5038
diff changeset
65 self.wlock = self.repo.wlock()
5014
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
66 self.lock = self.repo.lock()
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
67
914054ca532e convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents: 5013
diff changeset
68 def after(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9432
diff changeset
69 self.ui.debug('run hg sink post-conversion action\n')
10086
e388f5ee7bf5 convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents: 9546
diff changeset
70 if self.lock:
e388f5ee7bf5 convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents: 9546
diff changeset
71 self.lock.release()
e388f5ee7bf5 convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents: 9546
diff changeset
72 if self.wlock:
e388f5ee7bf5 convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents: 9546
diff changeset
73 self.wlock.release()
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
74
5011
89fbb0a5e8e3 convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
75 def revmapfile(self):
15069
650d81a313cb convert: use repo.join instead of referencing ".hg" directly
Martin Geisler <mg@aragost.com>
parents: 14556
diff changeset
76 return self.repo.join("shamap")
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
77
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
78 def authorfile(self):
15069
650d81a313cb convert: use repo.join instead of referencing ".hg" directly
Martin Geisler <mg@aragost.com>
parents: 14556
diff changeset
79 return self.repo.join("authormap")
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
80
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
81 def getheads(self):
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
82 h = self.repo.changelog.heads()
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
83 return [hex(x) for x in h]
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
84
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
85 def setbranch(self, branch, pbranches):
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
86 if not self.clonebranches:
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
87 return
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
88
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
89 setbranch = (branch != self.lastbranch)
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
90 self.lastbranch = branch
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
91 if not branch:
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
92 branch = 'default'
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
93 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
94 pbranch = pbranches and pbranches[0][1] or 'default'
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
95
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
96 branchpath = os.path.join(self.path, branch)
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
97 if setbranch:
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
98 self.after()
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
99 try:
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
100 self.repo = hg.repository(self.ui, branchpath)
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16687
diff changeset
101 except Exception:
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
102 self.repo = hg.repository(self.ui, branchpath, create=True)
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
103 self.before()
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
104
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
105 # pbranches may bring revisions from other branches (merge parents)
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
106 # Make sure we have them, or pull them.
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
107 missings = {}
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
108 for b in pbranches:
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
109 try:
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
110 self.repo.lookup(b[0])
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16687
diff changeset
111 except Exception:
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
112 missings.setdefault(b[1], []).append(b[0])
6210
942287cb1f57 Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5959
diff changeset
113
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
114 if missings:
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
115 self.after()
18373
687ed69f6fdf convert: process missing branches in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 17922
diff changeset
116 for pbranch, heads in sorted(missings.iteritems()):
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
117 pbranchpath = os.path.join(self.path, pbranch)
14556
517e1d88bf7e hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents: 14151
diff changeset
118 prepo = hg.peer(self.ui, {}, pbranchpath)
5934
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
119 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
120 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
e495f3f35b2d convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents: 5918
diff changeset
121 self.before()
5173
6b4c332f241b convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents: 5143
diff changeset
122
20378
9616b03113ce convert: add tagmap logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 20377
diff changeset
123 def _rewritetags(self, source, revmap, tagmap, data):
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
124 fp = cStringIO.StringIO()
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
125 for line in data.splitlines():
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
126 s = line.split(' ', 1)
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
127 if len(s) != 2:
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
128 continue
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
129 revid = revmap.get(source.lookuprev(s[0]))
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
130 if not revid:
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
131 continue
20378
9616b03113ce convert: add tagmap logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 20377
diff changeset
132 fp.write('%s %s\n' % (revid, tagmap.get(s[1], s[1])))
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
133 return fp.getvalue()
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
134
20378
9616b03113ce convert: add tagmap logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 20377
diff changeset
135 def putcommit(self, files, copies, parents, commit, source,
9616b03113ce convert: add tagmap logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 20377
diff changeset
136 revmap, tagmap):
6716
c9b8d2565b92 convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents: 6217
diff changeset
137
6717
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
138 files = dict(files)
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
139 def getfilectx(repo, memctx, f):
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
140 v = files[f]
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
141 data, mode = source.getfile(f, v)
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
142 if f == '.hgtags':
20378
9616b03113ce convert: add tagmap logic
Sean Farley <sean.michael.farley@gmail.com>
parents: 20377
diff changeset
143 data = self._rewritetags(source, revmap, tagmap, data)
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
144 return context.memfilectx(f, data, 'l' in mode, 'x' in mode,
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
145 copies.get(f))
6717
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
146
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
147 pl = []
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
148 for p in parents:
6717
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
149 if p not in pl:
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
150 pl.append(p)
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
151 parents = pl
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
152 nparents = len(parents)
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
153 if self.filemapmode and nparents == 1:
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
154 m1node = self.repo.changelog.read(bin(parents[0]))[0]
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
155 parent = parents[0]
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
156
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
157 if len(parents) < 2:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
158 parents.append(nullid)
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
159 if len(parents) < 2:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
160 parents.append(nullid)
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
161 p2 = parents.pop(0)
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
162
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
163 text = commit.desc
20372
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
164
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
165 sha1s = re.findall(sha1re, text)
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
166 for sha1 in sha1s:
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
167 oldrev = source.lookuprev(sha1)
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
168 newrev = revmap.get(oldrev)
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
169 if newrev is not None:
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
170 text = text.replace(sha1, newrev[:len(sha1)])
45562379ce4e convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents: 19891
diff changeset
171
5439
d0c67b52ac01 convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5437
diff changeset
172 extra = commit.extra.copy()
5038
8f157190075e convert: add config option to turn off use of branch names
Bryan O'Sullivan <bos@serpentine.com>
parents: 5017
diff changeset
173 if self.branchnames and commit.branch:
4873
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
174 extra['branch'] = commit.branch
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
175 if commit.rev:
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4765
diff changeset
176 extra['convert_revision'] = commit.rev
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4873
diff changeset
177
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
178 while parents:
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
179 p1 = p2
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
180 p2 = parents.pop(0)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
181 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(),
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
182 getfilectx, commit.author, commit.date, extra)
7874
d812029cda85 cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7815
diff changeset
183 self.repo.commitctx(ctx)
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
184 text = "(octopus merge fixup)\n"
6217
fe8dbbe9520d Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents: 6212
diff changeset
185 p2 = hex(self.repo.changelog.tip())
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
186
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
187 if self.filemapmode and nparents == 1:
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
188 man = self.repo.manifest
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
189 mnode = self.repo.changelog.read(bin(p2))[0]
11673
a2f11188e2d2 convert: handle closed branch heads in hg-hg conversion (issue2185)
Matt Mackall <mpm@selenic.com>
parents: 11134
diff changeset
190 closed = 'close' in commit.extra
a2f11188e2d2 convert: handle closed branch heads in hg-hg conversion (issue2185)
Matt Mackall <mpm@selenic.com>
parents: 11134
diff changeset
191 if not closed and not man.cmp(m1node, man.revision(mnode)):
8611
ba42e3c6e602 convert: better feedback when filtering out empty revisions
Patrick Mezard <pmezard@gmail.com>
parents: 8596
diff changeset
192 self.ui.status(_("filtering out empty revision\n"))
15193
a84e3ed661cb convert: fix crazy rollback call, broken by recent rollback safety checks
Matt Mackall <mpm@selenic.com>
parents: 15069
diff changeset
193 self.repo.rollback(force=True)
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
194 return parent
1389
9b3ef6f3cef5 convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents: 1388
diff changeset
195 return p2
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
196
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
197 def puttags(self, tags):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
198 try:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
199 parentctx = self.repo[self.tagsbranch]
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
200 tagparent = parentctx.node()
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
201 except error.RepoError:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
202 parentctx = None
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
203 tagparent = nullid
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
204
20376
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
205 oldlines = set()
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
206 for branch, heads in self.repo.branchmap().iteritems():
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
207 for h in heads:
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
208 if '.hgtags' in self.repo[h]:
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
209 oldlines.update(
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
210 set(self.repo[h]['.hgtags'].data().splitlines(True)))
7a4797910205 convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents: 20373
diff changeset
211 oldlines = sorted(list(oldlines))
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
212
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
213 newlines = sorted([("%s %s\n" % (tags[tag], tag)) for tag in tags])
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
214 if newlines == oldlines:
9431
d1b135f2f415 convert: fix history topology when using hg.tagsbranch
Patrick Mezard <pmezard@gmail.com>
parents: 8693
diff changeset
215 return None, None
20377
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
216
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
217 # if the old and new tags match, then there is nothing to update
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
218 oldtags = set()
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
219 newtags = set()
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
220 for line in oldlines:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
221 s = line.strip().split(' ', 1)
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
222 if len(s) != 2:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
223 continue
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
224 oldtags.add(s[1])
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
225 for line in newlines:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
226 s = line.strip().split(' ', 1)
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
227 if len(s) != 2:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
228 continue
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
229 if s[1] not in oldtags:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
230 newtags.add(s[1].strip())
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
231
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
232 if not newtags:
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
233 return None, None
5842d63cfe56 convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents: 20376
diff changeset
234
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
235 data = "".join(newlines)
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
236 def getfilectx(repo, memctx, f):
6717
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
237 return context.memfilectx(f, data, False, False, None)
2011bb8ada9a convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents: 6716
diff changeset
238
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
239 self.ui.status(_("updating tags\n"))
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
240 date = "%s 0" % int(time.mktime(time.gmtime()))
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
241 extra = {'branch': self.tagsbranch}
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
242 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
243 [".hgtags"], getfilectx, "convert-repo", date,
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
244 extra)
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7875
diff changeset
245 self.repo.commitctx(ctx)
9431
d1b135f2f415 convert: fix history topology when using hg.tagsbranch
Patrick Mezard <pmezard@gmail.com>
parents: 8693
diff changeset
246 return hex(self.repo.changelog.tip()), hex(tagparent)
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
247
5378
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
248 def setfilemapmode(self, active):
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
249 self.filemapmode = active
8a2915f57dfc convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5360
diff changeset
250
13746
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
251 def putbookmarks(self, updatedbookmark):
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
252 if not len(updatedbookmark):
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
253 return
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
254
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
255 self.ui.status(_("updating bookmarks\n"))
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 16867
diff changeset
256 destmarks = self.repo._bookmarks
13746
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
257 for bookmark in updatedbookmark:
17922
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 16867
diff changeset
258 destmarks[bookmark] = bin(updatedbookmark[bookmark])
7f5dab94e48c bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents: 16867
diff changeset
259 destmarks.write()
13746
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
260
16106
d75aa756149b convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents: 15193
diff changeset
261 def hascommit(self, rev):
16686
67964cda8701 cleanup: "not x in y" -> "x not in y"
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
262 if rev not in self.repo and self.clonebranches:
16162
7e279d475669 convert: fix typos in error messages
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 16106
diff changeset
263 raise util.Abort(_('revision %s not found in destination '
16106
d75aa756149b convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents: 15193
diff changeset
264 'repository (lookups with clonebranches=true '
d75aa756149b convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents: 15193
diff changeset
265 'are not implemented)') % rev)
d75aa756149b convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents: 15193
diff changeset
266 return rev in self.repo
13746
d80b768545cb convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents: 11673
diff changeset
267
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
268 class mercurial_source(converter_source):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
269 def __init__(self, ui, path, rev=None):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
270 converter_source.__init__(self, ui, path, rev)
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
271 self.ignoreerrors = ui.configbool('convert', 'hg.ignoreerrors', False)
8456
e9e2a2c9b294 convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8250
diff changeset
272 self.ignored = set()
7815
bcd364b247ba convert: change hg.saverev default to False
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
273 self.saverev = ui.configbool('convert', 'hg.saverev', False)
5358
4fbd27bf04b1 convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents: 5352
diff changeset
274 try:
4fbd27bf04b1 convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents: 5352
diff changeset
275 self.repo = hg.repository(self.ui, path)
5437
4d34f8b12a9e convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents: 5402
diff changeset
276 # try to provoke an exception if this isn't really a hg
4d34f8b12a9e convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents: 5402
diff changeset
277 # repo, but some other bogus compatible-looking url
5522
f5345a2d2391 convert: make sure mercurial_source has a local hg repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5521
diff changeset
278 if not self.repo.local():
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 16686
diff changeset
279 raise error.RepoError
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
280 except error.RepoError:
8206
cce63ef1045b ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents: 8112
diff changeset
281 ui.traceback()
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
282 raise NoRepo(_("%s is not a local Mercurial repository") % path)
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
283 self.lastrev = None
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
284 self.lastctx = None
5379
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
285 self._changescache = None
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5553
diff changeset
286 self.convertfp = None
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
287 # Restrict converted revisions to startrev descendants
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
288 startnode = ui.config('convert', 'hg.startrev')
19891
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
289 hgrevs = ui.config('convert', 'hg.revs')
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
290 if hgrevs is None:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
291 if startnode is not None:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
292 try:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
293 startnode = self.repo.lookup(startnode)
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
294 except error.RepoError:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
295 raise util.Abort(_('%s is not a valid start revision')
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
296 % startnode)
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
297 startrev = self.repo.changelog.rev(startnode)
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
298 children = {startnode: 1}
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
299 for r in self.repo.changelog.descendants([startrev]):
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
300 children[self.repo.changelog.node(r)] = 1
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
301 self.keep = children.__contains__
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
302 else:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
303 self.keep = util.always
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
304 if rev:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
305 self._heads = [self.repo[rev].node()]
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
306 else:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
307 self._heads = self.repo.heads()
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
308 else:
19891
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
309 if rev or startnode is not None:
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
310 raise util.Abort(_('hg.revs cannot be combined with '
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
311 'hg.startrev or --rev'))
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
312 nodes = set()
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
313 parents = set()
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
314 for r in scmutil.revrange(self.repo, [hgrevs]):
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
315 ctx = self.repo[r]
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
316 nodes.add(ctx.node())
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
317 parents.update(p.node() for p in ctx.parents())
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
318 self.keep = nodes.__contains__
e271970b9821 convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents: 19890
diff changeset
319 self._heads = nodes - parents
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
320
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
321 def changectx(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
322 if self.lastrev != rev:
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6717
diff changeset
323 self.lastctx = self.repo[rev]
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
324 self.lastrev = rev
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
325 return self.lastctx
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
326
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
327 def parents(self, ctx):
9531
a2f36a082449 convert/hg: make parents() return changectx, not nodes
Patrick Mezard <pmezard@gmail.com>
parents: 9431
diff changeset
328 return [p for p in ctx.parents() if p and self.keep(p.node())]
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
329
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
330 def getheads(self):
19890
9057855d8749 convert: refactor head calculation for hg sources
Mads Kiilerich <madski@unity3d.com>
parents: 19457
diff changeset
331 return [hex(h) for h in self._heads if self.keep(h)]
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
332
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
333 def getfile(self, name, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
334 try:
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
335 fctx = self.changectx(rev)[name]
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
336 return fctx.data(), fctx.flags()
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7236
diff changeset
337 except error.LookupError, err:
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
338 raise IOError(err)
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
339
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
340 def getchanges(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
341 ctx = self.changectx(rev)
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
342 parents = self.parents(ctx)
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
343 if not parents:
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
344 files = sorted(ctx.manifest())
14151
1fe82c93b8e2 convert: also catch missing revlogs when introduced in repo roots
Mads Kiilerich <mads@kiilerich.com>
parents: 13757
diff changeset
345 # getcopies() is not needed for roots, but it is a simple way to
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16514
diff changeset
346 # detect missing revlogs and abort on errors or populate
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16514
diff changeset
347 # self.ignored
14151
1fe82c93b8e2 convert: also catch missing revlogs when introduced in repo roots
Mads Kiilerich <mads@kiilerich.com>
parents: 13757
diff changeset
348 self.getcopies(ctx, parents, files)
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
349 return [(f, rev) for f in files if f not in self.ignored], {}
5379
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
350 if self._changescache and self._changescache[0] == rev:
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
351 m, a, r = self._changescache[1]
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
352 else:
9531
a2f36a082449 convert/hg: make parents() return changectx, not nodes
Patrick Mezard <pmezard@gmail.com>
parents: 9431
diff changeset
353 m, a, r = self.repo.status(parents[0].node(), ctx.node())[:3]
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
354 # getcopies() detects missing revlogs early, run it before
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
355 # filtering the changes.
9532
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
356 copies = self.getcopies(ctx, parents, m + a)
7236
db6fbb785800 Remove trailing spaces.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7232
diff changeset
357 changes = [(name, rev) for name in m + a + r
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
358 if name not in self.ignored]
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8206
diff changeset
359 return sorted(changes), copies
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
360
9532
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
361 def getcopies(self, ctx, parents, files):
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
362 copies = {}
5280
11e1e574da02 convert: mercurial_source: also search for copies in modified files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5279
diff changeset
363 for name in files:
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
364 if name in self.ignored:
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
365 continue
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
366 try:
19457
948df0f10ec1 convert: fix bad conversion of copies when hg.startrev is specified
Mads Kiilerich <madski@unity3d.com>
parents: 19120
diff changeset
367 copysource, _copynode = ctx.filectx(name).renamed()
948df0f10ec1 convert: fix bad conversion of copies when hg.startrev is specified
Mads Kiilerich <madski@unity3d.com>
parents: 19120
diff changeset
368 if copysource in self.ignored:
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
369 continue
9532
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
370 # Ignore copy sources not in parent revisions
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
371 found = False
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
372 for p in parents:
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
373 if copysource in p:
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
374 found = True
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
375 break
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
376 if not found:
989cb39d1df4 convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents: 9531
diff changeset
377 continue
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
378 copies[name] = copysource
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
379 except TypeError:
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
380 pass
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents: 7236
diff changeset
381 except error.LookupError, e:
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
382 if not self.ignoreerrors:
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
383 raise
8456
e9e2a2c9b294 convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8250
diff changeset
384 self.ignored.add(name)
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
385 self.ui.warn(_('ignoring: %s\n') % e)
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
386 return copies
5143
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5131
diff changeset
387
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
388 def getcommit(self, rev):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
389 ctx = self.changectx(rev)
9531
a2f36a082449 convert/hg: make parents() return changectx, not nodes
Patrick Mezard <pmezard@gmail.com>
parents: 9431
diff changeset
390 parents = [p.hex() for p in self.parents(ctx)]
5556
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
391 if self.saverev:
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
392 crev = rev
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
393 else:
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
394 crev = None
16514
363e808de349 i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16162
diff changeset
395 return commit(author=ctx.user(),
363e808de349 i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 16162
diff changeset
396 date=util.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'),
5556
61fdf2558c0a convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents: 5554
diff changeset
397 desc=ctx.description(), rev=crev, parents=parents,
8690
c5b4f662109f convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents: 8611
diff changeset
398 branch=ctx.branch(), extra=ctx.extra(),
c5b4f662109f convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents: 8611
diff changeset
399 sortkey=ctx.rev())
5013
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
400
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
401 def gettags(self):
6c1029aacc9a convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
402 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
403 return dict([(name, hex(node)) for name, node in tags
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
404 if self.keep(node)])
5379
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
405
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
406 def getchangedfiles(self, rev, i):
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
407 ctx = self.changectx(rev)
6885
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
408 parents = self.parents(ctx)
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
409 if not parents and i is None:
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
410 i = 0
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
411 changes = [], ctx.manifest().keys(), []
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
412 else:
6e253aa04ff7 convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents: 6762
diff changeset
413 i = i or 0
9531
a2f36a082449 convert/hg: make parents() return changectx, not nodes
Patrick Mezard <pmezard@gmail.com>
parents: 9431
diff changeset
414 changes = self.repo.status(parents[i].node(), ctx.node())[:3]
7231
8e7130a10f3b convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents: 6956
diff changeset
415 changes = [[f for f in l if f not in self.ignored] for l in changes]
5379
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
416
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
417 if i == 0:
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
418 self._changescache = (rev, changes)
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
419
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
420 return changes[0] + changes[1] + changes[2]
d3e51dc804f8 mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5378
diff changeset
421
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5553
diff changeset
422 def converted(self, rev, destrev):
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5553
diff changeset
423 if self.convertfp is None:
15069
650d81a313cb convert: use repo.join instead of referencing ".hg" directly
Martin Geisler <mg@aragost.com>
parents: 14556
diff changeset
424 self.convertfp = open(self.repo.join('shamap'), 'a')
5554
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5553
diff changeset
425 self.convertfp.write('%s %s\n' % (destrev, rev))
2147a734dcf9 convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents: 5553
diff changeset
426 self.convertfp.flush()
5805
e422305e0853 test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents: 5556
diff changeset
427
e422305e0853 test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents: 5556
diff changeset
428 def before(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9432
diff changeset
429 self.ui.debug('run hg source pre-conversion action\n')
5805
e422305e0853 test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents: 5556
diff changeset
430
e422305e0853 test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents: 5556
diff changeset
431 def after(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9432
diff changeset
432 self.ui.debug('run hg source post-conversion action\n')
8691
a0a541d6fed6 convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents: 8690
diff changeset
433
a0a541d6fed6 convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents: 8690
diff changeset
434 def hasnativeorder(self):
a0a541d6fed6 convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents: 8690
diff changeset
435 return True
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
436
18819
05acdf8e1f23 convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents: 18373
diff changeset
437 def hasnativeclose(self):
05acdf8e1f23 convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents: 18373
diff changeset
438 return True
05acdf8e1f23 convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents: 18373
diff changeset
439
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
440 def lookuprev(self, rev):
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
441 try:
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
442 return hex(self.repo.lookup(rev))
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
443 except error.RepoError:
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
444 return None
13757
043238abda94 convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents: 13746
diff changeset
445
043238abda94 convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents: 13746
diff changeset
446 def getbookmarks(self):
043238abda94 convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents: 13746
diff changeset
447 return bookmarks.listbookmarks(self.repo)
19120
58e782f076e7 splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents: 18819
diff changeset
448
20373
e8203629371b convert: add mapname parameter to checkrevformat
Sean Farley <sean.michael.farley@gmail.com>
parents: 20372
diff changeset
449 def checkrevformat(self, revstr, mapname='splicemap'):
19120
58e782f076e7 splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents: 18819
diff changeset
450 """ Mercurial, revision string is a 40 byte hex """
20373
e8203629371b convert: add mapname parameter to checkrevformat
Sean Farley <sean.michael.farley@gmail.com>
parents: 20372
diff changeset
451 self.checkhexformat(revstr, mapname)