author | Patrick Mezard <pmezard@gmail.com> |
Sun, 09 Dec 2007 15:25:36 +0100 | |
changeset 5621 | badbefa55972 |
parent 5521 | hgext/convert/__init__.py@03496d4fa509 |
child 5632 | fe2e81229819 |
child 5934 | e495f3f35b2d |
permissions | -rw-r--r-- |
5621
badbefa55972
convert: move commands definition to ease demandload job (issue 860)
Patrick Mezard <pmezard@gmail.com>
parents:
5521
diff
changeset
|
1 |
# convcmd - convert extension commands definition |
3917
645e1dd4b8ae
convert-repo: update usage information
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3911
diff
changeset
|
2 |
# |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4591
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
316 | 4 |
# |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
5 |
# This software may be used and distributed according to the terms |
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
6 |
# of the GNU General Public License, incorporated herein by reference. |
316 | 7 |
|
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
8 |
from common import NoRepo, SKIPREV, converter_source, converter_sink |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
9 |
from cvs import convert_cvs |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
5356
diff
changeset
|
10 |
from darcs import darcs_source |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
11 |
from git import convert_git |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5012
diff
changeset
|
12 |
from hg import mercurial_source, mercurial_sink |
5438
6fa5258be3d4
convert: rename convert_svn to svn_source
Bryan O'Sullivan <bos@serpentine.com>
parents:
5415
diff
changeset
|
13 |
from subversion import svn_source, debugsvnlog |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
14 |
import filemap |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
15 |
|
5376
d60a067227a5
convert: move filemapper class to a separate file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5375
diff
changeset
|
16 |
import os, shutil |
5621
badbefa55972
convert: move commands definition to ease demandload job (issue 860)
Patrick Mezard <pmezard@gmail.com>
parents:
5521
diff
changeset
|
17 |
from mercurial import hg, util |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
18 |
from mercurial.i18n import _ |
3821
158fce02dc40
Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents:
2657
diff
changeset
|
19 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
20 |
source_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
21 |
('cvs', convert_cvs), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
22 |
('git', convert_git), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
23 |
('svn', svn_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
24 |
('hg', mercurial_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
25 |
('darcs', darcs_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
26 |
] |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
27 |
|
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
28 |
sink_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
29 |
('hg', mercurial_sink), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
30 |
] |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
31 |
|
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
32 |
def convertsource(ui, path, type, rev): |
5521
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5488
diff
changeset
|
33 |
exceptions = [] |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
34 |
for name, source in source_converters: |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
35 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
36 |
if not type or name == type: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
37 |
return source(ui, path, rev) |
5415
1d53a75ea0fc
convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
5414
diff
changeset
|
38 |
except NoRepo, inst: |
5521
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5488
diff
changeset
|
39 |
exceptions.append(inst) |
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5488
diff
changeset
|
40 |
if not ui.quiet: |
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5488
diff
changeset
|
41 |
for inst in exceptions: |
03496d4fa509
convert: display all errors if we couldn't open the source repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5488
diff
changeset
|
42 |
ui.write(_("%s\n") % inst) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
43 |
raise util.Abort('%s: unknown repository type' % path) |
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
44 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
45 |
def convertsink(ui, path, type): |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
46 |
for name, sink in sink_converters: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
47 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
48 |
if not type or name == type: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
49 |
return sink(ui, path) |
5415
1d53a75ea0fc
convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
5414
diff
changeset
|
50 |
except NoRepo, inst: |
1d53a75ea0fc
convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
5414
diff
changeset
|
51 |
ui.note(_("convert: %s\n") % inst) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
52 |
raise util.Abort('%s: unknown repository type' % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
53 |
|
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
54 |
class converter(object): |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
55 |
def __init__(self, ui, source, dest, revmapfile, opts): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
56 |
|
316 | 57 |
self.source = source |
58 |
self.dest = dest |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
59 |
self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
60 |
self.opts = opts |
316 | 61 |
self.commitcache = {} |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
62 |
self.revmapfile = revmapfile |
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
63 |
self.revmapfilefd = None |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
64 |
self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
65 |
self.authorfile = None |
316 | 66 |
|
5373
6aba1835a7b3
convert: pass the order of the revmapfile to the converter_source
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5359
diff
changeset
|
67 |
self.maporder = [] |
316 | 68 |
self.map = {} |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
69 |
try: |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
70 |
origrevmapfile = open(self.revmapfile, 'r') |
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
71 |
for l in origrevmapfile: |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
72 |
sv, dv = l[:-1].split() |
5373
6aba1835a7b3
convert: pass the order of the revmapfile to the converter_source
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5359
diff
changeset
|
73 |
if sv not in self.map: |
6aba1835a7b3
convert: pass the order of the revmapfile to the converter_source
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5359
diff
changeset
|
74 |
self.maporder.append(sv) |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
75 |
self.map[sv] = dv |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
76 |
origrevmapfile.close() |
1655
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
77 |
except IOError: |
7bfd4724932a
convert-repo: automatically create empty map file
Matt Mackall <mpm@selenic.com>
parents:
1389
diff
changeset
|
78 |
pass |
316 | 79 |
|
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
80 |
# Read first the dst author map if any |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
81 |
authorfile = self.dest.authorfile() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
82 |
if authorfile and os.path.exists(authorfile): |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
83 |
self.readauthormap(authorfile) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
84 |
# Extend/Override with new author map if necessary |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
85 |
if opts.get('authors'): |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
86 |
self.readauthormap(opts.get('authors')) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
87 |
self.authorfile = self.dest.authorfile() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
88 |
|
316 | 89 |
def walktree(self, heads): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
90 |
'''Return a mapping that identifies the uncommitted parents of every |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
91 |
uncommitted changeset.''' |
316 | 92 |
visit = heads |
93 |
known = {} |
|
94 |
parents = {} |
|
95 |
while visit: |
|
96 |
n = visit.pop(0) |
|
97 |
if n in known or n in self.map: continue |
|
98 |
known[n] = 1 |
|
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
99 |
commit = self.cachecommit(n) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
100 |
parents[n] = [] |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
101 |
for p in commit.parents: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
102 |
parents[n].append(p) |
316 | 103 |
visit.append(p) |
104 |
||
105 |
return parents |
|
106 |
||
107 |
def toposort(self, parents): |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
108 |
'''Return an ordering such that every uncommitted changeset is |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
109 |
preceeded by all its uncommitted ancestors.''' |
316 | 110 |
visit = parents.keys() |
111 |
seen = {} |
|
112 |
children = {} |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
113 |
|
316 | 114 |
while visit: |
115 |
n = visit.pop(0) |
|
116 |
if n in seen: continue |
|
117 |
seen[n] = 1 |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
118 |
# Ensure that nodes without parents are present in the 'children' |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
119 |
# mapping. |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
120 |
children.setdefault(n, []) |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
121 |
for p in parents[n]: |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
122 |
if not p in self.map: |
316 | 123 |
visit.append(p) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
124 |
children.setdefault(p, []).append(n) |
316 | 125 |
|
126 |
s = [] |
|
127 |
removed = {} |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
128 |
visit = children.keys() |
316 | 129 |
while visit: |
130 |
n = visit.pop(0) |
|
131 |
if n in removed: continue |
|
132 |
dep = 0 |
|
133 |
if n in parents: |
|
134 |
for p in parents[n]: |
|
135 |
if p in self.map: continue |
|
136 |
if p not in removed: |
|
137 |
# we're still dependent |
|
138 |
visit.append(n) |
|
139 |
dep = 1 |
|
140 |
break |
|
141 |
||
142 |
if not dep: |
|
143 |
# all n's parents are in the list |
|
144 |
removed[n] = 1 |
|
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
145 |
if n not in self.map: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
146 |
s.append(n) |
316 | 147 |
if n in children: |
148 |
for c in children[n]: |
|
149 |
visit.insert(0, c) |
|
150 |
||
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
151 |
if self.opts.get('datesort'): |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
152 |
depth = {} |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
153 |
for n in s: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
154 |
depth[n] = 0 |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
155 |
pl = [p for p in self.commitcache[n].parents |
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
156 |
if p not in self.map] |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
157 |
if pl: |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
158 |
depth[n] = max([depth[p] for p in pl]) + 1 |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
159 |
|
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
160 |
s = [(depth[n], self.commitcache[n].date, n) for n in s] |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
161 |
s.sort() |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
162 |
s = [e[2] for e in s] |
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
163 |
|
316 | 164 |
return s |
165 |
||
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
166 |
def mapentry(self, src, dst): |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
167 |
if self.revmapfilefd is None: |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
168 |
try: |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
169 |
self.revmapfilefd = open(self.revmapfile, "a") |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
170 |
except IOError, (errno, strerror): |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
171 |
raise util.Abort("Could not open map file %s: %s, %s\n" % (self.revmapfile, errno, strerror)) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
172 |
self.map[src] = dst |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
173 |
self.revmapfilefd.write("%s %s\n" % (src, dst)) |
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
174 |
self.revmapfilefd.flush() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
175 |
|
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
176 |
def writeauthormap(self): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
177 |
authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
178 |
if authorfile: |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
179 |
self.ui.status('Writing author map file %s\n' % authorfile) |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
180 |
ofile = open(authorfile, 'w+') |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
181 |
for author in self.authors: |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
182 |
ofile.write("%s=%s\n" % (author, self.authors[author])) |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
183 |
ofile.close() |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
184 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
185 |
def readauthormap(self, authorfile): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
186 |
afile = open(authorfile, 'r') |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
187 |
for line in afile: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
188 |
try: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
189 |
srcauthor = line.split('=')[0].strip() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
190 |
dstauthor = line.split('=')[1].strip() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
191 |
if srcauthor in self.authors and dstauthor != self.authors[srcauthor]: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
192 |
self.ui.status( |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
193 |
'Overriding mapping for author %s, was %s, will be %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
194 |
% (srcauthor, self.authors[srcauthor], dstauthor)) |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
195 |
else: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
196 |
self.ui.debug('Mapping author %s to %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
197 |
% (srcauthor, dstauthor)) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
198 |
self.authors[srcauthor] = dstauthor |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
199 |
except IndexError: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
200 |
self.ui.warn( |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
201 |
'Ignoring bad line in author file map %s: %s\n' |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
202 |
% (authorfile, line)) |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
203 |
afile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
204 |
|
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
205 |
def cachecommit(self, rev): |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
206 |
commit = self.source.getcommit(rev) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
207 |
commit.author = self.authors.get(commit.author, commit.author) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
208 |
self.commitcache[rev] = commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
209 |
return commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
210 |
|
316 | 211 |
def copy(self, rev): |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
212 |
commit = self.commitcache[rev] |
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
213 |
do_copies = hasattr(self.dest, 'copyfile') |
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
214 |
filenames = [] |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4924
diff
changeset
|
215 |
|
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
216 |
changes = self.source.getchanges(rev) |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
217 |
if isinstance(changes, basestring): |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
218 |
if changes == SKIPREV: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
219 |
dest = SKIPREV |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
220 |
else: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
221 |
dest = self.map[changes] |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
222 |
self.mapentry(rev, dest) |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
223 |
return |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
224 |
files, copies = changes |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
225 |
parents = [self.map[r] for r in commit.parents] |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
226 |
if commit.parents: |
5204
6f636d13f6b8
convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents:
5203
diff
changeset
|
227 |
prev = commit.parents[0] |
6f636d13f6b8
convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents:
5203
diff
changeset
|
228 |
if prev not in self.commitcache: |
6f636d13f6b8
convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents:
5203
diff
changeset
|
229 |
self.cachecommit(prev) |
6f636d13f6b8
convert: load parent commits on-demand
Patrick Mezard <pmezard@gmail.com>
parents:
5203
diff
changeset
|
230 |
pbranch = self.commitcache[prev].branch |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
231 |
else: |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
232 |
pbranch = None |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
233 |
self.dest.setbranch(commit.branch, pbranch, parents) |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5018
diff
changeset
|
234 |
for f, v in files: |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
235 |
filenames.append(f) |
316 | 236 |
try: |
237 |
data = self.source.getfile(f, v) |
|
238 |
except IOError, inst: |
|
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
239 |
self.dest.delfile(f) |
316 | 240 |
else: |
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
241 |
e = self.source.getmode(f, v) |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
242 |
self.dest.putfile(f, e, data) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
243 |
if do_copies: |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5018
diff
changeset
|
244 |
if f in copies: |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
245 |
copyf = copies[f] |
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
246 |
# Merely marks that a copy happened. |
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
247 |
self.dest.copyfile(copyf, f) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
248 |
|
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
249 |
newnode = self.dest.putcommit(filenames, parents, commit) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
250 |
self.mapentry(rev, newnode) |
316 | 251 |
|
252 |
def convert(self): |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
253 |
try: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
254 |
self.source.before() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
255 |
self.dest.before() |
5373
6aba1835a7b3
convert: pass the order of the revmapfile to the converter_source
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5359
diff
changeset
|
256 |
self.source.setrevmap(self.map, self.maporder) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
257 |
self.ui.status("scanning source...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
258 |
heads = self.source.getheads() |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
259 |
parents = self.walktree(heads) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
260 |
self.ui.status("sorting...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
261 |
t = self.toposort(parents) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
262 |
num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
263 |
c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
264 |
|
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
265 |
self.ui.status("converting...\n") |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
266 |
for c in t: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
267 |
num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
268 |
desc = self.commitcache[c].desc |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
269 |
if "\n" in desc: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
270 |
desc = desc.splitlines()[0] |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
271 |
self.ui.status("%d %s\n" % (num, desc)) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
272 |
self.copy(c) |
316 | 273 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
274 |
tags = self.source.gettags() |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
275 |
ctags = {} |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
276 |
for k in tags: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
277 |
v = tags[k] |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
278 |
if self.map.get(v, SKIPREV) != SKIPREV: |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
279 |
ctags[k] = self.map[v] |
316 | 280 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
281 |
if c and ctags: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
282 |
nrev = self.dest.puttags(ctags) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
283 |
# write another hash correspondence to override the previous |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
284 |
# one so we don't end up with extra tag heads |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
285 |
if nrev: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
286 |
self.mapentry(c, nrev) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
287 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
288 |
self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
289 |
finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
290 |
self.cleanup() |
694 | 291 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
292 |
def cleanup(self): |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
293 |
try: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
294 |
self.dest.after() |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
295 |
finally: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
296 |
self.source.after() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
297 |
if self.revmapfilefd: |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
298 |
self.revmapfilefd.close() |
694 | 299 |
|
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
300 |
def convert(ui, src, dest=None, revmapfile=None, **opts): |
4895
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
301 |
util._encoding = 'UTF-8' |
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
302 |
|
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
303 |
if not dest: |
4883
72ac66e88c43
convert: Use clone's behaviour for the default destionation name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4719
diff
changeset
|
304 |
dest = hg.defaultdest(src) + "-hg" |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
305 |
ui.status("assuming destination %s\n" % dest) |
4521
d634b61e9cec
Add some more smart when initializing destination repository
Edouard Gomez <ed.gomez@free.fr>
parents:
4520
diff
changeset
|
306 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
307 |
destc = convertsink(ui, dest, opts.get('dest_type')) |
316 | 308 |
|
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
309 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
310 |
srcc = convertsource(ui, src, opts.get('source_type'), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
311 |
opts.get('rev')) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
312 |
except Exception: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
313 |
for path in destc.created: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
314 |
shutil.rmtree(path, True) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
315 |
raise |
316 | 316 |
|
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
317 |
fmap = opts.get('filemap') |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
318 |
if fmap: |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
319 |
srcc = filemap.filemap_source(ui, srcc, fmap) |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
320 |
destc.setfilemapmode(True) |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
321 |
|
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
322 |
if not revmapfile: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
323 |
try: |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
324 |
revmapfile = destc.revmapfile() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
325 |
except: |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4958
diff
changeset
|
326 |
revmapfile = os.path.join(destc, "map") |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
327 |
|
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
328 |
c = converter(ui, srcc, destc, revmapfile, opts) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
329 |
c.convert() |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
330 |