Mercurial > hg
annotate hgext/convert/convcmd.py @ 8688:31e613a89750
convert: split toposort() into subfunctions for readability
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 01 Jun 2009 17:12:37 +0200 |
parents | e9e2a2c9b294 |
children | 9bc95f8eb018 |
rev | line source |
---|---|
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 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7968
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7968
diff
changeset
|
6 # GNU General Public License version 2, incorporated herein by reference. |
316 | 7 |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6306
diff
changeset
|
8 from common import NoRepo, MissingTool, 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 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7823
diff
changeset
|
13 from subversion import 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 |
7053
209ef5f3534c
convert: add bzr source
Marek Kubica <marek@xivilization.net>
parents:
6976
diff
changeset
|
16 from bzr import bzr_source |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
7599
diff
changeset
|
17 from p4 import p4_source |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
18 import filemap |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
19 |
5376
d60a067227a5
convert: move filemapper class to a separate file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5375
diff
changeset
|
20 import os, shutil |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
21 from mercurial import hg, util, encoding |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
22 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
|
23 |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
24 orig_encoding = 'ascii' |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
25 |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
26 def recode(s): |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
27 if isinstance(s, unicode): |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
28 return s.encode(orig_encoding, 'replace') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
29 else: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
30 return s.decode('utf-8').encode(orig_encoding, 'replace') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
31 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
32 source_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
33 ('cvs', convert_cvs), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
34 ('git', convert_git), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
35 ('svn', svn_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
36 ('hg', mercurial_source), |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
37 ('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
|
38 ('mtn', monotone_source), |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
5996
diff
changeset
|
39 ('gnuarch', gnuarch_source), |
7053
209ef5f3534c
convert: add bzr source
Marek Kubica <marek@xivilization.net>
parents:
6976
diff
changeset
|
40 ('bzr', bzr_source), |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
7599
diff
changeset
|
41 ('p4', p4_source), |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
42 ] |
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 sink_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
45 ('hg', mercurial_sink), |
5513
f0c58fd4b798
convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
46 ('svn', svn_sink), |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
47 ] |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
48 |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
49 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
|
50 exceptions = [] |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
51 for name, source in source_converters: |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
52 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
53 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
|
54 return source(ui, path, rev) |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6306
diff
changeset
|
55 except (NoRepo, MissingTool), 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
|
56 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
|
57 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
|
58 for inst in exceptions: |
6913
580d5e6bfc1f
move % out of translatable strings
Martin Geisler <mg@daimi.au.dk>
parents:
6716
diff
changeset
|
59 ui.write("%s\n" % inst) |
6976
b072266a83d1
convert: document source and sink identifiers, fix error message
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
60 raise util.Abort(_('%s: missing or unsupported repository') % path) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
61 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
62 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
|
63 for name, sink in sink_converters: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
64 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 ui.note(_("convert: %s\n") % inst) |
6913
580d5e6bfc1f
move % out of translatable strings
Martin Geisler <mg@daimi.au.dk>
parents:
6716
diff
changeset
|
69 raise util.Abort(_('%s: unknown repository type') % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
70 |
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
71 class converter(object): |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
72 def __init__(self, ui, source, dest, revmapfile, opts): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
73 |
316 | 74 self.source = source |
75 self.dest = dest | |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
76 self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
77 self.opts = opts |
316 | 78 self.commitcache = {} |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
79 self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
80 self.authorfile = None |
316 | 81 |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
82 # Record converted revisions persistently: maps source revision |
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
83 # ID to target revision ID (both strings). (This is how |
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
84 # incremental conversions work.) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
85 self.map = mapfile(ui, revmapfile) |
316 | 86 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
87 # 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
|
88 authorfile = self.dest.authorfile() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
89 if authorfile and os.path.exists(authorfile): |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
90 self.readauthormap(authorfile) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
91 # 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
|
92 if opts.get('authors'): |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
93 self.readauthormap(opts.get('authors')) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
94 self.authorfile = self.dest.authorfile() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
95 |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
96 self.splicemap = mapfile(ui, opts.get('splicemap')) |
8377
29f4f0d66cd5
convert: adding branchmap functionality to convert extension
Michael J. Pedersen <m.pedersen@icelus.org>
parents:
8225
diff
changeset
|
97 self.branchmap = mapfile(ui, opts.get('branchmap')) |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
98 |
316 | 99 def walktree(self, heads): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
100 '''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
|
101 uncommitted changeset.''' |
316 | 102 visit = heads |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
103 known = set() |
316 | 104 parents = {} |
105 while visit: | |
106 n = visit.pop(0) | |
107 if n in known or n in self.map: continue | |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
108 known.add(n) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
109 commit = self.cachecommit(n) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
110 parents[n] = [] |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
111 for p in commit.parents: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
112 parents[n].append(p) |
316 | 113 visit.append(p) |
114 | |
115 return parents | |
116 | |
117 def toposort(self, parents): | |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
118 '''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
|
119 preceeded by all its uncommitted ancestors.''' |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
120 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
121 def mapchildren(parents): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
122 """Return a (children, roots) tuple where 'children' maps parent |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
123 revision identifiers to children ones, and 'roots' is the list of |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
124 revisions without parents. 'parents' must be a mapping of revision |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
125 identifier to its parents ones. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
126 """ |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
127 visit = parents.keys() |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
128 seen = set() |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
129 children = {} |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
130 roots = [] |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
131 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
132 while visit: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
133 n = visit.pop(0) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
134 if n in seen: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
135 continue |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
136 seen.add(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
137 # Ensure that nodes without parents are present in the |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
138 # 'children' mapping. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
139 children.setdefault(n, []) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
140 hasparent = False |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
141 for p in parents[n]: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
142 if not p in self.map: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
143 visit.append(p) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
144 hasparent = True |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
145 children.setdefault(p, []).append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
146 if not hasparent: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
147 roots.append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
148 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
149 return children, roots |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
150 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
151 # Sort functions are supposed to take a list of revisions which |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
152 # can be converted immediately and pick one |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
153 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
154 def makebranchsorter(): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
155 """If the previously converted revision has a child in the |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
156 eligible revisions list, pick it. Return the list head |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
157 otherwise. Branch sort attempts to minimize branch |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
158 switching, which is harmful for Mercurial backend |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
159 compression. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
160 """ |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
161 prev = [None] |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
162 def picknext(nodes): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
163 next = nodes[0] |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
164 for n in nodes: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
165 if prev[0] in parents[n]: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
166 next = n |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
167 break |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
168 prev[0] = next |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
169 return next |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
170 return picknext |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
171 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
172 def makedatesorter(): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
173 """Sort revisions by date.""" |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
174 dates = {} |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
175 def getdate(n): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
176 if n not in dates: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
177 dates[n] = util.parsedate(self.commitcache[n].date) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
178 return dates[n] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
179 |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
180 def picknext(nodes): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
181 return min([(getdate(n), n) for n in nodes])[1] |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
182 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
183 return picknext |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
184 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
185 if self.opts.get('datesort'): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
186 picknext = makedatesorter() |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
187 else: |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
188 picknext = makebranchsorter() |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
189 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
190 children, actives = mapchildren(parents) |
316 | 191 |
192 s = [] | |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
193 pendings = {} |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
194 while actives: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
195 n = picknext(actives) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
196 actives.remove(n) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
197 s.append(n) |
316 | 198 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
199 # Update dependents list |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
200 for c in children.get(n, []): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
201 if c not in pendings: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
202 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
|
203 try: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
204 pendings[c].remove(n) |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
205 except ValueError: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
206 raise util.Abort(_('cycle detected between %s and %s') |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
207 % (recode(c), recode(n))) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
208 if not pendings[c]: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
209 # Parents are converted, node is eligible |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
210 actives.insert(0, c) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
211 pendings[c] = None |
316 | 212 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
213 if len(s) != len(parents): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
214 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
|
215 |
316 | 216 return s |
217 | |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
218 def writeauthormap(self): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
219 authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
220 if authorfile: |
7877
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
221 self.ui.status(_('Writing author map file %s\n') % authorfile) |
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
222 ofile = open(authorfile, 'w+') |
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
223 for author in self.authors: |
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
224 ofile.write("%s=%s\n" % (author, self.authors[author])) |
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
225 ofile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
226 |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
227 def readauthormap(self, authorfile): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
228 afile = open(authorfile, 'r') |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
229 for line in afile: |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
230 |
7968
43b70a964e0d
convert: handle comments starting with '#' in authormap files
Marti Raudsepp <marti@juffo.org>
parents:
7962
diff
changeset
|
231 line = line.strip() |
43b70a964e0d
convert: handle comments starting with '#' in authormap files
Marti Raudsepp <marti@juffo.org>
parents:
7962
diff
changeset
|
232 if not line or line.startswith('#'): |
6184
9d13e7129423
convert: Ignore empty lines in authormap file.
Marti Raudsepp <marti@juffo.org>
parents:
6143
diff
changeset
|
233 continue |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
234 |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
235 try: |
6186
aae4eb2f40b0
convert: Clean up authormap key=value splitting.
Marti Raudsepp <marti@juffo.org>
parents:
6185
diff
changeset
|
236 srcauthor, dstauthor = line.split('=', 1) |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
237 except ValueError: |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
238 msg = _('Ignoring bad line in author map file %s: %s\n') |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
239 self.ui.warn(msg % (authorfile, line.rstrip())) |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
240 continue |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
241 |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
242 srcauthor = srcauthor.strip() |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
243 dstauthor = dstauthor.strip() |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
244 if self.authors.get(srcauthor) in (None, dstauthor): |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
245 msg = _('mapping author %s to %s\n') |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
246 self.ui.debug(msg % (srcauthor, dstauthor)) |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
247 self.authors[srcauthor] = dstauthor |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
248 continue |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
249 |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
250 m = _('overriding mapping for author %s, was %s, will be %s\n') |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
251 self.ui.status(m % (srcauthor, self.authors[srcauthor], dstauthor)) |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
252 |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
253 afile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
254 |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
255 def cachecommit(self, rev): |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
256 commit = self.source.getcommit(rev) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
257 commit.author = self.authors.get(commit.author, commit.author) |
8377
29f4f0d66cd5
convert: adding branchmap functionality to convert extension
Michael J. Pedersen <m.pedersen@icelus.org>
parents:
8225
diff
changeset
|
258 commit.branch = self.branchmap.get(commit.branch, commit.branch) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
259 self.commitcache[rev] = commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
260 return commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
261 |
316 | 262 def copy(self, rev): |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
263 commit = self.commitcache[rev] |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4924
diff
changeset
|
264 |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 else: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
270 dest = self.map[changes] |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
271 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
|
272 return |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
273 files, copies = changes |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
274 pbranches = [] |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
275 if commit.parents: |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
276 for prev in commit.parents: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
277 if prev not in self.commitcache: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
278 self.cachecommit(prev) |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6186
diff
changeset
|
279 pbranches.append((self.map[prev], |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
280 self.commitcache[prev].branch)) |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
281 self.dest.setbranch(commit.branch, pbranches) |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
282 try: |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
283 parents = self.splicemap[rev].replace(',', ' ').split() |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
284 self.ui.status(_('spliced in %s as parents of %s\n') % |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
285 (parents, rev)) |
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
286 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
|
287 except KeyError: |
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
288 parents = [b[0] for b in pbranches] |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
289 newnode = self.dest.putcommit(files, copies, parents, commit, self.source) |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5528
diff
changeset
|
290 self.source.converted(rev, newnode) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
291 self.map[rev] = newnode |
316 | 292 |
293 def convert(self): | |
5954
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
294 |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
295 try: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
296 self.source.before() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
297 self.dest.before() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
298 self.source.setrevmap(self.map) |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
299 self.ui.status(_("scanning source...\n")) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
300 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
|
301 parents = self.walktree(heads) |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
302 self.ui.status(_("sorting...\n")) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
303 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
|
304 num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
305 c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
306 |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
307 self.ui.status(_("converting...\n")) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
308 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
|
309 num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 # convert log message to local encoding without using |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
314 # tolocal() because encoding.encoding conver() use it as |
5794
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
315 # 'utf-8' |
5954
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
316 self.ui.status("%d %s\n" % (num, recode(desc))) |
6913
580d5e6bfc1f
move % out of translatable strings
Martin Geisler <mg@daimi.au.dk>
parents:
6716
diff
changeset
|
317 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
|
318 self.copy(c) |
316 | 319 |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
320 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
|
321 ctags = {} |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 ctags[k] = self.map[v] |
316 | 326 |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
327 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
|
328 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
|
329 # 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
|
330 # 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
|
331 if nrev: |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
332 self.map[c] = nrev |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
333 |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
334 self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
335 finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
336 self.cleanup() |
694 | 337 |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
338 def cleanup(self): |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
339 try: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
340 self.dest.after() |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
341 finally: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
342 self.source.after() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
343 self.map.close() |
694 | 344 |
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
345 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
|
346 global orig_encoding |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
347 orig_encoding = encoding.encoding |
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
348 encoding.encoding = 'UTF-8' |
4895
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
349 |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
350 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
|
351 dest = hg.defaultdest(src) + "-hg" |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
352 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
|
353 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
354 destc = convertsink(ui, dest, opts.get('dest_type')) |
316 | 355 |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
356 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
357 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
|
358 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
|
359 except Exception: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
360 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
|
361 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
|
362 raise |
316 | 363 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
364 fmap = opts.get('filemap') |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
365 if fmap: |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
366 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
|
367 destc.setfilemapmode(True) |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
368 |
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
|
369 if not revmapfile: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
370 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
|
371 revmapfile = destc.revmapfile() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
372 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
|
373 revmapfile = os.path.join(destc, "map") |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
374 |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
375 c = converter(ui, srcc, destc, revmapfile, opts) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
376 c.convert() |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
377 |