annotate hgext/convert/filemap.py @ 51686:39033e7a6e0a

convert: stringify `shlex` class argument The documentation is handwavy, but typeshed says this should be `str`[1]. I'm not sure if this is the correct encoding (vs `fsencode` or "latin1" like the tokens returned by the proxy class). While we're here, we can add a few more type hints that would have caused pytype to flag the problem. [1] https://github.com/python/typeshed/blob/6a9b53e719a139c2d6b41cf265ed0990cf438192/stdlib/shlex.pyi#L51
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 11 Jul 2024 21:16:45 -0400
parents 0eb515c7bec8
children f4733654f144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5376
d60a067227a5 convert: move filemapper class to a separate file
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5375
diff changeset
1 # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com>
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
2 # Copyright 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
3 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8150
diff changeset
4 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8693
diff changeset
5 # GNU General Public License version 2 or any later version.
34137
a8994d08e4a2 doctest: use print_function and convert bytes to unicode where needed
Yuya Nishihara <yuya@tcha.org>
parents: 34131
diff changeset
6
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
7
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
8 import posixpath
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
9 import typing
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
10
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
11 from typing import (
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
12 Iterator,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
13 Mapping,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
14 MutableMapping,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
15 Optional,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
16 Set,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
17 Tuple,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
18 overload,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
19 )
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28367
diff changeset
20
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28367
diff changeset
21 from mercurial.i18n import _
28367
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
22 from mercurial import (
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
23 error,
36560
41c0e7b7869c convert: fix two %r output formats with pycompat.bytestr() wrapping
Augie Fackler <augie@google.com>
parents: 36559
diff changeset
24 pycompat,
28367
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
25 )
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
26 from . import common
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
27
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
28 if typing.TYPE_CHECKING:
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
29 from mercurial import (
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
30 ui as uimod,
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
31 )
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
32
28367
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
33 SKIPREV = common.SKIPREV
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
34
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
35
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
36 def rpairs(path: bytes) -> Iterator[Tuple[bytes, bytes]]:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
37 """Yield tuples with path split at '/', starting with the full path.
20048
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
38 No leading, trailing or double '/', please.
34137
a8994d08e4a2 doctest: use print_function and convert bytes to unicode where needed
Yuya Nishihara <yuya@tcha.org>
parents: 34131
diff changeset
39 >>> for x in rpairs(b'foo/bar/baz'): print(x)
20048
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
40 ('foo/bar/baz', '')
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
41 ('foo/bar', 'baz')
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
42 ('foo', 'bar/baz')
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
43 ('.', 'foo/bar/baz')
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
44 """
20048
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
45 i = len(path)
da99ebd35f00 convert: readability and test of rpairs function
Mads Kiilerich <madski@unity3d.com>
parents: 19892
diff changeset
46 while i != -1:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
47 yield path[:i], path[i + 1 :]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
48 i = path.rfind(b'/', 0, i)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
49 yield b'.', path
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
50
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
51
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
52 if typing.TYPE_CHECKING:
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
53
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
54 @overload
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
55 def normalize(path: bytes) -> bytes:
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
56 pass
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
57
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
58 @overload
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
59 def normalize(path: None) -> None:
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
60 pass
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
61
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
62
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
63 def normalize(path):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
64 """We use posixpath.normpath to support cross-platform path format.
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
65 However, it doesn't handle None input. So we wrap it up."""
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
66 if path is None:
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
67 return None
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
68 return posixpath.normpath(path)
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
69
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
70
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
71 class filemapper:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
72 """Map and filter filenames when importing.
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
73 A name can be mapped to itself, a new name, or None (omit from new
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
74 repository)."""
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
75
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
76 rename: MutableMapping[bytes, bytes]
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
77 targetprefixes: Optional[Set[bytes]]
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
78
51686
39033e7a6e0a convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents: 51685
diff changeset
79 def __init__(self, ui: "uimod.ui", path: Optional[bytes] = None) -> None:
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
80 self.ui = ui
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
81 self.include = {}
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
82 self.exclude = {}
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
83 self.rename = {}
26036
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
84 self.targetprefixes = None
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
85 if path:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
86 if self.parse(path):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
87 raise error.Abort(_(b'errors in filemap'))
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
88
51686
39033e7a6e0a convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents: 51685
diff changeset
89 def parse(self, path: Optional[bytes]) -> int:
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
90 errs = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
91
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
92 def check(name: bytes, mapping, listname: bytes):
11680
7fefef3ce791 convert: warn on superfluous / in paths
Mads Kiilerich <mads@kiilerich.com>
parents: 11673
diff changeset
93 if not name:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
94 self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 _(b'%s:%d: path to %s is missing\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
96 % (lex.infile, lex.lineno, listname)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
97 )
11680
7fefef3ce791 convert: warn on superfluous / in paths
Mads Kiilerich <mads@kiilerich.com>
parents: 11673
diff changeset
98 return 1
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
99 if name in mapping:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
100 self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
101 _(b'%s:%d: %r already in %s list\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
102 % (lex.infile, lex.lineno, name, listname)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
103 )
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
104 return 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
105 if name.startswith(b'/') or name.endswith(b'/') or b'//' in name:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
106 self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
107 _(b'%s:%d: superfluous / in %s %r\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
108 % (lex.infile, lex.lineno, listname, pycompat.bytestr(name))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
109 )
11680
7fefef3ce791 convert: warn on superfluous / in paths
Mads Kiilerich <mads@kiilerich.com>
parents: 11673
diff changeset
110 return 1
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
111 return 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
112
36559
5374a22d014a convert: use our shlex wrapper in filemap to avoid Python 3 tracebacks
Augie Fackler <augie@google.com>
parents: 36132
diff changeset
113 lex = common.shlexer(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
114 filepath=path, wordchars=b'!@#$%^&*()-=+[]{}|;:,./<>?'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
115 )
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
116 cmd = lex.get_token()
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
117 while cmd:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
118 if cmd == b'include':
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
119 name = normalize(lex.get_token())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
120 errs += check(name, self.exclude, b'exclude')
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
121 self.include[name] = name
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
122 elif cmd == b'exclude':
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
123 name = normalize(lex.get_token())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
124 errs += check(name, self.include, b'include')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
125 errs += check(name, self.rename, b'rename')
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
126 self.exclude[name] = name
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
127 elif cmd == b'rename':
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
128 src = normalize(lex.get_token())
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
129 dest = normalize(lex.get_token())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
130 errs += check(src, self.exclude, b'exclude')
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
131 self.rename[src] = dest
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
132 elif cmd == b'source':
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
133 errs += self.parse(normalize(lex.get_token()))
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
134 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
135 self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
136 _(b'%s:%d: unknown directive %r\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
137 % (lex.infile, lex.lineno, pycompat.bytestr(cmd))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
138 )
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
139 errs += 1
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
140 cmd = lex.get_token()
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
141 return errs
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
142
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
143 def lookup(
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
144 self, name: bytes, mapping: Mapping[bytes, bytes]
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
145 ) -> Tuple[bytes, bytes, bytes]:
17797
e4da793998bf convert: normalize paths in filemaps (issue3612)
Huayang <huayang@fb.com>
parents: 17184
diff changeset
146 name = normalize(name)
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
147 for pre, suf in rpairs(name):
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
148 try:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
149 return mapping[pre], pre, suf
7875
553aa0cbeab6 cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 5803
diff changeset
150 except KeyError:
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
151 pass
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
152 return b'', name, b''
5143
d4fa6bafc43a Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5139
diff changeset
153
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
154 def istargetfile(self, filename: bytes) -> bool:
26036
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
155 """Return true if the given target filename is covered as a destination
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
156 of the filemap. This is useful for identifying what parts of the target
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
157 repo belong to the source repo and what parts don't."""
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
158 if self.targetprefixes is None:
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
159 self.targetprefixes = set()
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
160 for before, after in self.rename.items():
26036
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
161 self.targetprefixes.add(after)
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
162
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
163 # If "." is a target, then all target files are considered from the
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
164 # source.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
165 if not self.targetprefixes or b'.' in self.targetprefixes:
26036
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
166 return True
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
167
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
168 filename = normalize(filename)
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
169 for pre, suf in rpairs(filename):
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
170 # This check is imperfect since it doesn't account for the
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
171 # include/exclude list, but it should work in filemaps that don't
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
172 # apply include/exclude to the same source directories they are
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
173 # renaming.
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
174 if pre in self.targetprefixes:
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
175 return True
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
176 return False
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
177
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
178 def __call__(self, name: bytes) -> Optional[bytes]:
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
179 if self.include:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
180 inc = self.lookup(name, self.include)[0]
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
181 else:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
182 inc = name
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
183 if self.exclude:
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
184 exc = self.lookup(name, self.exclude)[0]
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
185 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
186 exc = b''
9884
2dd700a35fd1 convert: make filemap favor most specific filtering rule
Stefan Simek <simek@triaxis.sk>
parents: 8693
diff changeset
187 if (not self.include and exc) or (len(inc) <= len(exc)):
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
188 return None
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
189 newpre, pre, suf = self.lookup(name, self.rename)
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
190 if newpre:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
191 if newpre == b'.':
5133
745cffe59ca8 convert: use '.' as destination name if renaming subdir into root
Bryan O'Sullivan <bos@serpentine.com>
parents: 5127
diff changeset
192 return suf
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
193 if suf:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
194 if newpre.endswith(b'/'):
15565
3992c7df85f2 convert: handle trailing slashes in filemap better (issue3124)
Matt Mackall <mpm@selenic.com>
parents: 15107
diff changeset
195 return newpre + suf
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
196 return newpre + b'/' + suf
5016
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
197 return newpre
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
198 return name
4ebc8693ce72 convert: add filename filtering and renaming support
Bryan O'Sullivan <bos@serpentine.com>
parents: 5014
diff changeset
199
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
200 def active(self) -> bool:
5195
33015dac5df5 convert: fix mercurial_sink.putcommit
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5173
diff changeset
201 return bool(self.include or self.exclude or self.rename)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
202
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
203
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
204 # This class does two additional things compared to a regular source:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
205 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
206 # - Filter and rename files. This is mostly wrapped by the filemapper
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
207 # class above. We hide the original filename in the revision that is
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
208 # returned by getchanges to be able to find things later in getfile.
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
209 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
210 # - Return only revisions that matter for the files we're interested in.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
211 # This involves rewriting the parents of the original revision to
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
212 # create a graph that is restricted to those revisions.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
213 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
214 # This set of revisions includes not only revisions that directly
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
215 # touch files we're interested in, but also merges that merge two
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
216 # or more interesting revisions.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
217
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
218
28367
58b176240df6 convert: filemap use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
219 class filemap_source(common.converter_source):
51686
39033e7a6e0a convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents: 51685
diff changeset
220 def __init__(
39033e7a6e0a convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents: 51685
diff changeset
221 self, ui: "uimod.ui", baseconverter, filemap: Optional[bytes]
39033e7a6e0a convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents: 51685
diff changeset
222 ) -> None:
35176
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 34137
diff changeset
223 super(filemap_source, self).__init__(ui, baseconverter.repotype)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
224 self.base = baseconverter
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
225 self.filemapper = filemapper(ui, filemap)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
226 self.commits = {}
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
227 # if a revision rev has parent p in the original revision graph, then
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
228 # rev will have parent self.parentmap[p] in the restricted graph.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
229 self.parentmap = {}
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
230 # self.wantedancestors[rev] is the set of all ancestors of rev that
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
231 # are in the restricted graph.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
232 self.wantedancestors = {}
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
233 self.convertedorder = None
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
234 self._rebuilt = False
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
235 self.origparents = {}
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
236 self.children = {}
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
237 self.seenchildren = {}
25742
d859123e0f47 convert: add config option for disabling ancestor parent checks
Durham Goode <durham@fb.com>
parents: 25149
diff changeset
238 # experimental config: convert.ignoreancestorcheck
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
239 self.ignoreancestorcheck = self.ui.configbool(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
240 b'convert', b'ignoreancestorcheck'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
241 )
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
242
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
243 def before(self) -> None:
5799
4b82d1a84db8 convert: filemap must call base converter before()/after() actions
Patrick Mezard <pmezard@gmail.com>
parents: 5401
diff changeset
244 self.base.before()
4b82d1a84db8 convert: filemap must call base converter before()/after() actions
Patrick Mezard <pmezard@gmail.com>
parents: 5401
diff changeset
245
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
246 def after(self) -> None:
5799
4b82d1a84db8 convert: filemap must call base converter before()/after() actions
Patrick Mezard <pmezard@gmail.com>
parents: 5401
diff changeset
247 self.base.after()
4b82d1a84db8 convert: filemap must call base converter before()/after() actions
Patrick Mezard <pmezard@gmail.com>
parents: 5401
diff changeset
248
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5401
diff changeset
249 def setrevmap(self, revmap):
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
250 # rebuild our state to make things restartable
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
251 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
252 # To avoid calling getcommit for every revision that has already
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
253 # been converted, we rebuild only the parentmap, delaying the
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
254 # rebuild of wantedancestors until we need it (i.e. until a
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
255 # merge).
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
256 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
257 # We assume the order argument lists the revisions in
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
258 # topological order, so that we can infer which revisions were
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
259 # wanted by previous runs.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
260 self._rebuilt = not revmap
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
261 seen = {SKIPREV: SKIPREV}
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 7875
diff changeset
262 dummyset = set()
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
263 converted = []
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5401
diff changeset
264 for rev in revmap.order:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
265 mapped = revmap[rev]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
266 wanted = mapped not in seen
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
267 if wanted:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
268 seen[mapped] = rev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
269 self.parentmap[rev] = rev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
270 else:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
271 self.parentmap[rev] = seen[mapped]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
272 self.wantedancestors[rev] = dummyset
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
273 arg = seen[mapped]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
274 if arg == SKIPREV:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
275 arg = None
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
276 converted.append((rev, wanted, arg))
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
277 self.convertedorder = converted
5510
11d7908a3ea8 convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents: 5401
diff changeset
278 return self.base.setrevmap(revmap)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
279
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
280 def rebuild(self) -> bool:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
281 if self._rebuilt:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
282 return True
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
283 self._rebuilt = True
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
284 self.parentmap.clear()
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
285 self.wantedancestors.clear()
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
286 self.seenchildren.clear()
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
287 for rev, wanted, arg in self.convertedorder:
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
288 if rev not in self.origparents:
19863
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
289 try:
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
290 self.origparents[rev] = self.getcommit(rev).parents
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
291 except error.RepoLookupError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
292 self.ui.debug(b"unknown revmap source: %s\n" % rev)
19863
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
293 continue
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
294 if arg is not None:
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
295 self.children[arg] = self.children.get(arg, 0) + 1
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
296
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
297 for rev, wanted, arg in self.convertedorder:
19863
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
298 try:
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
299 parents = self.origparents[rev]
daeab82fa644 convert: fix crash when existing converted revision didn't come from source
Mads Kiilerich <madski@unity3d.com>
parents: 19862
diff changeset
300 except KeyError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
301 continue # unknown revmap source
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
302 if wanted:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
303 self.mark_wanted(rev, parents)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
304 else:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
305 self.mark_not_wanted(rev, arg)
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
306 self._discard(arg, *parents)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
307
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
308 return True
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
309
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
310 def getheads(self):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
311 return self.base.getheads()
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
312
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
313 def getcommit(self, rev: bytes):
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
314 # We want to save a reference to the commit objects to be able
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
315 # to rewrite their parents later on.
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
316 c = self.commits[rev] = self.base.getcommit(rev)
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
317 for p in c.parents:
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
318 self.children[p] = self.children.get(p, 0) + 1
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
319 return c
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
320
41179
77088fa862df convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents: 36560
diff changeset
321 def numcommits(self):
77088fa862df convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents: 36560
diff changeset
322 return self.base.numcommits()
77088fa862df convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents: 36560
diff changeset
323
13968
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
324 def _cachedcommit(self, rev):
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
325 if rev in self.commits:
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
326 return self.commits[rev]
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
327 return self.base.getcommit(rev)
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
328
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
329 def _discard(self, *revs) -> None:
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
330 for r in revs:
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
331 if r is None:
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
332 continue
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
333 self.seenchildren[r] = self.seenchildren.get(r, 0) + 1
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
334 if self.seenchildren[r] == self.children[r]:
19862
42455ebbab9f convert: fix crash when filemap filtering is changed
Mads Kiilerich <madski@unity3d.com>
parents: 17797
diff changeset
335 self.wantedancestors.pop(r, None)
42455ebbab9f convert: fix crash when filemap filtering is changed
Mads Kiilerich <madski@unity3d.com>
parents: 17797
diff changeset
336 self.parentmap.pop(r, None)
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
337 del self.seenchildren[r]
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
338 if self._rebuilt:
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
339 del self.children[r]
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
340
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
341 def wanted(self, rev, i) -> bool:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
342 # Return True if we're directly interested in rev.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
343 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
344 # i is an index selecting one of the parents of rev (if rev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
345 # has no parents, i is None). getchangedfiles will give us
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
346 # the list of files that are different in rev and in the parent
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
347 # indicated by i. If we're interested in any of these files,
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
348 # we're interested in rev.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
349 try:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
350 files = self.base.getchangedfiles(rev, i)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
351 except NotImplementedError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
352 raise error.Abort(_(b"source repository doesn't support --filemap"))
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
353 for f in files:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
354 if self.filemapper(f):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
355 return True
41180
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
356
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
357 # The include directive is documented to include nothing else (though
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
358 # valid branch closes are included).
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
359 if self.filemapper.include:
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
360 return False
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
361
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
362 # Allow empty commits in the source revision through. The getchanges()
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
363 # method doesn't even bother calling this if it determines that the
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
364 # close marker is significant (i.e. all of the branch ancestors weren't
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
365 # eliminated). Therefore if there *is* a close marker, getchanges()
69804c040a04 convert: don't drop commits that are empty in the source when using --filemap
Matt Harbison <matt_harbison@yahoo.com>
parents: 41179
diff changeset
366 # doesn't consider it significant, and this revision should be dropped.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
367 return not files and b'close' not in self.commits[rev].extra
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
368
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
369 def mark_not_wanted(self, rev, p) -> None:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
370 # Mark rev as not interesting and update data structures.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
371
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
372 if p is None:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
373 # A root revision. Use SKIPREV to indicate that it doesn't
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
374 # map to any revision in the restricted graph. Put SKIPREV
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
375 # in the set of wanted ancestors to simplify code elsewhere
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
376 self.parentmap[rev] = SKIPREV
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 29205
diff changeset
377 self.wantedancestors[rev] = {SKIPREV}
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
378 return
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
379
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
380 # Reuse the data from our parent.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
381 self.parentmap[rev] = self.parentmap[p]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
382 self.wantedancestors[rev] = self.wantedancestors[p]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
383
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
384 def mark_wanted(self, rev, parents) -> None:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
385 # Mark rev ss wanted and update data structures.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
386
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
387 # rev will be in the restricted graph, so children of rev in
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
388 # the original graph should still have rev as a parent in the
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
389 # restricted graph.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
390 self.parentmap[rev] = rev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
391
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
392 # The set of wanted ancestors of rev is the union of the sets
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
393 # of wanted ancestors of its parents. Plus rev itself.
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 7875
diff changeset
394 wrev = set()
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
395 for p in parents:
19862
42455ebbab9f convert: fix crash when filemap filtering is changed
Mads Kiilerich <madski@unity3d.com>
parents: 17797
diff changeset
396 if p in self.wantedancestors:
42455ebbab9f convert: fix crash when filemap filtering is changed
Mads Kiilerich <madski@unity3d.com>
parents: 17797
diff changeset
397 wrev.update(self.wantedancestors[p])
42455ebbab9f convert: fix crash when filemap filtering is changed
Mads Kiilerich <madski@unity3d.com>
parents: 17797
diff changeset
398 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
399 self.ui.warn(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
400 _(b'warning: %s parent %s is missing\n') % (rev, p)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
401 )
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
402 wrev.add(rev)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
403 self.wantedancestors[rev] = wrev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
404
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 20048
diff changeset
405 def getchanges(self, rev, full):
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
406 parents = self.commits[rev].parents
25742
d859123e0f47 convert: add config option for disabling ancestor parent checks
Durham Goode <durham@fb.com>
parents: 25149
diff changeset
407 if len(parents) > 1 and not self.ignoreancestorcheck:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
408 self.rebuild()
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
409
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
410 # To decide whether we're interested in rev we:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
411 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
412 # - calculate what parents rev will have if it turns out we're
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
413 # interested in it. If it's going to have more than 1 parent,
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
414 # we're interested in it.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
415 #
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
416 # - otherwise, we'll compare it with the single parent we found.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
417 # If any of the files we're interested in is different in the
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
418 # the two revisions, we're interested in rev.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
419
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
420 # A parent p is interesting if its mapped version (self.parentmap[p]):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
421 # - is not SKIPREV
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
422 # - is still not in the list of parents (we don't want duplicates)
17103
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
423 # - is not an ancestor of the mapped versions of the other parents or
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
424 # there is no parent in the same branch than the current revision.
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
425 mparents = []
17103
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
426 knownparents = set()
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
427 branch = self.commits[rev].branch
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
428 hasbranchparent = False
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
429 for i, p1 in enumerate(parents):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
430 mp1 = self.parentmap[p1]
17103
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
431 if mp1 == SKIPREV or mp1 in knownparents:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
432 continue
25742
d859123e0f47 convert: add config option for disabling ancestor parent checks
Durham Goode <durham@fb.com>
parents: 25149
diff changeset
433
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
434 isancestor = not self.ignoreancestorcheck and any(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
435 p2
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
436 for p2 in parents
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
437 if p1 != p2
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
438 and mp1 != self.parentmap[p2]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
439 and mp1 in self.wantedancestors[p2]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41180
diff changeset
440 )
17103
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
441 if not isancestor and not hasbranchparent and len(parents) > 1:
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
442 # This could be expensive, avoid unnecessary calls.
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
443 if self._cachedcommit(p1).branch == branch:
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
444 hasbranchparent = True
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
445 mparents.append((p1, mp1, i, isancestor))
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
446 knownparents.add(mp1)
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
447 # Discard parents ancestors of other parents if there is a
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
448 # non-ancestor one on the same branch than current revision.
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
449 if hasbranchparent:
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
450 mparents = [p for p in mparents if not p[3]]
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
451 wp = None
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
452 if mparents:
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
453 wp = max(p[2] for p in mparents)
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
454 mparents = [p[1] for p in mparents]
5146de7bce96 convert: keep branch switching merges with ancestors (issue3340)
Patrick Mezard <patrick@mezard.eu>
parents: 15565
diff changeset
455 elif parents:
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
456 wp = 0
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
457
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
458 self.origparents[rev] = parents
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
459
13968
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
460 closed = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
461 if b'close' in self.commits[rev].extra:
13968
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
462 # A branch closing revision is only useful if one of its
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
463 # parents belong to the branch being closed
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
464 pbranches = [self._cachedcommit(p).branch for p in mparents]
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
465 if branch in pbranches:
82845434e974 convert: make filemap prune useless branch closing revs (issue2774)
Patrick Mezard <pmezard@gmail.com>
parents: 11680
diff changeset
466 closed = True
11673
a2f11188e2d2 convert: handle closed branch heads in hg-hg conversion (issue2185)
Matt Mackall <mpm@selenic.com>
parents: 11134
diff changeset
467
a2f11188e2d2 convert: handle closed branch heads in hg-hg conversion (issue2185)
Matt Mackall <mpm@selenic.com>
parents: 11134
diff changeset
468 if len(mparents) < 2 and not closed and not self.wanted(rev, wp):
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
469 # We don't want this revision.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
470 # Update our state and tell the convert process to map this
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
471 # revision to the same revision its parent as mapped to.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
472 p = None
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
473 if parents:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
474 p = parents[wp]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
475 self.mark_not_wanted(rev, p)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
476 self.convertedorder.append((rev, False, p))
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
477 self._discard(*parents)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
478 return self.parentmap[rev]
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
479
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
480 # We want this revision.
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
481 # Rewrite the parents of the commit object
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
482 self.commits[rev].parents = mparents
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
483 self.mark_wanted(rev, parents)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
484 self.convertedorder.append((rev, True, None))
5401
4c555dd167dd convert --filemap: reduce memory usage
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5377
diff changeset
485 self._discard(*parents)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
486
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
487 # Get the real changes and do the filtering/mapping. To be
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
488 # able to get the files later on in getfile, we hide the
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
489 # original filename in the rev part of the return value.
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
490 changes, copies, cleanp2 = self.base.getchanges(rev, full)
17174
32b2e6d641e4 convert: make filemap renames consistently override revision renames
Wagner Bruna <wbruna@yahoo.com>
parents: 15565
diff changeset
491 files = {}
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
492 ncleanp2 = set(cleanp2)
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
493 for f, r in changes:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
494 newf = self.filemapper(f)
17174
32b2e6d641e4 convert: make filemap renames consistently override revision renames
Wagner Bruna <wbruna@yahoo.com>
parents: 15565
diff changeset
495 if newf and (newf != f or newf not in files):
32b2e6d641e4 convert: make filemap renames consistently override revision renames
Wagner Bruna <wbruna@yahoo.com>
parents: 15565
diff changeset
496 files[newf] = (f, r)
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
497 if newf != f:
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
498 ncleanp2.discard(f)
17174
32b2e6d641e4 convert: make filemap renames consistently override revision renames
Wagner Bruna <wbruna@yahoo.com>
parents: 15565
diff changeset
499 files = sorted(files.items())
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
500
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
501 ncopies = {}
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
502 for c in copies:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
503 newc = self.filemapper(c)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
504 if newc:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
505 newsource = self.filemapper(copies[c])
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
506 if newsource:
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
507 ncopies[newc] = newsource
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
508
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 22300
diff changeset
509 return files, ncopies, ncleanp2
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
510
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
511 def targetfilebelongstosource(self, targetfilename: bytes) -> bool:
26036
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
512 return self.filemapper.istargetfile(targetfilename)
db677b70a298 convert: implements targetfilebelongstosource for filemap source
Durham Goode <durham@fb.com>
parents: 25742
diff changeset
513
5377
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
514 def getfile(self, name, rev):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
515 realname, realrev = rev
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
516 return self.base.getfile(realname, realrev)
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
517
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
518 def gettags(self):
756a43a30e34 convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5376
diff changeset
519 return self.base.gettags()
8691
a0a541d6fed6 convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents: 8225
diff changeset
520
51685
0eb515c7bec8 typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
521 def hasnativeorder(self) -> bool:
8691
a0a541d6fed6 convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents: 8225
diff changeset
522 return self.base.hasnativeorder()
8693
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
523
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
524 def lookuprev(self, rev):
68e0a55eee6e convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents: 8691
diff changeset
525 return self.base.lookuprev(rev)
15107
2433525a9e1e convert: added bookmarks support in filemap
etienne <etienne.desautels@gmail.com>
parents: 13968
diff changeset
526
2433525a9e1e convert: added bookmarks support in filemap
etienne <etienne.desautels@gmail.com>
parents: 13968
diff changeset
527 def getbookmarks(self):
2433525a9e1e convert: added bookmarks support in filemap
etienne <etienne.desautels@gmail.com>
parents: 13968
diff changeset
528 return self.base.getbookmarks()
19892
77872b002e73 convert: update source shamap when using filemap, just as when not using filemap
Mads Kiilerich <madski@unity3d.com>
parents: 19863
diff changeset
529
77872b002e73 convert: update source shamap when using filemap, just as when not using filemap
Mads Kiilerich <madski@unity3d.com>
parents: 19863
diff changeset
530 def converted(self, rev, sinkrev):
77872b002e73 convert: update source shamap when using filemap, just as when not using filemap
Mads Kiilerich <madski@unity3d.com>
parents: 19863
diff changeset
531 self.base.converted(rev, sinkrev)