Mercurial > hg-stable
annotate hgext/convert/convcmd.py @ 52182:fa58f4f97337 stable tip
ci: shard the test run on mac os X
This should comes with some benefit:
- spread the load across more runner,
- reduce the real-time CI run,
- reduce the "retry" run when we need them.
We start with the Mac jobs, but that would be tremendously useful for Windows
too.
For linux, we need to reduce the startup overhead for this to be worth it.
Building smaller image and speeding up clone should help with that.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 08 Nov 2024 17:08:11 +0100 |
parents | f4733654f144 |
children |
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 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
45957
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@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. |
316 | 7 |
51901
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51762
diff
changeset
|
8 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51762
diff
changeset
|
9 |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35208
diff
changeset
|
10 import collections |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
11 import heapq |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
12 import os |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
13 import shutil |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
14 import typing |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
15 |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
16 from typing import ( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
17 AnyStr, |
51746
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
18 Dict, |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
19 List, |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
20 Mapping, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
21 Optional, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
22 Union, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
23 ) |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
24 |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28900
diff
changeset
|
25 from mercurial.i18n import _ |
43085
eef9a2d67051
py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
26 from mercurial.pycompat import open |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
27 from mercurial import ( |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
28 encoding, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
29 error, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
30 hg, |
36171
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36170
diff
changeset
|
31 pycompat, |
35188
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35187
diff
changeset
|
32 scmutil, |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
33 util, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
34 ) |
36636
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36587
diff
changeset
|
35 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
|
36 |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
37 from . import ( |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
38 bzr, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
39 common, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
40 cvs, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
41 darcs, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
42 filemap, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
43 git, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
44 gnuarch, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
45 hg as hgconvert, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
46 monotone, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
47 p4, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
48 subversion, |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
49 ) |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
50 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
51 if typing.TYPE_CHECKING: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
52 from mercurial import ( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
53 ui as uimod, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
54 ) |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
55 |
28409
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
56 mapfile = common.mapfile |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
57 MissingTool = common.MissingTool |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
58 NoRepo = common.NoRepo |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
59 SKIPREV = common.SKIPREV |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
60 |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
61 bzr_source = bzr.bzr_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
62 convert_cvs = cvs.convert_cvs |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
63 convert_git = git.convert_git |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
64 darcs_source = darcs.darcs_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
65 gnuarch_source = gnuarch.gnuarch_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
66 mercurial_sink = hgconvert.mercurial_sink |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
67 mercurial_source = hgconvert.mercurial_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
68 monotone_source = monotone.monotone_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
69 p4_source = p4.p4_source |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
70 svn_sink = subversion.svn_sink |
c43c5e7167a2
convert: convcmd use absolute_import
timeless <timeless@mozdev.org>
parents:
26812
diff
changeset
|
71 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
|
72 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
73 orig_encoding: bytes = b'ascii' |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
74 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
75 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
76 def readauthormap(ui: "uimod.ui", authorfile, authors=None): |
44102
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
77 if authors is None: |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
78 authors = {} |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
79 with open(authorfile, b'rb') as afile: |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
80 for line in afile: |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
81 line = line.strip() |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
82 if not line or line.startswith(b'#'): |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
83 continue |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
84 |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
85 try: |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
86 srcauthor, dstauthor = line.split(b'=', 1) |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
87 except ValueError: |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
88 msg = _(b'ignoring bad line in author map file %s: %s\n') |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
89 ui.warn(msg % (authorfile, line.rstrip())) |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
90 continue |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
91 |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
92 srcauthor = srcauthor.strip() |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
93 dstauthor = dstauthor.strip() |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
94 if authors.get(srcauthor) in (None, dstauthor): |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
95 msg = _(b'mapping author %s to %s\n') |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
96 ui.debug(msg % (srcauthor, dstauthor)) |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
97 authors[srcauthor] = dstauthor |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
98 continue |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
99 |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
100 m = _(b'overriding mapping for author %s, was %s, will be %s\n') |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
101 ui.status(m % (srcauthor, authors[srcauthor], dstauthor)) |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
102 return authors |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
103 |
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
104 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
105 def recode(s: AnyStr) -> bytes: |
49025
06de08b36c82
py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
106 if isinstance(s, str): |
36171
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36170
diff
changeset
|
107 return s.encode(pycompat.sysstr(orig_encoding), 'replace') |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
108 else: |
36171
6df206ef4b10
convcmd: pass encoding name as a sysstr
Augie Fackler <augie@google.com>
parents:
36170
diff
changeset
|
109 return s.decode('utf-8').encode( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
110 pycompat.sysstr(orig_encoding), 'replace' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
111 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
112 |
6131
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
113 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
114 def mapbranch(branch: bytes, branchmap: Mapping[bytes, bytes]) -> bytes: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
115 """ |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30410
diff
changeset
|
116 >>> bmap = {b'default': b'branch1'} |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30410
diff
changeset
|
117 >>> 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
|
118 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
119 'branch1' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
120 'branch1' |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30410
diff
changeset
|
121 >>> bmap = {b'None': b'branch2'} |
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30410
diff
changeset
|
122 >>> 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
|
123 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
124 'branch2' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
125 'branch2' |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
30410
diff
changeset
|
126 >>> 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:
30410
diff
changeset
|
127 >>> 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
|
128 ... mapbranch(i, bmap) |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
129 'branch3' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
130 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
131 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
132 'branch4' |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
133 'branch5' |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
134 """ |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
135 # 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
|
136 # 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
|
137 # 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
|
138 # 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
|
139 # default branch in the destination repository. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
140 branch = branchmap.get(branch or b'default', branch) |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
141 # 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
|
142 # attempt to use that for backward compatibility. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
143 if not branch: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
144 branch = branchmap.get(b'None', branch) |
25805
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
145 return branch |
584044e5ad57
convert: use 'default' for specifying branch name in branchmap (issue4753)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
146 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
147 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
148 source_converters = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
149 (b'cvs', convert_cvs, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
150 (b'git', convert_git, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
151 (b'svn', svn_source, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
152 (b'hg', mercurial_source, b'sourcesort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
153 (b'darcs', darcs_source, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
154 (b'mtn', monotone_source, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
155 (b'gnuarch', gnuarch_source, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 (b'bzr', bzr_source, b'branchsort'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 (b'p4', p4_source, b'branchsort'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
158 ] |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
159 |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
160 sink_converters = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 (b'hg', mercurial_sink), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 (b'svn', svn_sink), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
163 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
164 |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
165 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
166 def convertsource(ui: "uimod.ui", path: bytes, type: bytes, 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
|
167 exceptions = [] |
9962
a7178eccf2dc
convert: better error on invalid repository type
Patrick Mezard <pmezard@gmail.com>
parents:
9431
diff
changeset
|
168 if type and type not in [s[0] for s in source_converters]: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
169 raise error.Abort(_(b'%s: invalid source repository type') % type) |
8692
827d4e807d57
convert: default revisions order depends on source
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
170 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
|
171 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
172 if not type or name == type: |
35187
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34360
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 for inst in exceptions: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
178 ui.write(b"%s\n" % pycompat.bytestr(inst.args[0])) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
179 raise error.Abort(_(b'%s: missing or unsupported repository') % path) |
4763
8e9d3faec270
convert: split converter into convertsource and convertsink
Brendan Cully <brendan@kublai.com>
parents:
4761
diff
changeset
|
180 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
181 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
182 def convertsink( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
183 ui: "uimod.ui", path: bytes, type: bytes |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
184 ) -> Union[hgconvert.mercurial_sink, subversion.svn_sink]: |
9962
a7178eccf2dc
convert: better error on invalid repository type
Patrick Mezard <pmezard@gmail.com>
parents:
9431
diff
changeset
|
185 if type and type not in [s[0] for s in sink_converters]: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
186 raise error.Abort(_(b'%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
|
187 for name, sink in sink_converters: |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
188 try: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
189 if not type or name == type: |
35187
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34360
diff
changeset
|
190 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
|
191 except NoRepo as inst: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
192 ui.note(_(b"convert: %s\n") % inst) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
193 except MissingTool as inst: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
194 raise error.Abort(b'%s\n' % inst) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 raise error.Abort(_(b'%s: unknown repository type') % path) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
196 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
197 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49032
diff
changeset
|
198 class progresssource: |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
199 def __init__( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
200 self, ui: "uimod.ui", source, filecount: Optional[int] |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
201 ) -> None: |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
202 self.ui = ui |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
203 self.source = source |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
204 self.progress = ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
205 _(b'getting files'), unit=_(b'files'), total=filecount |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
206 ) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
207 |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
208 def getfile(self, file, rev): |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
209 self.progress.increment(item=file) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
210 return self.source.getfile(file, rev) |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
211 |
26035
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25805
diff
changeset
|
212 def targetfilebelongstosource(self, targetfilename): |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25805
diff
changeset
|
213 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
|
214 |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
215 def lookuprev(self, rev): |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
216 return self.source.lookuprev(rev) |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
217 |
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
218 def close(self): |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
219 self.progress.complete() |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
220 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
221 |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
222 # Sorters are used by the `toposort` function to maintain a set of revisions |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
223 # which can be converted immediately and pick one |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
224 class branchsorter: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
225 """If the previously converted revision has a child in the |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
226 eligible revisions list, pick it. Return the list head |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
227 otherwise. Branch sort attempts to minimize branch |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
228 switching, which is harmful for Mercurial backend |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
229 compression. |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
230 """ |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
231 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
232 def __init__(self, parents): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
233 self.nodes = [] |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
234 self.parents = parents |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
235 self.prev = None |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
236 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
237 def picknext(self): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
238 next = self.nodes[0] |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
239 for n in self.nodes: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
240 if self.prev in self.parents[n]: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
241 next = n |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
242 break |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
243 self.prev = next |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
244 self.nodes.remove(next) |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
245 return next |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
246 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
247 def insert(self, node): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
248 self.nodes.insert(0, node) |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
249 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
250 def __len__(self): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
251 return self.nodes.__len__() |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
252 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
253 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
254 class keysorter: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
255 """Key-based sort, ties broken by insertion order""" |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
256 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
257 def __init__(self, keyfn): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
258 self.heap = [] |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
259 self.keyfn = keyfn |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
260 self.counter = 0 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
261 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
262 def picknext(self): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
263 return heapq.heappop(self.heap)[2] |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
264 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
265 def insert(self, node): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
266 counter = self.counter |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
267 self.counter = counter + 1 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
268 key = self.keyfn(node) |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
269 heapq.heappush(self.heap, (key, counter, node)) |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
270 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
271 def __len__(self): |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
272 return self.heap.__len__() |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
273 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
274 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49032
diff
changeset
|
275 class converter: |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
276 def __init__(self, ui: "uimod.ui", source, dest, revmapfile, opts) -> None: |
316 | 277 self.source = source |
278 self.dest = dest | |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
279 self.ui = ui |
3957
2b87d3c5ab8e
convert-repo: add option to attempt to sort by date
Matt Mackall <mpm@selenic.com>
parents:
3956
diff
changeset
|
280 self.opts = opts |
316 | 281 self.commitcache = {} |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
282 self.authors = {} |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
283 self.authorfile = None |
316 | 284 |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8377
diff
changeset
|
285 # Record converted revisions persistently: maps source revision |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8693
diff
changeset
|
286 # 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
|
287 # incremental conversions work.) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
288 self.map = mapfile(ui, revmapfile) |
316 | 289 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
290 # 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
|
291 authorfile = self.dest.authorfile() |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
292 if authorfile and os.path.exists(authorfile): |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
293 self.readauthormap(authorfile) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
294 # Extend/Override with new author map if necessary |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
295 if opts.get(b'authormap'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 self.readauthormap(opts.get(b'authormap')) |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
297 self.authorfile = self.dest.authorfile() |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
298 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
299 self.splicemap = self.parsesplicemap(opts.get(b'splicemap')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
300 self.branchmap = mapfile(ui, opts.get(b'branchmap')) |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
301 |
51746
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
302 def parsesplicemap(self, path: bytes) -> Dict[bytes, List[bytes]]: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
303 """check and validate the splicemap format and |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
304 return a child/parents dictionary. |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
305 Format checking has two parts. |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
306 1. generic format which is same across all source types |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
307 2. specific format checking which may be different for |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
308 different source type. This logic is implemented in |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
309 checkrevformat function in source files like |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
310 hg.py, subversion.py etc. |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
311 """ |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
312 |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
313 if not path: |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
314 return {} |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
315 m = {} |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
316 try: |
51746
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
317 with open(path, b'rb') as fp: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
318 for i, line in enumerate(fp): |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
319 line = line.splitlines()[0].rstrip() |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
320 if not line: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
321 # Ignore blank lines |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
322 continue |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
323 # split line |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
324 lex = common.shlexer(data=line, whitespace=b',') |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
325 line = list(lex) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
326 # check number of parents |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
327 if not (2 <= len(line) <= 3): |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
328 raise error.Abort( |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
329 _( |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
330 b'syntax error in %s(%d): child parent1' |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
331 b'[,parent2] expected' |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
332 ) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
333 % (path, i + 1) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
334 ) |
51746
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
335 for part in line: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
336 self.source.checkrevformat(part) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
337 child, p1, p2 = line[0], line[1:2], line[2:] |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
338 if p1 == p2: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
339 m[child] = p1 |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
340 else: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
341 m[child] = p1 + p2 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
342 # 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
|
343 except IOError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
344 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 _(b'splicemap file not found or error reading %s:') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
346 ) |
19119
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
347 return m |
61f1223ab358
splicemap: move parsesplicemap to convcmd.py (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
348 |
316 | 349 def walktree(self, heads): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
350 """Return a mapping that identifies the uncommitted parents of every |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
351 uncommitted changeset.""" |
37932
73ca1c5e65f8
convcmd: make a copy of heads before mutating it
Augie Fackler <augie@google.com>
parents:
36636
diff
changeset
|
352 visit = list(heads) |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
353 known = set() |
316 | 354 parents = {} |
22411
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
355 numcommits = self.source.numcommits() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
356 progress = self.ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
357 _(b'scanning'), unit=_(b'revisions'), total=numcommits |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
358 ) |
316 | 359 while visit: |
360 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
|
361 if n in known: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
362 continue |
21636
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
363 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
|
364 m = self.map[n] |
3de9f2c4900c
convert: only consider shamap revisions converted if they still exists
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
365 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
|
366 continue |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8444
diff
changeset
|
367 known.add(n) |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
368 progress.update(len(known)) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
369 commit = self.cachecommit(n) |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
370 parents[n] = [] |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
371 for p in commit.parents: |
4719
1069205a8894
fix 'convert' with single commit repositories
Hollis Blanchard <hollisb@us.ibm.com>
parents:
4635
diff
changeset
|
372 parents[n].append(p) |
316 | 373 visit.append(p) |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
374 progress.complete() |
316 | 375 |
376 return parents | |
377 | |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
378 def mergesplicemap(self, parents, splicemap) -> None: |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
379 """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
|
380 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
|
381 links in the source graph. |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
382 """ |
18372
5965997b7023
convert: process splicemap in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
17424
diff
changeset
|
383 for c in sorted(splicemap): |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
384 if c not in parents: |
21634
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21077
diff
changeset
|
385 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
|
386 # Could be in source but not converted during this run |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
387 self.ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
388 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
389 b'splice map revision %s is not being ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
390 b'converted, ignoring\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
391 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
392 % c |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
393 ) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
394 continue |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
395 pc = [] |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
396 for p in splicemap[c]: |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
397 # 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
|
398 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
|
399 continue |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
400 # 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
|
401 if p not in parents: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
402 raise error.Abort(_(b'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
|
403 pc.append(p) |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
404 parents[c] = pc |
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
405 |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
406 def toposort(self, parents, sortmode): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
407 """Return an ordering such that every uncommitted changeset is |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44102
diff
changeset
|
408 preceded by all its uncommitted ancestors.""" |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
409 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
410 def mapchildren(parents): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
411 """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
|
412 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
|
413 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
|
414 identifier to its parents ones. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
415 """ |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35208
diff
changeset
|
416 visit = collections.deque(sorted(parents)) |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
417 seen = set() |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
418 children = {} |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
419 roots = [] |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
420 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
421 while visit: |
35779
eefabd9ed3e1
convert: use a collections.deque
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35208
diff
changeset
|
422 n = visit.popleft() |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
423 if n in seen: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
424 continue |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
425 seen.add(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
426 # 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
|
427 # 'children' mapping. |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
428 children.setdefault(n, []) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
429 hasparent = False |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
430 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
|
431 if p not in self.map: |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
432 visit.append(p) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
433 hasparent = True |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
434 children.setdefault(p, []).append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
435 if not hasparent: |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
436 roots.append(n) |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
437 |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
438 return children, roots |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
439 |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
440 def makesourcesorter(): |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
441 """Source specific sort.""" |
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
442 keyfn = lambda n: self.commitcache[n].sortkey |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
443 return keysorter(keyfn) |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
444 |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
445 def makeclosesorter(): |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
446 """Close order sort.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
447 keyfn = lambda n: ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
448 b'close' not in self.commitcache[n].extra, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
449 self.commitcache[n].sortkey, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
450 ) |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
451 return keysorter(keyfn) |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18376
diff
changeset
|
452 |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
453 def makedatesorter(): |
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
454 """Sort revisions by date.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
455 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
456 def getdate(n): |
50910
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
457 commit = self.commitcache[n] |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
458 # The other entries are here as tie breaker for stability |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
459 return ( |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
460 dateutil.parsedate(commit.date), |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
461 commit.rev, |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
462 commit.branch, |
8edfd28a01d1
convert: stabilize subversion date sorter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50220
diff
changeset
|
463 ) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
464 |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
465 return keysorter(getdate) |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
466 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
467 if sortmode == b'branchsort': |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
468 sorter = branchsorter(parents) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 elif sortmode == b'datesort': |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
470 sorter = makedatesorter() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
471 elif sortmode == b'sourcesort': |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
472 sorter = makesourcesorter() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
473 elif sortmode == b'closesort': |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
474 sorter = makeclosesorter() |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
475 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
476 raise error.Abort(_(b'unknown sort mode: %s') % sortmode) |
8688
31e613a89750
convert: split toposort() into subfunctions for readability
Patrick Mezard <pmezard@gmail.com>
parents:
8456
diff
changeset
|
477 |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
478 children, roots = mapchildren(parents) |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
479 |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
480 for node in roots: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
481 sorter.insert(node) |
316 | 482 |
483 s = [] | |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
484 pendings = {} |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
485 while sorter: |
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
486 n = sorter.picknext() |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
487 s.append(n) |
316 | 488 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
489 # Update dependents list |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
490 for c in children.get(n, []): |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
491 if c not in pendings: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
492 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
|
493 try: |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
494 pendings[c].remove(n) |
fddeeb00f8d1
convert: improve cycles detection message
Patrick Mezard <pmezard@gmail.com>
parents:
6130
diff
changeset
|
495 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
496 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
497 _(b'cycle detected between %s and %s') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
498 % (recode(c), recode(n)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
499 ) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
500 if not pendings[c]: |
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
501 # Parents are converted, node is eligible |
50220
02fe65f74be5
convert: use a priority queue for sorting commits, to make sorting faster
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49037
diff
changeset
|
502 sorter.insert(c) |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
503 pendings[c] = None |
316 | 504 |
6100
49c69e1e4aa2
convert: fix --datesort ordering
Patrick Mezard <pmezard@gmail.com>
parents:
6099
diff
changeset
|
505 if len(s) != len(parents): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
506 raise error.Abort(_(b"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
|
507 |
316 | 508 return s |
509 | |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
510 def writeauthormap(self) -> None: |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
511 authorfile = self.authorfile |
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
512 if authorfile: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
513 self.ui.status(_(b'writing author map file %s\n') % authorfile) |
51746
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
514 with open(authorfile, b'wb+') as ofile: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
515 for author in self.authors: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
516 ofile.write( |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
517 util.tonativeeol( |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
518 b"%s=%s\n" % (author, self.authors[author]) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51744
diff
changeset
|
519 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 ) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
521 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
522 def readauthormap(self, authorfile) -> None: |
44102
fdaa4233dc18
convert: refactor authormap into separate function for outside use
Joerg Sonnenberger <joerg@bec.de>
parents:
43105
diff
changeset
|
523 self.authors = readauthormap(self.ui, authorfile, self.authors) |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
524 |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
525 def cachecommit(self, rev): |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
526 commit = self.source.getcommit(rev) |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
527 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
|
528 commit.branch = mapbranch(commit.branch, self.branchmap) |
5203
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
529 self.commitcache[rev] = commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
530 return commit |
653790c2fa52
convert: wrap cached commits author remapping
Patrick Mezard <pmezard@gmail.com>
parents:
5195
diff
changeset
|
531 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
532 def copy(self, rev) -> None: |
5016
4ebc8693ce72
convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents:
5014
diff
changeset
|
533 commit = self.commitcache[rev] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
534 full = self.opts.get(b'full') |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
21636
diff
changeset
|
535 changes = self.source.getchanges(rev, full) |
35208
bfd072c52e03
py3: use bytes in place of basestring
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35188
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 else: |
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
540 dest = self.map[changes] |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
541 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
|
542 return |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24328
diff
changeset
|
543 files, copies, cleanp2 = changes |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
544 pbranches = [] |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
545 if commit.parents: |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
546 for prev in commit.parents: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
547 if prev not in self.commitcache: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
548 self.cachecommit(prev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
549 pbranches.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
550 (self.map[prev], self.commitcache[prev].branch) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
551 ) |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5621
diff
changeset
|
552 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
|
553 try: |
16105
ebaa0aa749e2
convert: turn splicemap into a simple dictionary
Patrick Mezard <patrick@mezard.eu>
parents:
13745
diff
changeset
|
554 parents = self.splicemap[rev] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
555 self.ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
556 _(b'spliced in %s as parents of %s\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
557 % (_(b' and ').join(parents), rev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
558 ) |
6143
5b159ebb19cf
convert: document splicemap, allow setting of multiple parents
Bryan O'Sullivan <bos@serpentine.com>
parents:
6131
diff
changeset
|
559 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
|
560 except KeyError: |
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
561 parents = [b[0] for b in pbranches] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
562 parents.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
563 self.map[x] for x in commit.optparents if x in self.map |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
564 ) |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24328
diff
changeset
|
565 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
|
566 cleanp2 = set() |
24328
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
567 if len(parents) < 3: |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
568 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
|
569 else: |
603a8d09e12d
convert: adjust progress bar for octopus merges (issue4169)
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
570 # 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
|
571 # 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
|
572 # 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
|
573 # itself. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
574 source = progresssource( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
575 self.ui, self.source, len(files) * (len(parents) - 1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
576 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
577 newnode = self.dest.putcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
578 files, copies, parents, commit, source, self.map, full, cleanp2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
579 ) |
11136
ecc8b18736da
convert: display files data retrieval progress
Patrick Mezard <pmezard@gmail.com>
parents:
11135
diff
changeset
|
580 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
|
581 self.source.converted(rev, newnode) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
582 self.map[rev] = newnode |
316 | 583 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
584 def convert(self, sortmode) -> None: |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
585 try: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
586 self.source.before() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
587 self.dest.before() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
588 self.source.setrevmap(self.map) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
589 self.ui.status(_(b"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
|
590 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
|
591 parents = self.walktree(heads) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
592 self.mergesplicemap(parents, self.splicemap) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
593 self.ui.status(_(b"sorting...\n")) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
594 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
|
595 num = len(t) |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
596 c = None |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
597 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
598 self.ui.status(_(b"converting...\n")) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
599 progress = self.ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
600 _(b'converting'), unit=_(b'revisions'), total=len(t) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
601 ) |
12769
daa8dc6e1f66
convert: kill trailing whitespace
timeless <timeless@gmail.com>
parents:
12768
diff
changeset
|
602 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
|
603 num -= 1 |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
604 desc = self.commitcache[c].desc |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
605 if b"\n" in desc: |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
606 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
|
607 # convert log message to local encoding without using |
12768
c6b55be14461
convert: fix typo in comment
timeless <timeless@gmail.com>
parents:
12198
diff
changeset
|
608 # tolocal() because the encoding.encoding convert() |
c6b55be14461
convert: fix typo in comment
timeless <timeless@gmail.com>
parents:
12198
diff
changeset
|
609 # uses is 'utf-8' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
610 self.ui.status(b"%d %s\n" % (num, recode(desc))) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
611 self.ui.note(_(b"source: %s\n") % recode(c)) |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
612 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
|
613 self.copy(c) |
38412
65d1d7da63d1
convert: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38372
diff
changeset
|
614 progress.complete() |
316 | 615 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
616 if not self.ui.configbool(b'convert', b'skiptags'): |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
617 tags = self.source.gettags() |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
618 ctags = {} |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
619 for k in tags: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
620 v = tags[k] |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
621 if self.map.get(v, SKIPREV) != SKIPREV: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
622 ctags[k] = self.map[v] |
316 | 623 |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
624 if c and ctags: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
625 nrev, tagsparent = self.dest.puttags(ctags) |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
626 if nrev and tagsparent: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
627 # write another hash correspondence to override the |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
628 # previous one so we don't end up with extra tag heads |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
629 tagsparents = [ |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
630 e for e in self.map.items() if e[1] == tagsparent |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
631 ] |
25741
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
632 if tagsparents: |
86fe3c404c1e
convert: add config to not convert tags
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
633 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
|
634 |
13745
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
635 bookmarks = self.source.getbookmarks() |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
636 cbookmarks = {} |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
637 for k in bookmarks: |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
638 v = bookmarks[k] |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
639 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
|
640 cbookmarks[k] = self.map[v] |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
641 |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
642 if c and cbookmarks: |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
643 self.dest.putbookmarks(cbookmarks) |
9ff22f600c6c
convert: add bookmark support to main command
Edouard Gomez <ed.gomez@free.fr>
parents:
13685
diff
changeset
|
644 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4588
diff
changeset
|
645 self.writeauthormap() |
4588
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
646 finally: |
9855939d0c82
convert extension: Save a few opens on the map file
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
647 self.cleanup() |
694 | 648 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
649 def cleanup(self) -> None: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
650 try: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
651 self.dest.after() |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
652 finally: |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5281
diff
changeset
|
653 self.source.after() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5488
diff
changeset
|
654 self.map.close() |
694 | 655 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
656 |
51744
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
657 def convert( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
658 ui: "uimod.ui", src, dest: Optional[bytes] = None, revmapfile=None, **opts |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
50910
diff
changeset
|
659 ) -> None: |
36362
93943eef696f
py3: use pycompat.byteskwargs in hgext/convert/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36186
diff
changeset
|
660 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
|
661 global orig_encoding |
7948
de377b1a9a84
move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents:
7877
diff
changeset
|
662 orig_encoding = encoding.encoding |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
663 encoding.encoding = b'UTF-8' |
4895
fa6c9381d053
convert: manually set encoding to UTF-8
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4883
diff
changeset
|
664 |
12198
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
665 # support --authors as an alias for --authormap |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
666 if not opts.get(b'authormap'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
667 opts[b'authormap'] = opts.get(b'authors') |
12198
0c67a58f0580
convert: deprecate --authors in preference for --authormap
Martin Geisler <mg@lazybytes.net>
parents:
11731
diff
changeset
|
668 |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
669 if not dest: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
670 dest = hg.defaultdest(src) + b"-hg" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
671 ui.status(_(b"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
|
672 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
673 destc = convertsink(ui, dest, opts.get(b'dest_type')) |
35188
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
35187
diff
changeset
|
674 destc = scmutil.wrapconvertsink(destc) |
316 | 675 |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
676 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
677 srcc, defaultsort = convertsource( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
678 ui, src, opts.get(b'source_type'), opts.get(b'rev') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
679 ) |
4761
7c8cd400e86a
convert: initialize source after destination, cleaning up if source is unusable
Brendan Cully <brendan@kublai.com>
parents:
4760
diff
changeset
|
680 except Exception: |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5438
diff
changeset
|
681 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
|
682 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
|
683 raise |
316 | 684 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
685 sortmodes = (b'branchsort', b'datesort', b'sourcesort', b'closesort') |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8689
diff
changeset
|
686 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
|
687 if len(sortmode) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
688 raise error.Abort(_(b'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
|
689 if sortmode: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
690 sortmode = sortmode[0] |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
691 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
692 sortmode = defaultsort |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
693 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
694 if sortmode == b'sourcesort' and not srcc.hasnativeorder(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
695 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
696 _(b'--sourcesort is not supported by this data source') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41440
diff
changeset
|
697 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
698 if sortmode == b'closesort' and not srcc.hasnativeclose(): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
699 raise error.Abort( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
700 _(b'--closesort is not supported by this data source') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
701 ) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
702 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
703 fmap = opts.get(b'filemap') |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
704 if fmap: |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
705 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
|
706 destc.setfilemapmode(True) |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5376
diff
changeset
|
707 |
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
|
708 if not revmapfile: |
19889
3828b3e09462
convert: remove unused and incorrect default handling for revmapfile
Mads Kiilerich <madski@unity3d.com>
parents:
19181
diff
changeset
|
709 revmapfile = destc.revmapfile() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
710 |
5375
dae323e453aa
convert: disable current --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
711 c = converter(ui, srcc, destc, revmapfile, opts) |
8689
9bc95f8eb018
convert: parse sort mode sooner
Patrick Mezard <pmezard@gmail.com>
parents:
8688
diff
changeset
|
712 c.convert(sortmode) |