Mercurial > public > mercurial-scm > hg
annotate hgext/convert/common.py @ 53042:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 3e84e001b6c1 |
children |
rev | line source |
---|---|
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
1 # common.py - common code for the convert extension |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
45942
diff
changeset
|
3 # Copyright 2005-2009 Olivia Mackall <olivia@selenic.com> and others |
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
4 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
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. |
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
7 |
51859
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51683
diff
changeset
|
8 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51683
diff
changeset
|
9 |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
10 import base64 |
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
11 import os |
48870
df56e6bd37f6
py3: use pickle directly
Gregory Szorc <gregory.szorc@gmail.com>
parents:
46819
diff
changeset
|
12 import pickle |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
13 import re |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
14 import shlex |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
15 import subprocess |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
16 import typing |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
17 |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
18 from typing import ( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
19 Any, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
20 AnyStr, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
21 Optional, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
22 ) |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
23 |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28900
diff
changeset
|
24 from mercurial.i18n import _ |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
25 from mercurial import ( |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
30659
diff
changeset
|
26 encoding, |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
27 error, |
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
28 phases, |
36329
93943eef696f
py3: use pycompat.byteskwargs in hgext/convert/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36148
diff
changeset
|
29 pycompat, |
28410
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
30 util, |
48b04018c897
convert: common use absolute_import
timeless <timeless@mozdev.org>
parents:
26587
diff
changeset
|
31 ) |
51680
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
32 from mercurial.utils import ( |
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
33 dateutil, |
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
34 procutil, |
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
35 ) |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
36 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
37 if typing.TYPE_CHECKING: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
38 from typing import ( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
39 overload, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
40 ) |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
41 from mercurial import ( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
42 ui as uimod, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
43 ) |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
44 |
15606
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
45 propertycache = util.propertycache |
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
46 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
47 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
48 if typing.TYPE_CHECKING: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
49 |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
50 @overload |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
51 def _encodeornone(d: str) -> bytes: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
52 pass |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
53 |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
54 @overload |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
55 def _encodeornone(d: None) -> None: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
56 pass |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
57 |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
58 |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
59 def _encodeornone(d): |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
60 if d is None: |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
61 return |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
62 return d.encode('latin1') |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
63 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
64 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48941
diff
changeset
|
65 class _shlexpy3proxy: |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
66 def __init__(self, l: shlex.shlex) -> None: |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
67 self._l = l |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
68 |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
69 def __iter__(self): |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
70 return (_encodeornone(v) for v in self._l) |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
71 |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
72 def get_token(self): |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
73 return _encodeornone(self._l.get_token()) |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
74 |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
75 @property |
51682
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
76 def infile(self) -> bytes: |
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
77 if self._l.infile is not None: |
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
78 return encoding.strtolocal(self._l.infile) |
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
79 return b'<unknown>' |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
80 |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
81 @property |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
82 def lineno(self) -> int: |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
83 return self._l.lineno |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
84 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
85 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
86 def shlexer( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
87 data=None, |
51682
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
88 filepath: Optional[bytes] = None, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
89 wordchars: Optional[bytes] = None, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
90 whitespace: Optional[bytes] = None, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
91 ): |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
92 if data is None: |
52656
3e84e001b6c1
pyupgrade: drop redundant `open()` modes
Matt Harbison <matt_harbison@yahoo.com>
parents:
52645
diff
changeset
|
93 data = open(filepath, encoding='latin1') |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
94 else: |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
95 if filepath is not None: |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
96 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 b'shlexer only accepts data or filepath, not both' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
98 ) |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
99 data = data.decode('latin1') |
51682
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
100 infile = encoding.strfromlocal(filepath) if filepath is not None else None |
39033e7a6e0a
convert: stringify `shlex` class argument
Matt Harbison <matt_harbison@yahoo.com>
parents:
51681
diff
changeset
|
101 l = shlex.shlex(data, infile=infile, posix=True) |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
102 if whitespace is not None: |
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
103 l.whitespace_split = True |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
104 l.whitespace += whitespace.decode('latin1') |
36557
d60430dc7853
convert: add some utility code for working with shlex on Python 3
Augie Fackler <augie@google.com>
parents:
36457
diff
changeset
|
105 if wordchars is not None: |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
106 l.wordchars += wordchars.decode('latin1') |
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
107 return _shlexpy3proxy(l) |
44967
de7bdb0e2a95
py3: suppress DeprecationWarning about deprecated base64 module aliases
Manuel Jacob <me@manueljacob.de>
parents:
44964
diff
changeset
|
108 |
de7bdb0e2a95
py3: suppress DeprecationWarning about deprecated base64 module aliases
Manuel Jacob <me@manueljacob.de>
parents:
44964
diff
changeset
|
109 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
110 def encodeargs(args: Any) -> bytes: |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
111 def encodearg(s: bytes) -> bytes: |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
112 lines = base64.encodebytes(s) |
44964
d96d8bbbedb1
py3: fix bytes iteration
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
113 lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
114 return b''.join(lines) |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5127
diff
changeset
|
115 |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
116 s = pickle.dumps(args) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
117 return encodearg(s) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
118 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
119 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
120 def decodeargs(s: bytes) -> Any: |
49288
ef5f5f1cbd90
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
121 s = base64.decodebytes(s) |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
122 return pickle.loads(s) |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
123 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
124 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
125 class MissingTool(Exception): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
126 pass |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
127 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
128 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
129 def checktool( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
130 exe: bytes, name: Optional[bytes] = None, abort: bool = True |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
131 ) -> None: |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
132 name = name or exe |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
133 if not procutil.findexe(exe): |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
134 if abort: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26035
diff
changeset
|
135 exc = error.Abort |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
136 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22411
diff
changeset
|
137 exc = MissingTool |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
138 raise exc(_(b'cannot find required "%s" tool') % name) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
139 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
140 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
141 class NoRepo(Exception): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
142 pass |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
143 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
144 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
145 SKIPREV: bytes = b'SKIP' |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
146 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
147 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48941
diff
changeset
|
148 class commit: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
149 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
150 self, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
151 author: bytes, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
152 date: bytes, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
153 desc: bytes, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
154 parents, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
155 branch: Optional[bytes] = None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
156 rev=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
157 extra=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
158 sortkey=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
159 saverev=True, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
160 phase: int = phases.draft, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
161 optparents=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
162 ctx=None, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
163 ) -> None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 self.author = author or b'unknown' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 self.date = date or b'0 0' |
5024
7963438881f5
convert: empty log messages are OK as of 7f5c3fb0a37d
Bryan O'Sullivan <bos@serpentine.com>
parents:
5012
diff
changeset
|
166 self.desc = desc |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
167 self.parents = parents # will be converted and used as parents |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
168 self.optparents = optparents or [] # will be used if already converted |
5012
be25decfdb13
convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
169 self.branch = branch |
be25decfdb13
convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
170 self.rev = rev |
30659
1404146157d9
convert: don't use {} as default argument value
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30400
diff
changeset
|
171 self.extra = extra or {} |
8690
c5b4f662109f
convert: add --sourcesort option for source specific sort
Patrick Mezard <pmezard@gmail.com>
parents:
8656
diff
changeset
|
172 self.sortkey = sortkey |
25570
7cc1d33f0ba6
convert: always track the hg source revision in the internal commit object
Matt Harbison <matt_harbison@yahoo.com>
parents:
24395
diff
changeset
|
173 self.saverev = saverev |
25571
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
174 self.phase = phase |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
175 self.ctx = ctx # for hg to hg conversions |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
176 |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
177 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48941
diff
changeset
|
178 class converter_source: |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
179 """Conversion source interface""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
180 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
181 def __init__( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
182 self, |
52645
4cb75772818d
pyupgrade: drop the quoting around type annotations
Matt Harbison <matt_harbison@yahoo.com>
parents:
52643
diff
changeset
|
183 ui: uimod.ui, |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
184 repotype: bytes, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
185 path: Optional[bytes] = None, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
186 revs=None, |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
187 ) -> None: |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
188 """Initialize conversion source (or raise NoRepo("message") |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
189 exception if path is not a valid repository)""" |
4810
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
190 self.ui = ui |
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
191 self.path = path |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
192 self.revs = revs |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34369
diff
changeset
|
193 self.repotype = repotype |
4810
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
194 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 self.encoding = b'utf-8' |
4812
a5209b0487e0
convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents:
4810
diff
changeset
|
196 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
197 def checkhexformat( |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
198 self, revstr: bytes, mapname: bytes = b'splicemap' |
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
199 ) -> None: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44967
diff
changeset
|
200 """fails if revstr is not a 40 byte hex. mercurial and git both uses |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44967
diff
changeset
|
201 such format for their revision numbering |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
202 """ |
37582
39ced3ef586d
py3: add b'' prefix to make the regex bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37463
diff
changeset
|
203 if not re.match(br'[0-9a-fA-F]{40,40}$', revstr): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
204 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43105
diff
changeset
|
205 _(b'%s entry %s is not a valid revision identifier') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
206 % (mapname, revstr) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
207 ) |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
208 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
209 def before(self) -> None: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
210 pass |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
211 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
212 def after(self) -> None: |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
213 pass |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
214 |
26035
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
215 def targetfilebelongstosource(self, targetfilename): |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
216 """Returns true if the given targetfile belongs to the source repo. This |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
217 is useful when only a subdirectory of the target belongs to the source |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
218 repo.""" |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
219 # For normal full repo converts, this is always True. |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
220 return True |
86598f4fe1cf
convert: add function to test if file is from source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
221 |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
222 def setrevmap(self, revmap): |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
223 """set the map of already-converted revisions""" |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
224 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
225 def getheads(self): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
226 """Return a list of this repository's heads""" |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
227 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
228 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
229 def getfile(self, name, rev): |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
230 """Return a pair (data, mode) where data is the file content |
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
231 as a string and mode one of '', 'x' or 'l'. rev is the |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21635
diff
changeset
|
232 identifier returned by a previous call to getchanges(). |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21635
diff
changeset
|
233 Data is None if file is missing/deleted in rev. |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
234 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
235 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
236 |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
237 def getchanges(self, version, full): |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
238 """Returns a tuple of (files, copies, cleanp2). |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
239 |
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
240 files is a sorted list of (filename, id) tuples for all files |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8250
diff
changeset
|
241 changed between version and its first parent returned by |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
242 getcommit(). If full, all files in that revision is returned. |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
243 id is the source revision id of the file. |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4515
diff
changeset
|
244 |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5112
diff
changeset
|
245 copies is a dictionary of dest: source |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
246 |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
247 cleanp2 is the set of files filenames that are clean against p2. |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
248 (Files that are clean against p1 are already not in files (unless |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
249 full). This makes it possible to handle p2 clean files similarly.) |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5112
diff
changeset
|
250 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
251 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
252 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
253 def getcommit(self, version): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
254 """Return the commit object for version""" |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
255 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
256 |
22411
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
257 def numcommits(self): |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
258 """Return the number of commits in this source. |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
259 |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
260 If unknown, return None. |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
261 """ |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
262 return None |
c497e39d81a3
convert: add support for deterministic progress bar on scanning phase
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
263 |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
264 def gettags(self): |
8887
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
265 """Return the tags as a dictionary of name: revision |
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
266 |
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
267 Tag names must be UTF-8 strings. |
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
268 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
269 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
270 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
271 def recode(self, s: AnyStr, encoding: Optional[bytes] = None) -> bytes: |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
272 if not encoding: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 encoding = self.encoding or b'utf-8' |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4873
diff
changeset
|
274 |
48934
06de08b36c82
py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
275 if isinstance(s, str): |
5287
c6f932d3e0f6
Don't decode unicode strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5173
diff
changeset
|
276 return s.encode("utf-8") |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
277 try: |
37622
bfdd20d22a86
py3: make sure decode() first argument is str
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37582
diff
changeset
|
278 return s.decode(pycompat.sysstr(encoding)).encode("utf-8") |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16687
diff
changeset
|
279 except UnicodeError: |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
280 try: |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
281 return s.decode("latin-1").encode("utf-8") |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16687
diff
changeset
|
282 except UnicodeError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
283 return s.decode(pycompat.sysstr(encoding), "replace").encode( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
284 "utf-8" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
285 ) |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
286 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
287 def getchangedfiles(self, rev, i): |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
288 """Return the files changed by rev compared to parent[i]. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
289 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
290 i is an index selecting one of the parents of rev. The return |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
291 value should be the list of files that are different in rev and |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
292 this parent. |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
293 |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
294 If rev has no parents, i is None. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
295 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
296 This function is only needed to support --filemap |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
297 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
298 raise NotImplementedError |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
299 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
300 def converted(self, rev, sinkrev) -> None: |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
301 '''Notify the source that a revision has been converted.''' |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
302 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
303 def hasnativeorder(self) -> bool: |
8691
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
304 """Return true if this source has a meaningful, native revision |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
305 order. For instance, Mercurial revisions are store sequentially |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
306 while there is no such global ordering with Darcs. |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
307 """ |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
308 return False |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
309 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
310 def hasnativeclose(self) -> bool: |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44967
diff
changeset
|
311 """Return true if this source has ability to close branch.""" |
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
17974
diff
changeset
|
312 return False |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
17974
diff
changeset
|
313 |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
314 def lookuprev(self, rev): |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
315 """If rev is a meaningful revision reference in source, return |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
316 the referenced identifier in the same format used by getcommit(). |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
317 return None otherwise. |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
318 """ |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
319 return None |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
320 |
13744
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
321 def getbookmarks(self): |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
322 """Return the bookmarks as a dictionary of name: revision |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
323 |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
324 Bookmark names are to be UTF-8 strings. |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
325 """ |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
326 return {} |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
327 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
328 def checkrevformat(self, revstr, mapname: bytes = b'splicemap') -> bool: |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
329 """revstr is a string that describes a revision in the given |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44967
diff
changeset
|
330 source control system. Return true if revstr has correct |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44967
diff
changeset
|
331 format. |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
332 """ |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
333 return True |
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
19119
diff
changeset
|
334 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
335 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48941
diff
changeset
|
336 class converter_sink: |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
337 """Conversion sink (target) interface""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
338 |
52645
4cb75772818d
pyupgrade: drop the quoting around type annotations
Matt Harbison <matt_harbison@yahoo.com>
parents:
52643
diff
changeset
|
339 def __init__(self, ui: uimod.ui, repotype: bytes, path: bytes) -> None: |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
340 """Initialize conversion sink (or raise NoRepo("message") |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
341 exception if path is not a valid repository) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
342 |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
343 created is a list of paths to remove if a fatal error occurs |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
344 later""" |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
345 self.ui = ui |
5440
b4ae8535f834
convert: add default constructor for converter_sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5439
diff
changeset
|
346 self.path = path |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
347 self.created = [] |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34369
diff
changeset
|
348 self.repotype = repotype |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
349 |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4957
diff
changeset
|
350 def revmapfile(self): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
351 """Path to a file that will contain lines |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
352 source_rev_id sink_rev_id |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
353 mapping equivalent revision identifiers for each system.""" |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
354 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
355 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
356 def authorfile(self): |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
357 """Path to a file that will contain lines |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
358 srcauthor=dstauthor |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
359 mapping equivalent authors identifiers for each system.""" |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
360 return None |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
361 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
362 def putcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
363 self, files, copies, parents, commit, source, revmap, full, cleanp2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
364 ): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
365 """Create a revision with all changed files listed in 'files' |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
366 and having listed parents. 'commit' is a commit object |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
367 containing at a minimum the author, date, and message for this |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
368 changeset. 'files' is a list of (path, version) tuples, |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
369 'copies' is a dictionary mapping destinations to sources, |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
370 'source' is the source repository, and 'revmap' is a mapfile |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
371 of source revisions to converted revisions. Only getfile() and |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
372 lookuprev() should be called on 'source'. 'full' means that 'files' |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
373 is complete and all other files should be removed. |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
374 'cleanp2' is a set of the filenames that are unchanged from p2 |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
375 (only in the common merge case where there two parents). |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
376 |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
377 Note that the sink repository is not told to update itself to |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
378 a particular revision (or even what that revision would be) |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
379 before it receives the file data. |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
380 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
381 raise NotImplementedError |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
382 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
383 def puttags(self, tags): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
384 """Put tags into sink. |
8887
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
385 |
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
386 tags: {tagname: sink_rev_id, ...} where tagname is an UTF-8 string. |
9431
d1b135f2f415
convert: fix history topology when using hg.tagsbranch
Patrick Mezard <pmezard@gmail.com>
parents:
8970
diff
changeset
|
387 Return a pair (tag_revision, tag_parent_revision), or (None, None) |
d1b135f2f415
convert: fix history topology when using hg.tagsbranch
Patrick Mezard <pmezard@gmail.com>
parents:
8970
diff
changeset
|
388 if nothing was changed. |
8887
0332f8b44e54
convert/svn: test svn tags encoding
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
389 """ |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
390 raise NotImplementedError |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
391 |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
392 def setbranch(self, branch, pbranches): |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
393 """Set the current branch name. Called before the first putcommit |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
394 on the branch. |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
395 branch: branch name for subsequent commits |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
396 pbranches: (converted parent revision, parent branch) tuples""" |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
397 |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
398 def setfilemapmode(self, active): |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
399 """Tell the destination that we're using a filemap |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
400 |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
401 Some converter_sources (svn in particular) can claim that a file |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
402 was changed in a revision, even if there was no change. This method |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
403 tells the destination that we're using a filemap and that it should |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
404 filter empty revisions. |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
405 """ |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
406 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
407 def before(self) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
408 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
409 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
410 def after(self) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
411 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
412 |
13744
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
413 def putbookmarks(self, bookmarks): |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
414 """Put bookmarks into sink. |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
415 |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
416 bookmarks: {bookmarkname: sink_rev_id, ...} |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
417 where bookmarkname is an UTF-8 string. |
7e525d2f9a75
convert: add bookmark support to common sink/source implementation
Edouard Gomez <ed.gomez@free.fr>
parents:
11134
diff
changeset
|
418 """ |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
419 |
21635
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
420 def hascommitfrommap(self, rev): |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
421 """Return False if a rev mentioned in a filemap is known to not be |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
422 present.""" |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
423 raise NotImplementedError |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
424 |
21634
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21076
diff
changeset
|
425 def hascommitforsplicemap(self, rev): |
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21076
diff
changeset
|
426 """This method is for the special needs for splicemap handling and not |
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21076
diff
changeset
|
427 for general use. Returns True if the sink contains rev, aborts on some |
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21076
diff
changeset
|
428 special cases.""" |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16265
diff
changeset
|
429 raise NotImplementedError |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
16105
diff
changeset
|
430 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
431 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48941
diff
changeset
|
432 class commandline: |
52645
4cb75772818d
pyupgrade: drop the quoting around type annotations
Matt Harbison <matt_harbison@yahoo.com>
parents:
52643
diff
changeset
|
433 def __init__(self, ui: uimod.ui, command: bytes) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
434 self.ui = ui |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
435 self.command = command |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
436 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
437 def prerun(self) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
438 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
439 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
440 def postrun(self) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
441 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
442 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
443 def _cmdline(self, cmd: bytes, *args: bytes, **kwargs) -> bytes: |
36329
93943eef696f
py3: use pycompat.byteskwargs in hgext/convert/
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36148
diff
changeset
|
444 kwargs = pycompat.byteskwargs(kwargs) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
445 cmdline = [self.command, cmd] + list(args) |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
446 for k, v in kwargs.items(): |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
447 if len(k) == 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
448 cmdline.append(b'-' + k) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
449 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
450 cmdline.append(b'--' + k.replace(b'_', b'-')) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
451 try: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
452 if len(k) == 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
453 cmdline.append(b'' + v) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
454 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
455 cmdline[-1] += b'=' + v |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
456 except TypeError: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
457 pass |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
458 cmdline = [procutil.shellquote(arg) for arg in cmdline] |
7611
dafcc96c1285
convert: display child command output if --debug (fix 878466138b57)
Patrick Mezard <pmezard@gmail.com>
parents:
7610
diff
changeset
|
459 if not self.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
460 cmdline += [b'2>', pycompat.bytestr(os.devnull)] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
461 cmdline = b' '.join(cmdline) |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
462 return cmdline |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
463 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
464 def _run(self, cmd: bytes, *args: bytes, **kwargs): |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
465 def popen(cmdline): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
466 p = subprocess.Popen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
467 procutil.tonativestr(cmdline), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
468 shell=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
469 bufsize=-1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
470 close_fds=procutil.closefds, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
471 stdout=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
472 ) |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
473 return p |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
474 |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
475 return self._dorun(popen, cmd, *args, **kwargs) |
13759
49b818fd26d8
convert: add support to common commandline to access stdin of the process
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13744
diff
changeset
|
476 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
477 def _run2(self, cmd: bytes, *args: bytes, **kwargs): |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
478 return self._dorun(procutil.popen2, cmd, *args, **kwargs) |
13759
49b818fd26d8
convert: add support to common commandline to access stdin of the process
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13744
diff
changeset
|
479 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
480 def _run3(self, cmd: bytes, *args: bytes, **kwargs): |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
481 return self._dorun(procutil.popen3, cmd, *args, **kwargs) |
28662
80cac1de6aea
convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26587
diff
changeset
|
482 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
483 def _dorun(self, openfunc, cmd: bytes, *args: bytes, **kwargs): |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
484 cmdline = self._cmdline(cmd, *args, **kwargs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
485 self.ui.debug(b'running: %s\n' % (cmdline,)) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
486 self.prerun() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
487 try: |
13759
49b818fd26d8
convert: add support to common commandline to access stdin of the process
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13744
diff
changeset
|
488 return openfunc(cmdline) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
489 finally: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
490 self.postrun() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
491 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
492 def run(self, cmd: bytes, *args: bytes, **kwargs): |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
493 p = self._run(cmd, *args, **kwargs) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
494 output = p.communicate()[0] |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
495 self.ui.debug(output) |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
496 return output, p.returncode |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
497 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
498 def runlines(self, cmd: bytes, *args: bytes, **kwargs): |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
499 p = self._run(cmd, *args, **kwargs) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
500 output = p.stdout.readlines() |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
501 p.wait() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 self.ui.debug(b''.join(output)) |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
17412
diff
changeset
|
503 return output, p.returncode |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
504 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
505 def checkexit(self, status, output: bytes = b'') -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
506 if status: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
507 if output: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 self.ui.warn(_(b'%s error:\n') % self.command) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
509 self.ui.warn(output) |
37463
bbd240f81ac5
procutil: make explainexit() simply return a message (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37120
diff
changeset
|
510 msg = procutil.explainexit(status) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
511 raise error.Abort(b'%s %s' % (self.command, msg)) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
512 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
513 def run0(self, cmd: bytes, *args: bytes, **kwargs): |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
514 output, status = self.run(cmd, *args, **kwargs) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
515 self.checkexit(status, output) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
516 return output |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
517 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
518 def runlines0(self, cmd: bytes, *args: bytes, **kwargs): |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
519 output, status = self.runlines(cmd, *args, **kwargs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 self.checkexit(status, b''.join(output)) |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
521 return output |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
522 |
15606
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
523 @propertycache |
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
524 def argmax(self): |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
525 # POSIX requires at least 4096 bytes for ARG_MAX |
15606
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
526 argmax = 4096 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
527 try: |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
528 argmax = os.sysconf("SC_ARG_MAX") |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16687
diff
changeset
|
529 except (AttributeError, ValueError): |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
530 pass |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
531 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
532 # Windows shells impose their own limits on command line length, |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
533 # down to 2047 bytes for cmd.exe under Windows NT/2k and 2500 bytes |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
534 # for older 4nt.exe. See http://support.microsoft.com/kb/830473 for |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
535 # details about cmd.exe limitations. |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
536 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
537 # Since ARG_MAX is for command line _and_ environment, lower our limit |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
538 # (and make happy Windows shells while doing this). |
15791
a814f8fcc65a
Use explicit integer division
Martin Geisler <mg@aragost.com>
parents:
15611
diff
changeset
|
539 return argmax // 2 - 1 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
540 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
541 def _limit_arglist(self, arglist, cmd: bytes, *args: bytes, **kwargs): |
17412
e169b11fa1e0
convert: make commandline.limit_arglist private, simplify
Patrick Mezard <patrick@mezard.eu>
parents:
17391
diff
changeset
|
542 cmdlen = len(self._cmdline(cmd, *args, **kwargs)) |
15606
2ad4e9b44d8b
convert: simplify getargmax() with propertycache
Patrick Mezard <pmezard@gmail.com>
parents:
14271
diff
changeset
|
543 limit = self.argmax - cmdlen |
36331
e218830f6f0a
convert: don't use bytes as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36329
diff
changeset
|
544 numbytes = 0 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
545 fl = [] |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
546 for fn in arglist: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
547 b = len(fn) + 3 |
36331
e218830f6f0a
convert: don't use bytes as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36329
diff
changeset
|
548 if numbytes + b < limit or len(fl) == 0: |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
549 fl.append(fn) |
36331
e218830f6f0a
convert: don't use bytes as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36329
diff
changeset
|
550 numbytes += b |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
551 else: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
552 yield fl |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
553 fl = [fn] |
36331
e218830f6f0a
convert: don't use bytes as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36329
diff
changeset
|
554 numbytes = b |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
555 if fl: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
556 yield fl |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
557 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
558 def xargs(self, arglist, cmd: bytes, *args: bytes, **kwargs): |
17412
e169b11fa1e0
convert: make commandline.limit_arglist private, simplify
Patrick Mezard <patrick@mezard.eu>
parents:
17391
diff
changeset
|
559 for l in self._limit_arglist(arglist, cmd, *args, **kwargs): |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
560 self.run0(cmd, *(list(args) + l), **kwargs) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
561 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
562 |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
563 class mapfile(dict): |
52645
4cb75772818d
pyupgrade: drop the quoting around type annotations
Matt Harbison <matt_harbison@yahoo.com>
parents:
52643
diff
changeset
|
564 def __init__(self, ui: uimod.ui, path: bytes) -> None: |
52643
5cc8deb96b48
pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents:
52640
diff
changeset
|
565 super().__init__() |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
566 self.ui = ui |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
567 self.path = path |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
568 self.fp = None |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
569 self.order = [] |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
570 self._read() |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
571 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
572 def _read(self) -> None: |
7774
3b8f2750efcf
Handle when the slicemap option is an empty string
Stefan Rusek <stefan@rusek.org>
parents:
7611
diff
changeset
|
573 if not self.path: |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
574 return |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
575 try: |
52375
bb07b1ca23eb
convert: stop using the `pycompat.open()` shim
Matt Harbison <matt_harbison@yahoo.com>
parents:
51859
diff
changeset
|
576 fp = open(self.path, 'rb') |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49288
diff
changeset
|
577 except FileNotFoundError: |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
578 return |
51683
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
579 |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
580 try: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
581 for i, line in enumerate(fp): |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
582 line = line.splitlines()[0].rstrip() |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
583 if not line: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
584 # Ignore blank lines |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
585 continue |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
586 try: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
587 key, value = line.rsplit(b' ', 1) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
588 except ValueError: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
589 raise error.Abort( |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
590 _(b'syntax error in %s(%d): key/value pair expected') |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
591 % (self.path, i + 1) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
592 ) |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
593 if key not in self: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
594 self.order.append(key) |
52643
5cc8deb96b48
pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents:
52640
diff
changeset
|
595 super().__setitem__(key, value) |
51683
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
596 finally: |
1eab9e40c0c8
convert: fix various leaked file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
51682
diff
changeset
|
597 fp.close() |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
598 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
599 def __setitem__(self, key, value) -> None: |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
600 if self.fp is None: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
601 try: |
52375
bb07b1ca23eb
convert: stop using the `pycompat.open()` shim
Matt Harbison <matt_harbison@yahoo.com>
parents:
51859
diff
changeset
|
602 self.fp = open(self.path, 'ab') |
52640
24ee91ba9aa8
pyupgrade: drop usage of py3 aliases for `OSError`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52375
diff
changeset
|
603 except OSError as err: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
30659
diff
changeset
|
604 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
605 _(b'could not open map file %r: %s') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
606 % (self.path, encoding.strtolocal(err.strerror)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
607 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
608 self.fp.write(util.tonativeeol(b'%s %s\n' % (key, value))) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
609 self.fp.flush() |
52643
5cc8deb96b48
pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents:
52640
diff
changeset
|
610 super().__setitem__(key, value) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
611 |
51681
0eb515c7bec8
typing: add trivial type hints to the convert extension's common modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
51680
diff
changeset
|
612 def close(self) -> None: |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
613 if self.fp: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
614 self.fp.close() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
615 self.fp = None |
16105
ebaa0aa749e2
convert: turn splicemap into a simple dictionary
Patrick Mezard <patrick@mezard.eu>
parents:
15791
diff
changeset
|
616 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42620
diff
changeset
|
617 |
51680
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
618 def makedatetimestamp(t: float) -> dateutil.hgdate: |
20e2a20674dc
convert: drop a duplicate implementation of `dateutil.makedate()`
Matt Harbison <matt_harbison@yahoo.com>
parents:
50749
diff
changeset
|
619 return dateutil.makedate(t) |