Mercurial > hg
annotate hgext/convert/hg.py @ 5725:8114d4c915a7
bisect: turn ancestors into an array
This makes things faster and eliminates the separate stop hash
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 27 Dec 2007 23:55:39 -0600 |
parents | 61fdf2558c0a |
children | e422305e0853 |
rev | line source |
---|---|
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
1 # hg backend for convert extension |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
2 |
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
3 # Notes for hg->hg conversion: |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
4 # |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
5 # * 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
|
6 # 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
|
7 # 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
|
8 # 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
|
9 # |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
10 # * By default, the source revision is stored in the converted |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
11 # revision. This will cause the converted revision to have a |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
12 # different identity than the source. To avoid this, use the |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
13 # following option: "--config convert.hg.saverev=false" |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
14 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
15 |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
16 import os, time |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
17 from mercurial.i18n import _ |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
18 from mercurial.node import * |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
19 from mercurial import hg, lock, revlog, util |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
20 |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
21 from common import NoRepo, commit, converter_source, converter_sink |
694 | 22 |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
23 class mercurial_sink(converter_sink): |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
24 def __init__(self, ui, path): |
5440
b4ae8535f834
convert: add default constructor for converter_sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5439
diff
changeset
|
25 converter_sink.__init__(self, ui, path) |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 self.lastbranch = None |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
30 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
|
31 try: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
32 self.repo = hg.repository(self.ui, path) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
33 except hg.RepoError, err: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
34 ui.print_exc() |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
35 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
|
36 else: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
37 try: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
38 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
|
39 self.repo = hg.repository(self.ui, path, create=True) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
40 self.created.append(path) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
41 except hg.RepoError, err: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
42 ui.print_exc() |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
43 raise NoRepo("could not create hg repo %s as sink" % path) |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
44 self.lock = None |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
45 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
|
46 self.filemapmode = False |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
47 |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
48 def before(self): |
5052
a11e8a181bd5
convert: fix locking order
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5038
diff
changeset
|
49 self.wlock = self.repo.wlock() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
50 self.lock = self.repo.lock() |
5279
2dbd750b3ddd
convert: clear the dirstate before a conversion, invalidate it afterwards
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5278
diff
changeset
|
51 self.repo.dirstate.clear() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
52 |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
53 def after(self): |
5279
2dbd750b3ddd
convert: clear the dirstate before a conversion, invalidate it afterwards
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5278
diff
changeset
|
54 self.repo.dirstate.invalidate() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
55 self.lock = None |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
56 self.wlock = None |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
57 |
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
|
58 def revmapfile(self): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
59 return os.path.join(self.path, ".hg", "shamap") |
316 | 60 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
61 def authorfile(self): |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
62 return os.path.join(self.path, ".hg", "authormap") |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
63 |
316 | 64 def getheads(self): |
65 h = self.repo.changelog.heads() | |
5017
06329efa722d
convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents:
5016
diff
changeset
|
66 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
|
67 |
316 | 68 def putfile(self, f, e, data): |
4082
6b2909e84203
convert-repo converts symlinks from git
Daniel Holth <dholth@fastmail.fm>
parents:
4062
diff
changeset
|
69 self.repo.wwrite(f, data, e) |
4906
30847b8af7ca
dirstate: add __contains__ and make __getitem__ more useful
Matt Mackall <mpm@selenic.com>
parents:
4904
diff
changeset
|
70 if f not in self.repo.dirstate: |
5278
70e9a527cc61
convert: avoid dirstate checks; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5260
diff
changeset
|
71 self.repo.dirstate.normallookup(f) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
72 |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
73 def copyfile(self, source, dest): |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
74 self.repo.copy(source, dest) |
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
75 |
316 | 76 def delfile(self, f): |
77 try: | |
5343
26692d08c2f9
convert: delete empty directories if deleting a file (bug 754)
Bryan O'Sullivan <bos@serpentine.com>
parents:
4589
diff
changeset
|
78 util.unlink(self.repo.wjoin(f)) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
79 #self.repo.remove([f]) |
5344
002fe2f364f5
convert: fix missing import
Patrick Mezard <pmezard@gmail.com>
parents:
5343
diff
changeset
|
80 except OSError: |
316 | 81 pass |
82 | |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
83 def setbranch(self, branch, pbranch, parents): |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
84 if (not self.clonebranches) or (branch == self.lastbranch): |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
85 return |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
86 |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
87 self.lastbranch = branch |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
88 self.after() |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
89 if not branch: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
90 branch = 'default' |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
91 if not pbranch: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
92 pbranch = 'default' |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
93 |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
94 branchpath = os.path.join(self.path, branch) |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
95 try: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
96 self.repo = hg.repository(self.ui, branchpath) |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
97 except: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
98 if not parents: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
99 self.repo = hg.repository(self.ui, branchpath, create=True) |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
100 else: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
101 self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch)) |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
102 hg.clone(self.ui, os.path.join(self.path, pbranch), |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
103 branchpath, rev=parents, update=False, |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
104 stream=True) |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
105 self.repo = hg.repository(self.ui, branchpath) |
5402
ad0b580cad35
mercurial_sink: regrab locks in setbranch
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5379
diff
changeset
|
106 self.before() |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
107 |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
108 def putcommit(self, files, parents, commit): |
5195
33015dac5df5
convert: fix mercurial_sink.putcommit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5173
diff
changeset
|
109 seen = {} |
431 | 110 pl = [] |
111 for p in parents: | |
112 if p not in seen: | |
113 pl.append(p) | |
114 seen[p] = 1 | |
115 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
|
116 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
|
117 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
|
118 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
|
119 parent = parents[0] |
316 | 120 |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
121 if len(parents) < 2: parents.append("0" * 40) |
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
122 if len(parents) < 2: parents.append("0" * 40) |
431 | 123 p2 = parents.pop(0) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
124 |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
125 text = commit.desc |
5439
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5437
diff
changeset
|
126 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
|
127 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
|
128 extra['branch'] = commit.branch |
28b23b9073a8
convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
129 if commit.rev: |
28b23b9073a8
convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents:
4765
diff
changeset
|
130 extra['convert_revision'] = commit.rev |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4873
diff
changeset
|
131 |
431 | 132 while parents: |
133 p1 = p2 | |
134 p2 = parents.pop(0) | |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
135 a = self.repo.rawcommit(files, text, commit.author, commit.date, |
5017
06329efa722d
convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents:
5016
diff
changeset
|
136 bin(p1), bin(p2), extra=extra) |
5278
70e9a527cc61
convert: avoid dirstate checks; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5260
diff
changeset
|
137 self.repo.dirstate.clear() |
431 | 138 text = "(octopus merge fixup)\n" |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
139 p2 = hg.hex(self.repo.changelog.tip()) |
431 | 140 |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
141 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
|
142 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
|
143 mnode = self.repo.changelog.read(bin(p2))[0] |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
144 if not man.cmp(m1node, man.revision(mnode)): |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
145 self.repo.rollback() |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
146 self.repo.dirstate.clear() |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
147 return parent |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
148 return p2 |
316 | 149 |
694 | 150 def puttags(self, tags): |
151 try: | |
152 old = self.repo.wfile(".hgtags").read() | |
153 oldlines = old.splitlines(1) | |
154 oldlines.sort() | |
155 except: | |
156 oldlines = [] | |
157 | |
158 k = tags.keys() | |
159 k.sort() | |
160 newlines = [] | |
161 for tag in k: | |
162 newlines.append("%s %s\n" % (tags[tag], tag)) | |
163 | |
164 newlines.sort() | |
165 | |
166 if newlines != oldlines: | |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
167 self.ui.status("updating tags\n") |
694 | 168 f = self.repo.wfile(".hgtags", "w") |
169 f.write("".join(newlines)) | |
170 f.close() | |
171 if not oldlines: self.repo.add([".hgtags"]) | |
1335
bea6356b8bca
git -> hg conversion script
Florian La Roche <laroche@redhat.com>
parents:
1237
diff
changeset
|
172 date = "%s 0" % int(time.mktime(time.gmtime())) |
5260
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
173 extra = {} |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
174 if self.tagsbranch != 'default': |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
175 extra['branch'] = self.tagsbranch |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
176 try: |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
177 tagparent = self.repo.changectx(self.tagsbranch).node() |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
178 except hg.RepoError, inst: |
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
179 tagparent = nullid |
694 | 180 self.repo.rawcommit([".hgtags"], "update tags", "convert-repo", |
5260
be4835ad9a85
convert: new config variable hg.tagsbranch controls which branch tags are committed to
Brendan Cully <brendan@kublai.com>
parents:
5195
diff
changeset
|
181 date, tagparent, nullid) |
5017
06329efa722d
convert: get rid of "hg." prefix where not needed
Bryan O'Sullivan <bos@serpentine.com>
parents:
5016
diff
changeset
|
182 return hex(self.repo.changelog.tip()) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
183 |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
184 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
|
185 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
|
186 |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
187 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
|
188 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
|
189 converter_source.__init__(self, ui, path, rev) |
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
190 self.saverev = ui.configbool('convert', 'hg.saverev', True) |
5358
4fbd27bf04b1
convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents:
5352
diff
changeset
|
191 try: |
4fbd27bf04b1
convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents:
5352
diff
changeset
|
192 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
|
193 # 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
|
194 # 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
|
195 if not self.repo.local(): |
f5345a2d2391
convert: make sure mercurial_source has a local hg repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5521
diff
changeset
|
196 raise hg.RepoError() |
5437
4d34f8b12a9e
convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents:
5402
diff
changeset
|
197 except hg.RepoError: |
4d34f8b12a9e
convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents:
5402
diff
changeset
|
198 ui.print_exc() |
5522
f5345a2d2391
convert: make sure mercurial_source has a local hg repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5521
diff
changeset
|
199 raise NoRepo("%s is not a local Mercurial repo" % path) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
200 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
|
201 self.lastctx = None |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
202 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
|
203 self.convertfp = None |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
204 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
205 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
|
206 if 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
|
207 self.lastctx = self.repo.changectx(rev) |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
208 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
|
209 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
|
210 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
211 def getheads(self): |
5131
2f9edf6bae95
convert: only get history for requested revs when converting hg repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
5121
diff
changeset
|
212 if self.rev: |
2f9edf6bae95
convert: only get history for requested revs when converting hg repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
5121
diff
changeset
|
213 return [hex(self.repo.changectx(self.rev).node())] |
2f9edf6bae95
convert: only get history for requested revs when converting hg repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
5121
diff
changeset
|
214 else: |
2f9edf6bae95
convert: only get history for requested revs when converting hg repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
5121
diff
changeset
|
215 return [hex(node) for node in self.repo.heads()] |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
216 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
217 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
|
218 try: |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
219 return self.changectx(rev).filectx(name).data() |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
220 except revlog.LookupError, err: |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
221 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
|
222 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
223 def getmode(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
|
224 m = self.changectx(rev).manifest() |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
225 return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '') |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
226 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
227 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
|
228 ctx = self.changectx(rev) |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
229 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
|
230 m, a, r = self._changescache[1] |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
231 else: |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
232 m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3] |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
233 changes = [(name, rev) for name in m + a + r] |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
234 changes.sort() |
5280
11e1e574da02
convert: mercurial_source: also search for copies in modified files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5279
diff
changeset
|
235 return (changes, self.getcopies(ctx, m + a)) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
236 |
5280
11e1e574da02
convert: mercurial_source: also search for copies in modified files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5279
diff
changeset
|
237 def getcopies(self, ctx, files): |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
238 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
|
239 for name in files: |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
240 try: |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
241 copies[name] = ctx.filectx(name).renamed()[0] |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
242 except TypeError: |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
243 pass |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
244 return copies |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5131
diff
changeset
|
245 |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
246 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
|
247 ctx = self.changectx(rev) |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
248 parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid] |
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
249 if self.saverev: |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
250 crev = rev |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
251 else: |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
252 crev = None |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
253 return commit(author=ctx.user(), date=util.datestr(ctx.date()), |
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
254 desc=ctx.description(), rev=crev, parents=parents, |
5439
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5437
diff
changeset
|
255 branch=ctx.branch(), extra=ctx.extra()) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
256 |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
257 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
|
258 tags = [t for t in self.repo.tagslist() if t[0] != 'tip'] |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
259 return dict([(name, hex(node)) for name, node in tags]) |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
260 |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
261 def getchangedfiles(self, rev, i): |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
262 ctx = self.changectx(rev) |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
263 i = i or 0 |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
264 changes = self.repo.status(ctx.parents()[i].node(), ctx.node())[:3] |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
265 |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
266 if i == 0: |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
267 self._changescache = (rev, changes) |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
268 |
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
269 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
|
270 |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
271 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
|
272 if self.convertfp is None: |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
273 self.convertfp = open(os.path.join(self.path, '.hg', 'shamap'), |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
274 'a') |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
275 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
|
276 self.convertfp.flush() |