Mercurial > hg
annotate hgext/convert/convcmd.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 26761665bdfe |
children | 687b865b95ad |
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 |
10263 | 6 # GNU General Public License version 2 or any later version. |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
7 from __future__ import absolute_import |
316 | 8 |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35197
diff
changeset
|
9 import collections |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
10 import os |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
11 import shutil |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
12 |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28900
diff
changeset
|
13 from mercurial.i18n import _ |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
14 from mercurial import ( |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
15 encoding, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
16 error, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
17 hg, |
36133
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36132
diff
changeset
|
18 pycompat, |
35177
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35176
diff
changeset
|
19 scmutil, |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
20 util, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
21 ) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36558
diff
changeset
|
22 from mercurial.utils import dateutil |
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
23 |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
24 from . import ( |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
25 bzr, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
26 common, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
27 cvs, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
28 darcs, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
29 filemap, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
30 git, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
31 gnuarch, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
32 hg as hgconvert, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
33 monotone, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
34 p4, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
35 subversion, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
36 ) |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
37 |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
38 mapfile = common.mapfile |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
39 MissingTool = common.MissingTool |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
40 NoRepo = common.NoRepo |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
41 SKIPREV = common.SKIPREV |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
42 |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
43 bzr_source = bzr.bzr_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
44 convert_cvs = cvs.convert_cvs |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
45 convert_git = git.convert_git |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
46 darcs_source = darcs.darcs_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
47 gnuarch_source = gnuarch.gnuarch_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
48 mercurial_sink = hgconvert.mercurial_sink |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
49 mercurial_source = hgconvert.mercurial_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
50 monotone_source = monotone.monotone_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
51 p4_source = p4.p4_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
52 svn_sink = subversion.svn_sink |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
53 svn_source = subversion.svn_source |
3821
158fce02dc40
Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents:
2657
diff
changeset
|
54 |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
55 orig_encoding = 'ascii' |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
56 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
57 |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
58 def recode(s): |
38312
79dd61a4554f
py3: replace `unicode` with pycompat.unicode
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37888
diff
changeset
|
59 if isinstance(s, pycompat.unicode): |
36133
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36132
diff
changeset
|
60 return s.encode(pycompat.sysstr(orig_encoding), 'replace') |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
61 else: |
36133
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36132
diff
changeset
|
62 return s.decode('utf-8').encode( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
63 pycompat.sysstr(orig_encoding), 'replace' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
64 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
65 |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
66 |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
67 def mapbranch(branch, branchmap): |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
68 ''' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
69 >>> bmap = {b'default': b'branch1'} |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
70 >>> for i in [b'', None]: |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
71 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
72 'branch1' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
73 'branch1' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
74 >>> bmap = {b'None': b'branch2'} |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
75 >>> for i in [b'', None]: |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
76 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
77 'branch2' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
78 'branch2' |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
79 >>> bmap = {b'None': b'branch3', b'default': b'branch4'} |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30400
diff
changeset
|
80 >>> for i in [b'None', b'', None, b'default', b'branch5']: |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
81 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
82 'branch3' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
83 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
84 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
85 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
86 'branch5' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
87 ''' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
88 # If branch is None or empty, this commit is coming from the source |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
89 # repository's default branch and destined for the default branch in the |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
90 # destination repository. For such commits, using a literal "default" |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
91 # in branchmap below allows the user to map "default" to an alternate |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
92 # default branch in the destination repository. |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
93 branch = branchmap.get(branch or 'default', branch) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
94 # At some point we used "None" literal to denote the default branch, |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
95 # attempt to use that for backward compatibility. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
96 if not branch: |
34359
ee10eb665036
py3: replace str(None) with literal in convcmd.py
Yuya Nishihara <yuya@tcha.org>
parents:
34131
diff
changeset
|
97 branch = branchmap.get('None', branch) |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
98 return branch |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
99 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
100 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
101 source_converters = [ |
8692
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
102 ('cvs', convert_cvs, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
103 ('git', convert_git, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
104 ('svn', svn_source, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
105 ('hg', mercurial_source, 'sourcesort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
106 ('darcs', darcs_source, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
107 ('mtn', monotone_source, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
108 ('gnuarch', gnuarch_source, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
109 ('bzr', bzr_source, 'branchsort'), |
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
110 ('p4', p4_source, 'branchsort'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
111 ] |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
112 |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
113 sink_converters = [ |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
114 ('hg', mercurial_sink), |
5513
f0c58fd4b798
convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
115 ('svn', svn_sink), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
116 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
117 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
118 |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25741
diff
changeset
|
119 def convertsource(ui, path, type, revs): |
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
|
120 exceptions = [] |
9962
a7178eccf2dc
convert: better error on invalid repository type
Patrick Mezard <pmezard@gmail.com>
parents:
9431
diff
changeset
|
121 if type and type not in [s[0] for s in source_converters]: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
122 raise error.Abort(_('%s: invalid source repository type') % type) |
8692
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
123 for name, source, sortmode in source_converters: |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
124 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
125 if not type or name == type: |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34359
diff
changeset
|
126 return source(ui, name, path, revs), sortmode |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
127 except (NoRepo, MissingTool) as 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
|
128 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
|
129 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
|
130 for inst in exceptions: |
41418
26761665bdfe
convert: print exception message directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38406
diff
changeset
|
131 ui.write("%s\n" % pycompat.bytestr(inst.args[0])) |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
132 raise error.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
|
133 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
134 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
135 def convertsink(ui, path, type): |
9962
a7178eccf2dc
convert: better error on invalid repository type
Patrick Mezard <pmezard@gmail.com>
parents:
9431
diff
changeset
|
136 if type and type not in [s[0] for s in sink_converters]: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
137 raise error.Abort(_('%s: invalid destination repository type') % type) |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
138 for name, sink in sink_converters: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
139 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
140 if not type or name == type: |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34359
diff
changeset
|
141 return sink(ui, name, path) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
142 except NoRepo as inst: |
5415
1d53a75ea0fc
convert: do not output when trying to load svn bindings
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
5414
diff
changeset
|
143 ui.note(_("convert: %s\n") % inst) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
144 except MissingTool as inst: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
145 raise error.Abort('%s\n' % inst) |
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
146 raise error.Abort(_('%s: unknown repository type') % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
147 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
148 |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
149 class progresssource(object): |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
150 def __init__(self, ui, source, filecount): |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
151 self.ui = ui |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
152 self.source = source |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
153 self.progress = ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
154 _('getting files'), unit=_('files'), total=filecount |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
155 ) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
156 |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
157 def getfile(self, file, rev): |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
158 self.progress.increment(item=file) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
159 return self.source.getfile(file, rev) |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
160 |
26035
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25805
diff
changeset
|
161 def targetfilebelongstosource(self, targetfilename): |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25805
diff
changeset
|
162 return self.source.targetfilebelongstosource(targetfilename) |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25805
diff
changeset
|
163 |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
164 def lookuprev(self, rev): |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
165 return self.source.lookuprev(rev) |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
166 |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
167 def close(self): |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
168 self.progress.complete() |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
169 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
170 |
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
171 class converter(object): |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
172 def __init__(self, ui, source, dest, revmapfile, opts): |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
173 |
316 | 174 self.source = source |
175 self.dest = dest | |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
176 self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
177 self.opts = opts |
316 | 178 self.commitcache = {} |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
179 self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
180 self.authorfile = None |
316 | 181 |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
182 # Record converted revisions persistently: maps source revision |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8693
diff
changeset
|
183 # ID to target revision ID (both strings). (This is how |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
184 # incremental conversions work.) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
185 self.map = mapfile(ui, revmapfile) |
316 | 186 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
187 # 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
|
188 authorfile = self.dest.authorfile() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
189 if authorfile and os.path.exists(authorfile): |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
190 self.readauthormap(authorfile) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
191 # Extend/Override with new author map if necessary |
12198
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
192 if opts.get('authormap'): |
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
193 self.readauthormap(opts.get('authormap')) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
194 self.authorfile = self.dest.authorfile() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
195 |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
196 self.splicemap = self.parsesplicemap(opts.get('splicemap')) |
8377
29f4f0d66cd5
convert: adding branchmap functionality to convert extension
Michael J. Pedersen <m.pedersen@icelus.org>
parents:
8225
diff
changeset
|
197 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
|
198 |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
199 def parsesplicemap(self, path): |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
200 """ check and validate the splicemap format and |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
201 return a child/parents dictionary. |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
202 Format checking has two parts. |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
203 1. generic format which is same across all source types |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
204 2. specific format checking which may be different for |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
205 different source type. This logic is implemented in |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
206 checkrevformat function in source files like |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
207 hg.py, subversion.py etc. |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
208 """ |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
209 |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
210 if not path: |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
211 return {} |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
212 m = {} |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
213 try: |
36132
42a393ea56d2
convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents:
35779
diff
changeset
|
214 fp = open(path, 'rb') |
30400 | 215 for i, line in enumerate(util.iterfile(fp)): |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
216 line = line.splitlines()[0].rstrip() |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
217 if not line: |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
218 # Ignore blank lines |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
219 continue |
19181
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
220 # split line |
36558
d4c98b6724e1
convcmd: use our shlex wrapper to avoid Python 3 tracebacks
Augie Fackler <augie@google.com>
parents:
36329
diff
changeset
|
221 lex = common.shlexer(data=line, whitespace=',') |
19181
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
222 line = list(lex) |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
223 # check number of parents |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
224 if not (2 <= len(line) <= 3): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
225 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
226 _( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
227 'syntax error in %s(%d): child parent1' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
228 '[,parent2] expected' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
229 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
230 % (path, i + 1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
231 ) |
19181
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
232 for part in line: |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
233 self.source.checkrevformat(part) |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
234 child, p1, p2 = line[0], line[1:2], line[2:] |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
235 if p1 == p2: |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
236 m[child] = p1 |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
237 else: |
8c2fdf7d5645
splicemap: support paths with spaces in splicemap (issue3844)
Szymon Wroblewski <bluex0@gmail.com>
parents:
19120
diff
changeset
|
238 m[child] = p1 + p2 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
239 # if file does not exist or error reading, exit |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
240 except IOError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
241 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
242 _('splicemap file not found or error reading %s:') % path |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
243 ) |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
244 return m |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
245 |
316 | 246 def walktree(self, heads): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
247 '''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
|
248 uncommitted changeset.''' |
37888
73ca1c5e65f8
convcmd: make a copy of heads before mutating it
Augie Fackler <augie@google.com>
parents:
36607
diff
changeset
|
249 visit = list(heads) |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
250 known = set() |
316 | 251 parents = {} |
22411
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
252 numcommits = self.source.numcommits() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
253 progress = self.ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
254 _('scanning'), unit=_('revisions'), total=numcommits |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
255 ) |
316 | 256 while visit: |
257 n = visit.pop(0) | |
21636
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
258 if n in known: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
259 continue |
21636
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
260 if n in self.map: |
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
261 m = self.map[n] |
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
262 if m == SKIPREV or self.dest.hascommitfrommap(m): |
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
263 continue |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
264 known.add(n) |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
265 progress.update(len(known)) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
266 commit = self.cachecommit(n) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
267 parents[n] = [] |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
268 for p in commit.parents: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
269 parents[n].append(p) |
316 | 270 visit.append(p) |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
271 progress.complete() |
316 | 272 |
273 return parents | |
274 | |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
275 def mergesplicemap(self, parents, splicemap): |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
276 """A splicemap redefines child/parent relationships. Check the |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
277 map contains valid revision identifiers and merge the new |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
278 links in the source graph. |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
279 """ |
18372
5965997b7023
convert: process splicemap in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
17424
diff
changeset
|
280 for c in sorted(splicemap): |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
281 if c not in parents: |
21634
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21077
diff
changeset
|
282 if not self.dest.hascommitforsplicemap(self.map.get(c, c)): |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
283 # Could be in source but not converted during this run |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
284 self.ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
285 _( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
286 'splice map revision %s is not being ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
287 'converted, ignoring\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
288 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
289 % c |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
290 ) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
291 continue |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
292 pc = [] |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
293 for p in splicemap[c]: |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
294 # We do not have to wait for nodes already in dest. |
21634
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21077
diff
changeset
|
295 if self.dest.hascommitforsplicemap(self.map.get(p, p)): |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
296 continue |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
297 # Parent is not in dest and not being converted, not good |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
298 if p not in parents: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
299 raise error.Abort(_('unknown splice map parent: %s') % p) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
300 pc.append(p) |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
301 parents[c] = pc |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
302 |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
303 def toposort(self, parents, sortmode): |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
304 '''Return an ordering such that every uncommitted changeset is |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16925
diff
changeset
|
305 preceded by all its uncommitted ancestors.''' |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
306 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
307 def mapchildren(parents): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
308 """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
|
309 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
|
310 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
|
311 identifier to its parents ones. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
312 """ |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35197
diff
changeset
|
313 visit = collections.deque(sorted(parents)) |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
314 seen = set() |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
315 children = {} |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
316 roots = [] |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
317 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
318 while visit: |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35197
diff
changeset
|
319 n = visit.popleft() |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
320 if n in seen: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
321 continue |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
322 seen.add(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
323 # 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
|
324 # 'children' mapping. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
325 children.setdefault(n, []) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
326 hasparent = False |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
327 for p in parents[n]: |
16686
67964cda8701
cleanup: "not x in y" -> "x not in y"
Brodie Rao <brodie@sf.io>
parents:
16106
diff
changeset
|
328 if p not in self.map: |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
329 visit.append(p) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
330 hasparent = True |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
331 children.setdefault(p, []).append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
332 if not hasparent: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
333 roots.append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
334 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
335 return children, roots |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
336 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
337 # 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
|
338 # can be converted immediately and pick one |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
339 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
340 def makebranchsorter(): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
341 """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
|
342 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
|
343 otherwise. Branch sort attempts to minimize branch |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
344 switching, which is harmful for Mercurial backend |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
345 compression. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
346 """ |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
347 prev = [None] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
348 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
349 def picknext(nodes): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
350 next = nodes[0] |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
351 for n in nodes: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
352 if prev[0] in parents[n]: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
353 next = n |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
354 break |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
355 prev[0] = next |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
356 return next |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
357 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
358 return picknext |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
359 |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
360 def makesourcesorter(): |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
361 """Source specific sort.""" |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
362 keyfn = lambda n: self.commitcache[n].sortkey |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
363 |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
364 def picknext(nodes): |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
365 return sorted(nodes, key=keyfn)[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
366 |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
367 return picknext |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
368 |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
369 def makeclosesorter(): |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
370 """Close order sort.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
371 keyfn = lambda n: ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
372 'close' not in self.commitcache[n].extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
373 self.commitcache[n].sortkey, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
374 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
375 |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
376 def picknext(nodes): |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
377 return sorted(nodes, key=keyfn)[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
378 |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
379 return picknext |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
380 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
381 def makedatesorter(): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
382 """Sort revisions by date.""" |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
383 dates = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
384 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
385 def getdate(n): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
386 if n not in dates: |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36558
diff
changeset
|
387 dates[n] = dateutil.parsedate(self.commitcache[n].date) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
388 return dates[n] |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
389 |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
390 def picknext(nodes): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
391 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
|
392 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
393 return picknext |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
394 |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
395 if sortmode == 'branchsort': |
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
396 picknext = makebranchsorter() |
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
397 elif sortmode == 'datesort': |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
398 picknext = makedatesorter() |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
399 elif sortmode == 'sourcesort': |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
400 picknext = makesourcesorter() |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
401 elif sortmode == 'closesort': |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
402 picknext = makeclosesorter() |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
403 else: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
404 raise error.Abort(_('unknown sort mode: %s') % sortmode) |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
405 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
406 children, actives = mapchildren(parents) |
316 | 407 |
408 s = [] | |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
409 pendings = {} |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
410 while actives: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
411 n = picknext(actives) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
412 actives.remove(n) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
413 s.append(n) |
316 | 414 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
415 # Update dependents list |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
416 for c in children.get(n, []): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
417 if c not in pendings: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
418 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
|
419 try: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
420 pendings[c].remove(n) |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
421 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
422 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
423 _('cycle detected between %s and %s') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
424 % (recode(c), recode(n)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
425 ) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
426 if not pendings[c]: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
427 # Parents are converted, node is eligible |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
428 actives.insert(0, c) |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
429 pendings[c] = None |
316 | 430 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
431 if len(s) != len(parents): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
432 raise error.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
|
433 |
316 | 434 return s |
435 | |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
436 def writeauthormap(self): |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
437 authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
438 if authorfile: |
16925
eaf6a6d7f015
convert: lowercase status and abort messages
Martin Geisler <mg@aragost.com>
parents:
16689
diff
changeset
|
439 self.ui.status(_('writing author map file %s\n') % authorfile) |
36132
42a393ea56d2
convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents:
35779
diff
changeset
|
440 ofile = open(authorfile, 'wb+') |
7877
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
441 for author in self.authors: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
442 ofile.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
443 util.tonativeeol("%s=%s\n" % (author, self.authors[author])) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
444 ) |
7877
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7873
diff
changeset
|
445 ofile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
446 |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
447 def readauthormap(self, authorfile): |
36132
42a393ea56d2
convert: open all files in binary mode
Augie Fackler <augie@google.com>
parents:
35779
diff
changeset
|
448 afile = open(authorfile, 'rb') |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
449 for line in afile: |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
450 |
7968
43b70a964e0d
convert: handle comments starting with '#' in authormap files
Marti Raudsepp <marti@juffo.org>
parents:
7962
diff
changeset
|
451 line = line.strip() |
43b70a964e0d
convert: handle comments starting with '#' in authormap files
Marti Raudsepp <marti@juffo.org>
parents:
7962
diff
changeset
|
452 if not line or line.startswith('#'): |
6184
9d13e7129423
convert: Ignore empty lines in authormap file.
Marti Raudsepp <marti@juffo.org>
parents:
6143
diff
changeset
|
453 continue |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
454 |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
455 try: |
6186
aae4eb2f40b0
convert: Clean up authormap key=value splitting.
Marti Raudsepp <marti@juffo.org>
parents:
6185
diff
changeset
|
456 srcauthor, dstauthor = line.split('=', 1) |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
457 except ValueError: |
16925
eaf6a6d7f015
convert: lowercase status and abort messages
Martin Geisler <mg@aragost.com>
parents:
16689
diff
changeset
|
458 msg = _('ignoring bad line in author map file %s: %s\n') |
7962
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
459 self.ui.warn(msg % (authorfile, line.rstrip())) |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
460 continue |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
461 |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
462 srcauthor = srcauthor.strip() |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
463 dstauthor = dstauthor.strip() |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
464 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
|
465 msg = _('mapping author %s to %s\n') |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
466 self.ui.debug(msg % (srcauthor, dstauthor)) |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
467 self.authors[srcauthor] = dstauthor |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
468 continue |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
469 |
62154415821f
convert: fix authormap handling of lines without '='
Marti Raudsepp <marti@juffo.org>
parents:
7948
diff
changeset
|
470 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
|
471 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
|
472 |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
473 afile.close() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
474 |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
475 def cachecommit(self, rev): |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
476 commit = self.source.getcommit(rev) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
477 commit.author = self.authors.get(commit.author, commit.author) |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
478 commit.branch = mapbranch(commit.branch, self.branchmap) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
479 self.commitcache[rev] = commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
480 return commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
481 |
316 | 482 def copy(self, rev): |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
483 commit = self.commitcache[rev] |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
21636
diff
changeset
|
484 full = self.opts.get('full') |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
21636
diff
changeset
|
485 changes = self.source.getchanges(rev, full) |
35197
bfd072c52e03
py3: use bytes in place of basestring
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35177
diff
changeset
|
486 if isinstance(changes, bytes): |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
487 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
|
488 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
|
489 else: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
490 dest = self.map[changes] |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
491 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
|
492 return |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24328
diff
changeset
|
493 files, copies, cleanp2 = changes |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
494 pbranches = [] |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
495 if commit.parents: |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
496 for prev in commit.parents: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
497 if prev not in self.commitcache: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
498 self.cachecommit(prev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
499 pbranches.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
500 (self.map[prev], self.commitcache[prev].branch) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
501 ) |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
502 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
|
503 try: |
16105
ebaa0aa749e2
convert: turn splicemap into a simple dictionary
Patrick Mezard <patrick@mezard.eu>
parents:
13745
diff
changeset
|
504 parents = self.splicemap[rev] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
505 self.ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
506 _('spliced in %s as parents of %s\n') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
507 % (_(' and ').join(parents), rev) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
508 ) |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
509 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
|
510 except KeyError: |
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
511 parents = [b[0] for b in pbranches] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
512 parents.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
513 self.map[x] for x in commit.optparents if x in self.map |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
514 ) |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24328
diff
changeset
|
515 if len(pbranches) != 2: |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24328
diff
changeset
|
516 cleanp2 = set() |
24328
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
517 if len(parents) < 3: |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
518 source = progresssource(self.ui, self.source, len(files)) |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
519 else: |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
520 # For an octopus merge, we end up traversing the list of |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
521 # changed files N-1 times. This tweak to the number of |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
522 # files makes it so the progress bar doesn't overflow |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
523 # itself. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
524 source = progresssource( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
525 self.ui, self.source, len(files) * (len(parents) - 1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
526 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
527 newnode = self.dest.putcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
528 files, copies, parents, commit, source, self.map, full, cleanp2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
529 ) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
530 source.close() |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5528
diff
changeset
|
531 self.source.converted(rev, newnode) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
532 self.map[rev] = newnode |
316 | 533 |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
534 def convert(self, sortmode): |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
535 try: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
536 self.source.before() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
537 self.dest.before() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 parents = self.walktree(heads) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
542 self.mergesplicemap(parents, self.splicemap) |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
543 self.ui.status(_("sorting...\n")) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
544 t = self.toposort(parents, sortmode) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
545 num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
546 c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
547 |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6913
diff
changeset
|
548 self.ui.status(_("converting...\n")) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
549 progress = self.ui.makeprogress( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
550 _('converting'), unit=_('revisions'), total=len(t) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
551 ) |
12769
daa8dc6e1f66
convert: kill trailing whitespace
timeless <timeless@gmail.com>
parents:
12768
diff
changeset
|
552 for i, c in enumerate(t): |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
553 num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 # convert log message to local encoding without using |
12768
c6b55be14461
convert: fix typo in comment
timeless <timeless@gmail.com>
parents:
12198
diff
changeset
|
558 # tolocal() because the encoding.encoding convert() |
c6b55be14461
convert: fix typo in comment
timeless <timeless@gmail.com>
parents:
12198
diff
changeset
|
559 # uses is 'utf-8' |
5954
851402e53337
convert: display source revision id with --verbose
Patrick Mezard <pmezard@gmail.com>
parents:
5794
diff
changeset
|
560 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
|
561 self.ui.note(_("source: %s\n") % recode(c)) |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
562 progress.update(i) |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
563 self.copy(c) |
38406
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38366
diff
changeset
|
564 progress.complete() |
316 | 565 |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
566 if not self.ui.configbool('convert', 'skiptags'): |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
567 tags = self.source.gettags() |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
568 ctags = {} |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
569 for k in tags: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
570 v = tags[k] |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
571 if self.map.get(v, SKIPREV) != SKIPREV: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
572 ctags[k] = self.map[v] |
316 | 573 |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
574 if c and ctags: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
575 nrev, tagsparent = self.dest.puttags(ctags) |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
576 if nrev and tagsparent: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
577 # write another hash correspondence to override the |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
578 # previous one so we don't end up with extra tag heads |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
579 tagsparents = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
580 e |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
581 for e in self.map.iteritems() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
582 if e[1] == tagsparent |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
583 ] |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
584 if tagsparents: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
585 self.map[tagsparents[0][0]] = nrev |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
586 |
13745
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
587 bookmarks = self.source.getbookmarks() |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
588 cbookmarks = {} |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
589 for k in bookmarks: |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
590 v = bookmarks[k] |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
591 if self.map.get(v, SKIPREV) != SKIPREV: |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
592 cbookmarks[k] = self.map[v] |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
593 |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
594 if c and cbookmarks: |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
595 self.dest.putbookmarks(cbookmarks) |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
596 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
597 self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
598 finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
599 self.cleanup() |
694 | 600 |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
601 def cleanup(self): |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
602 try: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
603 self.dest.after() |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
604 finally: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
605 self.source.after() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
606 self.map.close() |
694 | 607 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
608 |
5281
a176f9c8b26e
convert: rename a class and a function
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5256
diff
changeset
|
609 def convert(ui, src, dest=None, revmapfile=None, **opts): |
36329
93943eef696f
py3: use pycompat.byteskwargs in hgext/convert/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36148
diff
changeset
|
610 opts = pycompat.byteskwargs(opts) |
5794
4c16020d1172
convert: print commit log message with local encoding correctly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5656
diff
changeset
|
611 global orig_encoding |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
612 orig_encoding = encoding.encoding |
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
613 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
|
614 |
12198
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
615 # support --authors as an alias for --authormap |
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
616 if not opts.get('authormap'): |
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
617 opts['authormap'] = opts.get('authors') |
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
618 |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
623 destc = convertsink(ui, dest, opts.get('dest_type')) |
35177
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35176
diff
changeset
|
624 destc = scmutil.wrapconvertsink(destc) |
316 | 625 |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
626 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
627 srcc, defaultsort = convertsource( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
628 ui, src, opts.get('source_type'), opts.get('rev') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
629 ) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
630 except Exception: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
631 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
|
632 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
|
633 raise |
316 | 634 |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
635 sortmodes = ('branchsort', 'datesort', 'sourcesort', 'closesort') |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
636 sortmode = [m for m in sortmodes if opts.get(m)] |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
637 if len(sortmode) > 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
638 raise error.Abort(_('more than one sort mode specified')) |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
639 if sortmode: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
640 sortmode = sortmode[0] |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
641 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
642 sortmode = defaultsort |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
643 |
8691
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
644 if sortmode == 'sourcesort' and not srcc.hasnativeorder(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
645 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
646 _('--sourcesort is not supported by this data source') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41418
diff
changeset
|
647 ) |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
648 if sortmode == 'closesort' and not srcc.hasnativeclose(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
649 raise error.Abort(_('--closesort is not supported by this data source')) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
650 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
651 fmap = opts.get('filemap') |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
652 if fmap: |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
653 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
|
654 destc.setfilemapmode(True) |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
655 |
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
|
656 if not revmapfile: |
19889
3828b3e09462
convert: remove unused and incorrect default handling for revmapfile
Mads Kiilerich <madski@unity3d.com>
parents:
19181
diff
changeset
|
657 revmapfile = destc.revmapfile() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
658 |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
659 c = converter(ui, srcc, destc, revmapfile, opts) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
660 c.convert(sortmode) |