author | Mikkel Fahnøe Jørgensen <mikkel@dvide.com> |
Sat, 02 Feb 2008 19:14:59 +0100 | |
changeset 6306 | 2f9de4aaea9e |
parent 6212 | e75aab656f46 |
child 6332 | 950e72fc7cf3 |
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 |
|
6212 | 8 |
from common import NoRepo, SKIPREV, mapfile |
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 |
5513
f0c58fd4b798
convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
13 |
from subversion import debugsvnlog, svn_source, svn_sink |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6212
diff
changeset
|
14 |
from monotone import monotone_source |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
5996
diff
changeset
|
15 |
from gnuarch import gnuarch_source |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
16 |
import filemap |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
17 |
|
5376
d60a067227a5
convert: move filemapper class to a separate file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5375
diff
changeset
|
18 |
import os, shutil |
5621
badbefa55972
convert: move commands definition to ease demandload job (issue 860)
Patrick Mezard <pmezard@gmail.com>
parents:
5521
diff
changeset
|
19 |
from mercurial import hg, util |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
20 |
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
|
21 |
|
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
22 |
orig_encoding = 'ascii' |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
23 |
|
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
24 |
def recode(s): |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
25 |
if isinstance(s, unicode): |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
26 |
return s.encode(orig_encoding, 'replace') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
27 |
else: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
28 |
return s.decode('utf-8').encode(orig_encoding, 'replace') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
29 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
30 |
source_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
31 |
('cvs', convert_cvs), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
32 |
('git', convert_git), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
33 |
('svn', svn_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
34 |
('hg', mercurial_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
35 |
('darcs', darcs_source), |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6212
diff
changeset
|
36 |
('mtn', monotone_source), |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
5996
diff
changeset
|
37 |
('gnuarch', gnuarch_source), |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
38 |
] |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
39 |
|
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
40 |
sink_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
41 |
('hg', mercurial_sink), |
5513
f0c58fd4b798
convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
42 |
('svn', svn_sink), |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
43 |
] |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
44 |
|
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
45 |
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
|
46 |
exceptions = [] |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
47 |
for name, source in source_converters: |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
48 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
ui.write(_("%s\n") % inst) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
56 |
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
|
57 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
58 |
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
|
59 |
for name, sink in sink_converters: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
60 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
ui.note(_("convert: %s\n") % inst) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
65 |
raise util.Abort('%s: unknown repository type' % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
66 |
|
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
67 |
class converter(object): |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
68 |
def __init__(self, ui, source, dest, revmapfile, opts): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
69 |
|
316 | 70 |
self.source = source |
71 |
self.dest = dest |
|
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
72 |
self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
73 |
self.opts = opts |
316 | 74 |
self.commitcache = {} |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
75 |
self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
76 |
self.authorfile = None |
316 | 77 |
|
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
78 |
self.map = mapfile(ui, revmapfile) |
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 |
|
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
89 |
self.splicemap = mapfile(ui, opts.get('splicemap')) |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
90 |
|
316 | 91 |
def walktree(self, heads): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
92 |
'''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
|
93 |
uncommitted changeset.''' |
316 | 94 |
visit = heads |
95 |
known = {} |
|
96 |
parents = {} |
|
97 |
while visit: |
|
98 |
n = visit.pop(0) |
|
99 |
if n in known or n in self.map: continue |
|
100 |
known[n] = 1 |
|
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
101 |
commit = self.cachecommit(n) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
102 |
parents[n] = [] |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
103 |
for p in commit.parents: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
104 |
parents[n].append(p) |
316 | 105 |
visit.append(p) |
106 |
||
107 |
return parents |
|
108 |
||
109 |
def toposort(self, parents): |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
110 |
'''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
|
111 |
preceeded by all its uncommitted ancestors.''' |
316 | 112 |
visit = parents.keys() |
113 |
seen = {} |
|
114 |
children = {} |
|
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
115 |
actives = [] |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
116 |
|
316 | 117 |
while visit: |
118 |
n = visit.pop(0) |
|
119 |
if n in seen: continue |
|
120 |
seen[n] = 1 |
|
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
121 |
# 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
|
122 |
# mapping. |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
123 |
children.setdefault(n, []) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
124 |
hasparent = False |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
125 |
for p in parents[n]: |
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
126 |
if not p in self.map: |
316 | 127 |
visit.append(p) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
128 |
hasparent = True |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
129 |
children.setdefault(p, []).append(n) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
130 |
if not hasparent: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
131 |
actives.append(n) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
132 |
|
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
133 |
del seen |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
134 |
del visit |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
135 |
|
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
136 |
if self.opts.get('datesort'): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
137 |
dates = {} |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
138 |
def getdate(n): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
139 |
if n not in dates: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
140 |
dates[n] = util.parsedate(self.commitcache[n].date) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
141 |
return dates[n] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
142 |
|
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
143 |
def picknext(nodes): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
144 |
return min([(getdate(n), n) for n in nodes])[1] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
145 |
else: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
146 |
prev = [None] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
147 |
def picknext(nodes): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
148 |
# Return the first eligible child of the previously converted |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
149 |
# revision, or any of them. |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
150 |
next = nodes[0] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
151 |
for n in nodes: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
152 |
if prev[0] in parents[n]: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
153 |
next = n |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
154 |
break |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
155 |
prev[0] = next |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
156 |
return next |
316 | 157 |
|
158 |
s = [] |
|
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
159 |
pendings = {} |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
160 |
while actives: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
161 |
n = picknext(actives) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
162 |
actives.remove(n) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
163 |
s.append(n) |
316 | 164 |
|
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
165 |
# Update dependents list |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
166 |
for c in children.get(n, []): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
167 |
if c not in pendings: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
168 |
pendings[c] = [p for p in parents[c] if p not in self.map] |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
169 |
try: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
170 |
pendings[c].remove(n) |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
171 |
except ValueError: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
172 |
raise util.Abort(_('cycle detected between %s and %s') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
173 |
% (recode(c), recode(n))) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
174 |
if not pendings[c]: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
175 |
# Parents are converted, node is eligible |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
176 |
actives.insert(0, c) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
177 |
pendings[c] = None |
316 | 178 |
|
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
179 |
if len(s) != len(parents): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
180 |
raise util.Abort(_("not all revisions were sorted")) |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
181 |
|
316 | 182 |
return s |
183 |
||
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
184 |
def writeauthormap(self): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
185 |
authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
186 |
if authorfile: |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
187 |
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
|
188 |
ofile = open(authorfile, 'w+') |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
189 |
for author in self.authors: |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
190 |
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
|
191 |
ofile.close() |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
192 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
193 |
def readauthormap(self, authorfile): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
194 |
afile = open(authorfile, 'r') |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
195 |
for line in afile: |
6184
9d13e7129423
convert: Ignore empty lines in authormap file.
Marti Raudsepp <marti@juffo.org>
parents:
6143
diff
changeset
|
196 |
if line.strip() == '': |
9d13e7129423
convert: Ignore empty lines in authormap file.
Marti Raudsepp <marti@juffo.org>
parents:
6143
diff
changeset
|
197 |
continue |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
198 |
try: |
6186
aae4eb2f40b0
convert: Clean up authormap key=value splitting.
Marti Raudsepp <marti@juffo.org>
parents:
6185
diff
changeset
|
199 |
srcauthor, dstauthor = line.split('=', 1) |
aae4eb2f40b0
convert: Clean up authormap key=value splitting.
Marti Raudsepp <marti@juffo.org>
parents:
6185
diff
changeset
|
200 |
srcauthor = srcauthor.strip() |
aae4eb2f40b0
convert: Clean up authormap key=value splitting.
Marti Raudsepp <marti@juffo.org>
parents:
6185
diff
changeset
|
201 |
dstauthor = dstauthor.strip() |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
202 |
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
|
203 |
self.ui.status( |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
204 |
'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
|
205 |
% (srcauthor, self.authors[srcauthor], dstauthor)) |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
206 |
else: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
207 |
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
|
208 |
% (srcauthor, dstauthor)) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
209 |
self.authors[srcauthor] = dstauthor |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
210 |
except IndexError: |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
211 |
self.ui.warn( |
6185
c48d778d7c23
convert: Avoid redundant newline on authormap errors.
Marti Raudsepp <marti@juffo.org>
parents:
6184
diff
changeset
|
212 |
'Ignoring bad line in author map file %s: %s\n' |
c48d778d7c23
convert: Avoid redundant newline on authormap errors.
Marti Raudsepp <marti@juffo.org>
parents:
6184
diff
changeset
|
213 |
% (authorfile, line.rstrip())) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
214 |
afile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
215 |
|
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
216 |
def cachecommit(self, rev): |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
217 |
commit = self.source.getcommit(rev) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
218 |
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
|
219 |
self.commitcache[rev] = commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
220 |
return commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
221 |
|
316 | 222 |
def copy(self, rev): |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
223 |
commit = self.commitcache[rev] |
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
224 |
do_copies = hasattr(self.dest, 'copyfile') |
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
225 |
filenames = [] |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4924
diff
changeset
|
226 |
|
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
else: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
232 |
dest = self.map[changes] |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
233 |
self.map[rev] = dest |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
234 |
return |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
235 |
files, copies = changes |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
236 |
pbranches = [] |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
237 |
if commit.parents: |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
238 |
for prev in commit.parents: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
239 |
if prev not in self.commitcache: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
240 |
self.cachecommit(prev) |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6186
diff
changeset
|
241 |
pbranches.append((self.map[prev], |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
242 |
self.commitcache[prev].branch)) |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
243 |
self.dest.setbranch(commit.branch, pbranches) |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5018
diff
changeset
|
244 |
for f, v in files: |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
245 |
filenames.append(f) |
316 | 246 |
try: |
247 |
data = self.source.getfile(f, v) |
|
248 |
except IOError, inst: |
|
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
249 |
self.dest.delfile(f) |
316 | 250 |
else: |
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
251 |
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
|
252 |
self.dest.putfile(f, e, data) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
253 |
if do_copies: |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5018
diff
changeset
|
254 |
if f in copies: |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
255 |
copyf = copies[f] |
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
256 |
# Merely marks that a copy happened. |
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
257 |
self.dest.copyfile(copyf, f) |
4765
b6a1f2c46c6c
convert extension: Add SVN converter
Daniel Holth <dholth@fastmail.fm>
parents:
4763
diff
changeset
|
258 |
|
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
259 |
try: |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
260 |
parents = self.splicemap[rev].replace(',', ' ').split() |
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
261 |
self.ui.status('spliced in %s as parents of %s\n' % |
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
262 |
(parents, rev)) |
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
263 |
parents = [self.map.get(p, p) for p in parents] |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
264 |
except KeyError: |
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
265 |
parents = [b[0] for b in pbranches] |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
266 |
newnode = self.dest.putcommit(filenames, parents, commit) |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5528
diff
changeset
|
267 |
self.source.converted(rev, newnode) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
268 |
self.map[rev] = newnode |
316 | 269 |
|
270 |
def convert(self): |
|
5954
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
271 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
272 |
try: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
273 |
self.source.before() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
274 |
self.dest.before() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
275 |
self.source.setrevmap(self.map) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
282 |
c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
283 |
|
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
desc = desc.splitlines()[0] |
5794
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
290 |
# convert log message to local encoding without using |
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
291 |
# tolocal() because util._encoding conver() use it as |
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
292 |
# 'utf-8' |
5954
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
293 |
self.ui.status("%d %s\n" % (num, recode(desc))) |
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
294 |
self.ui.note(_("source: %s\n" % recode(c))) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
295 |
self.copy(c) |
316 | 296 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
297 |
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
|
298 |
ctags = {} |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
ctags[k] = self.map[v] |
316 | 303 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
# 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
|
307 |
# 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
|
308 |
if nrev: |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
309 |
self.map[c] = nrev |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
310 |
|
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
311 |
self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
312 |
finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
313 |
self.cleanup() |
694 | 314 |
|
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
315 |
def cleanup(self): |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
316 |
try: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
317 |
self.dest.after() |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
318 |
finally: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
319 |
self.source.after() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
320 |
self.map.close() |
694 | 321 |
|
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
322 |
def convert(ui, src, dest=None, revmapfile=None, **opts): |
5794
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
323 |
global orig_encoding |
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
324 |
orig_encoding = util._encoding |
4895
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
325 |
util._encoding = 'UTF-8' |
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
326 |
|
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
327 |
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
|
328 |
dest = hg.defaultdest(src) + "-hg" |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
329 |
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
|
330 |
|
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
331 |
destc = convertsink(ui, dest, opts.get('dest_type')) |
316 | 332 |
|
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
333 |
try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
except Exception: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
raise |
316 | 340 |
|
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
341 |
fmap = opts.get('filemap') |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
342 |
if fmap: |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
343 |
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
|
344 |
destc.setfilemapmode(True) |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
345 |
|
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
|
346 |
if not revmapfile: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
347 |
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
|
348 |
revmapfile = destc.revmapfile() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
349 |
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
|
350 |
revmapfile = os.path.join(destc, "map") |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
351 |
|
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
352 |
c = converter(ui, srcc, destc, revmapfile, opts) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
353 |
c.convert() |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
354 |