author | Martin von Zweigbergk <martinvonz@google.com> |
Fri, 11 Oct 2019 00:03:10 -0700 | |
changeset 43246 | 0fd47eb508c6 |
parent 43077 | 687b865b95ad |
child 43807 | be8552f25cab |
permissions | -rw-r--r-- |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
1 |
# Perforce source for convert extension. |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
2 |
# |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
3 |
# Copyright 2009, Frank Kingswood <frank@kingswood-consulting.co.uk> |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
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. |
28371
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
7 |
from __future__ import absolute_import |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
8 |
|
28371
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
9 |
import marshal |
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
10 |
import re |
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
11 |
|
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28371
diff
changeset
|
12 |
from mercurial.i18n import _ |
28371
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
13 |
from mercurial import ( |
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
14 |
error, |
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
15 |
util, |
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
16 |
) |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
17 |
from mercurial.utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
18 |
dateutil, |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
19 |
procutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
20 |
stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36636
diff
changeset
|
21 |
) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
22 |
|
28371
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
23 |
from . import common |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
24 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
25 |
|
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
26 |
def loaditer(f): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
27 |
b"Yield the dictionary objects generated by p4" |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
28 |
try: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
29 |
while True: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
30 |
d = marshal.load(f) |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
31 |
if not d: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
32 |
break |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
33 |
yield d |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
34 |
except EOFError: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
35 |
pass |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
36 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
37 |
|
25788
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
38 |
def decodefilename(filename): |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
39 |
"""Perforce escapes special characters @, #, *, or % |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
40 |
with %40, %23, %2A, or %25 respectively |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
41 |
|
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
31595
diff
changeset
|
42 |
>>> decodefilename(b'portable-net45%252Bnetcore45%252Bwp8%252BMonoAndroid') |
25788
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
43 |
'portable-net45%2Bnetcore45%2Bwp8%2BMonoAndroid' |
34146
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
31595
diff
changeset
|
44 |
>>> decodefilename(b'//Depot/Directory/%2525/%2523/%23%40.%2A') |
25788
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
45 |
'//Depot/Directory/%25/%23/#@.*' |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
46 |
""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
47 |
replacements = [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
48 |
(b'%2A', b'*'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 |
(b'%23', b'#'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
50 |
(b'%40', b'@'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 |
(b'%25', b'%'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 |
] |
25788
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
53 |
for k, v in replacements: |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
54 |
filename = filename.replace(k, v) |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
55 |
return filename |
a36fd0993522
convert: unescape Perforce-escaped special characters in filenames
Eugene Baranov <eug.baranov@gmail.com>
parents:
25776
diff
changeset
|
56 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
57 |
|
28371
630f5f04bc74
convert: p4 use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
58 |
class p4_source(common.converter_source): |
35187
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34988
diff
changeset
|
59 |
def __init__(self, ui, repotype, path, revs=None): |
34988
281214150561
convert: avoid wrong lfconvert defaults by moving configitems to core
Matt Harbison <matt_harbison@yahoo.com>
parents:
34503
diff
changeset
|
60 |
# avoid import cycle |
281214150561
convert: avoid wrong lfconvert defaults by moving configitems to core
Matt Harbison <matt_harbison@yahoo.com>
parents:
34503
diff
changeset
|
61 |
from . import convcmd |
281214150561
convert: avoid wrong lfconvert defaults by moving configitems to core
Matt Harbison <matt_harbison@yahoo.com>
parents:
34503
diff
changeset
|
62 |
|
35187
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34988
diff
changeset
|
63 |
super(p4_source, self).__init__(ui, repotype, path, revs=revs) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
64 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 |
if b"/" in path and not path.startswith(b'//'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
66 |
raise common.NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
67 |
_(b'%s does not look like a P4 repository') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
68 |
) |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7905
diff
changeset
|
69 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 |
common.checktool(b'p4', abort=False) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
71 |
|
30606
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
72 |
self.revmap = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
73 |
self.encoding = self.ui.config( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
74 |
b'convert', b'p4.encoding', convcmd.orig_encoding |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
75 |
) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
76 |
self.re_type = re.compile( |
41551
fc09aafd3c36
convert: use raw string for regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37123
diff
changeset
|
77 |
br"([a-z]+)?(text|binary|symlink|apple|resource|unicode|utf\d+)" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
78 |
br"(\+\w+)?$" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
79 |
) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
80 |
self.re_keywords = re.compile( |
41551
fc09aafd3c36
convert: use raw string for regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37123
diff
changeset
|
81 |
br"\$(Id|Header|Date|DateTime|Change|File|Revision|Author)" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
82 |
br":[^$\n]*\$" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
83 |
) |
41551
fc09aafd3c36
convert: use raw string for regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37123
diff
changeset
|
84 |
self.re_keywords_old = re.compile(br"\$(Id|Header):[^$\n]*\$") |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
85 |
|
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
24395
diff
changeset
|
86 |
if revs and len(revs) > 1: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
87 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
88 |
_( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
89 |
b"p4 source does not support specifying " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
90 |
b"multiple revisions" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
91 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
92 |
) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
93 |
|
30606
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
94 |
def setrevmap(self, revmap): |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
95 |
"""Sets the parsed revmap dictionary. |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
96 |
|
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
97 |
Revmap stores mappings from a source revision to a target revision. |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
98 |
It is set in convertcmd.convert and provided by the user as a file |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
99 |
on the commandline. |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
100 |
|
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
101 |
Revisions in the map are considered beeing present in the |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
102 |
repository and ignored during _parse(). This allows for incremental |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
103 |
imports if a revmap is provided. |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
104 |
""" |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
105 |
self.revmap = revmap |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
106 |
|
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
107 |
def _parse_view(self, path): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
108 |
b"Read changes affecting the path" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
109 |
cmd = b'p4 -G changes -s submitted %s' % procutil.shellquote(path) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
110 |
stdout = procutil.popen(cmd, mode=b'rb') |
30634
e92776c00ffd
convert: use return value in parse_view() instead of manipulating state
David Soria Parra <davidsp@fb.com>
parents:
30622
diff
changeset
|
111 |
p4changes = {} |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
112 |
for d in loaditer(stdout): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
113 |
c = d.get(b"change", None) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
114 |
if c: |
30634
e92776c00ffd
convert: use return value in parse_view() instead of manipulating state
David Soria Parra <davidsp@fb.com>
parents:
30622
diff
changeset
|
115 |
p4changes[c] = True |
e92776c00ffd
convert: use return value in parse_view() instead of manipulating state
David Soria Parra <davidsp@fb.com>
parents:
30622
diff
changeset
|
116 |
return p4changes |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
117 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
118 |
def _parse(self, ui, path): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 |
b"Prepare list of P4 filenames and revisions to import" |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
120 |
p4changes = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
121 |
changeset = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
122 |
files_map = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
123 |
copies_map = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
124 |
localname = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
125 |
depotname = {} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
126 |
heads = [] |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
127 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
128 |
ui.status(_(b'reading p4 views\n')) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
129 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
130 |
# read client spec or view |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
131 |
if b"/" in path: |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
132 |
p4changes.update(self._parse_view(path)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 |
if path.startswith(b"//") and path.endswith(b"/..."): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 |
views = {path[:-3]: b""} |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
135 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 |
views = {b"//": b""} |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
137 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
138 |
cmd = b'p4 -G client -o %s' % procutil.shellquote(path) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 |
clientspec = marshal.load(procutil.popen(cmd, mode=b'rb')) |
7869
bc027d72c289
cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7823
diff
changeset
|
140 |
|
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
141 |
views = {} |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
142 |
for client in clientspec: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 |
if client.startswith(b"View"): |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
144 |
sview, cview = clientspec[client].split() |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
145 |
p4changes.update(self._parse_view(sview)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 |
if sview.endswith(b"...") and cview.endswith(b"..."): |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
147 |
sview = sview[:-3] |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
148 |
cview = cview[:-3] |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
149 |
cview = cview[2:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
150 |
cview = cview[cview.find(b"/") + 1 :] |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
151 |
views[sview] = cview |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
152 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
153 |
# list of changes that affect our source files |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
154 |
p4changes = p4changes.keys() |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
155 |
p4changes.sort(key=int) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
156 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
157 |
# list with depot pathnames, longest first |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
158 |
vieworder = views.keys() |
9039 | 159 |
vieworder.sort(key=len, reverse=True) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
160 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
161 |
# handle revision limiting |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 |
startrev = self.ui.config(b'convert', b'p4.startrev') |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
163 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
164 |
# now read the full changelists to get the list of file revisions |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 |
ui.status(_(b'collecting p4 changelists\n')) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
166 |
lastid = None |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
167 |
for change in p4changes: |
30602
fa2d2c8ac398
convert: don't use long list comprehensions
David Soria Parra <davidsp@fb.com>
parents:
29205
diff
changeset
|
168 |
if startrev and int(change) < int(startrev): |
fa2d2c8ac398
convert: don't use long list comprehensions
David Soria Parra <davidsp@fb.com>
parents:
29205
diff
changeset
|
169 |
continue |
fa2d2c8ac398
convert: don't use long list comprehensions
David Soria Parra <davidsp@fb.com>
parents:
29205
diff
changeset
|
170 |
if self.revs and int(change) > int(self.revs[0]): |
fa2d2c8ac398
convert: don't use long list comprehensions
David Soria Parra <davidsp@fb.com>
parents:
29205
diff
changeset
|
171 |
continue |
30606
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
172 |
if change in self.revmap: |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
173 |
# Ignore already present revisions, but set the parent pointer. |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
174 |
lastid = change |
d47a01bf0059
convert: allow passing in a revmap
David Soria Parra <davidsp@fb.com>
parents:
30605
diff
changeset
|
175 |
continue |
30602
fa2d2c8ac398
convert: don't use long list comprehensions
David Soria Parra <davidsp@fb.com>
parents:
29205
diff
changeset
|
176 |
|
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
177 |
if lastid: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
178 |
parents = [lastid] |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
179 |
else: |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
180 |
parents = [] |
7869
bc027d72c289
cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7823
diff
changeset
|
181 |
|
30608
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
182 |
d = self._fetch_revision(change) |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
183 |
c = self._construct_commit(d, parents) |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
184 |
|
31595
78ac8acfc4bd
convert: fix the handling of empty changlist descriptions in P4
David Soria Parra <davidsp@fb.com>
parents:
30637
diff
changeset
|
185 |
descarr = c.desc.splitlines(True) |
78ac8acfc4bd
convert: fix the handling of empty changlist descriptions in P4
David Soria Parra <davidsp@fb.com>
parents:
30637
diff
changeset
|
186 |
if len(descarr) > 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
187 |
shortdesc = descarr[0].rstrip(b'\r\n') |
31595
78ac8acfc4bd
convert: fix the handling of empty changlist descriptions in P4
David Soria Parra <davidsp@fb.com>
parents:
30637
diff
changeset
|
188 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
189 |
shortdesc = b'**empty changelist description**' |
31595
78ac8acfc4bd
convert: fix the handling of empty changlist descriptions in P4
David Soria Parra <davidsp@fb.com>
parents:
30637
diff
changeset
|
190 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
191 |
t = b'%s %s' % (c.rev, repr(shortdesc)[1:-1]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
192 |
ui.status(stringutil.ellipsis(t, 80) + b'\n') |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
193 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
194 |
files = [] |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
195 |
copies = {} |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
196 |
copiedfiles = [] |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
197 |
i = 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 |
while (b"depotFile%d" % i) in d and (b"rev%d" % i) in d: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 |
oldname = d[b"depotFile%d" % i] |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
200 |
filename = None |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
201 |
for v in vieworder: |
25776
809c3e4a9e31
convert: ignore case changes in vieworder for Perforce
Eugene Baranov <eug.baranov@gmail.com>
parents:
25775
diff
changeset
|
202 |
if oldname.lower().startswith(v.lower()): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
203 |
filename = decodefilename(views[v] + oldname[len(v) :]) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
204 |
break |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
205 |
if filename: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
206 |
files.append((filename, d[b"rev%d" % i])) |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
207 |
depotname[filename] = oldname |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 |
if d.get(b"action%d" % i) == b"move/add": |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
209 |
copiedfiles.append(filename) |
30635
3830f8806094
convert: move localname state to function scope
David Soria Parra <davidsp@fb.com>
parents:
30634
diff
changeset
|
210 |
localname[oldname] = filename |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
211 |
i += 1 |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
212 |
|
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
213 |
# Collect information about copied files |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
214 |
for filename in copiedfiles: |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
215 |
oldname = depotname[filename] |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
216 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 |
flcmd = b'p4 -G filelog %s' % procutil.shellquote(oldname) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
218 |
flstdout = procutil.popen(flcmd, mode=b'rb') |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
219 |
|
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
220 |
copiedfilename = None |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
221 |
for d in loaditer(flstdout): |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
222 |
copiedoldname = None |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
223 |
|
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
224 |
i = 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
225 |
while (b"change%d" % i) in d: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
226 |
if ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 |
d[b"change%d" % i] == change |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 |
and d[b"action%d" % i] == b"move/add" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
229 |
): |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
230 |
j = 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
231 |
while (b"file%d,%d" % (i, j)) in d: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
232 |
if d[b"how%d,%d" % (i, j)] == b"moved from": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
233 |
copiedoldname = d[b"file%d,%d" % (i, j)] |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
234 |
break |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
235 |
j += 1 |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
236 |
i += 1 |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
237 |
|
30635
3830f8806094
convert: move localname state to function scope
David Soria Parra <davidsp@fb.com>
parents:
30634
diff
changeset
|
238 |
if copiedoldname and copiedoldname in localname: |
3830f8806094
convert: move localname state to function scope
David Soria Parra <davidsp@fb.com>
parents:
30634
diff
changeset
|
239 |
copiedfilename = localname[copiedoldname] |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
240 |
break |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
241 |
|
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
242 |
if copiedfilename: |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
243 |
copies[filename] = copiedfilename |
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
244 |
else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
245 |
ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 |
_(b"cannot find source for copied file: %s@%s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
247 |
% (filename, change) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
248 |
) |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
249 |
|
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
250 |
changeset[change] = c |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
251 |
files_map[change] = files |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
252 |
copies_map[change] = copies |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
253 |
lastid = change |
7869
bc027d72c289
cleanup: remove all trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7823
diff
changeset
|
254 |
|
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
255 |
if lastid and len(changeset) > 0: |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
256 |
heads = [lastid] |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
257 |
|
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
258 |
return { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
259 |
b'changeset': changeset, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
260 |
b'files': files_map, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 |
b'copies': copies_map, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
262 |
b'heads': heads, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
263 |
b'depotname': depotname, |
30636
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
264 |
} |
c2be48e56d59
convert: return calculated values from parse() instead of manpulating state
David Soria Parra <davidsp@fb.com>
parents:
30635
diff
changeset
|
265 |
|
30637
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
266 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
267 |
def _parse_once(self): |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
268 |
return self._parse(self.ui, self.path) |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
269 |
|
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
270 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
271 |
def copies(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
272 |
return self._parse_once[b'copies'] |
30637
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
273 |
|
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
274 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
275 |
def files(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 |
return self._parse_once[b'files'] |
30637
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
277 |
|
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
278 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
279 |
def changeset(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
280 |
return self._parse_once[b'changeset'] |
30637
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
281 |
|
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
282 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
283 |
def heads(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
284 |
return self._parse_once[b'heads'] |
30637
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
285 |
|
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
286 |
@util.propertycache |
1d0e4832e616
convert: parse perforce data on-demand
David Soria Parra <davidsp@fb.com>
parents:
30636
diff
changeset
|
287 |
def depotname(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
288 |
return self._parse_once[b'depotname'] |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
289 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
290 |
def getheads(self): |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
291 |
return self.heads |
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
292 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
293 |
def getfile(self, name, rev): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
294 |
cmd = b'p4 -G print %s' % procutil.shellquote( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
295 |
b"%s#%s" % (self.depotname[name], rev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
296 |
) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
297 |
|
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
298 |
lasterror = None |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
299 |
while True: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
300 |
stdout = procutil.popen(cmd, mode=b'rb') |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
301 |
|
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
302 |
mode = None |
25882
97a9f7602014
convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents:
25805
diff
changeset
|
303 |
contents = [] |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
304 |
keywords = None |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
305 |
|
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
306 |
for d in loaditer(stdout): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 |
code = d[b"code"] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
308 |
data = d.get(b"data") |
8829
ce4b92f5cea7
convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
8225
diff
changeset
|
309 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
310 |
if code == b"error": |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
311 |
# if this is the first time error happened |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
312 |
# re-attempt getting the file |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
313 |
if not lasterror: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 |
lasterror = IOError(d[b"generic"], data) |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
315 |
# this will exit inner-most for-loop |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
316 |
break |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
317 |
else: |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
318 |
raise lasterror |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8829
diff
changeset
|
319 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
320 |
elif code == b"stat": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
321 |
action = d.get(b"action") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
322 |
if action in [b"purge", b"delete", b"move/delete"]: |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
323 |
return None, None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 |
p4type = self.re_type.match(d[b"type"]) |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
325 |
if p4type: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
326 |
mode = b"" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
327 |
flags = (p4type.group(1) or b"") + ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
328 |
p4type.group(3) or b"" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
329 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
330 |
if b"x" in flags: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
331 |
mode = b"x" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
332 |
if p4type.group(2) == b"symlink": |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
333 |
mode = b"l" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
334 |
if b"ko" in flags: |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
335 |
keywords = self.re_keywords_old |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
336 |
elif b"k" in flags: |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
337 |
keywords = self.re_keywords |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8829
diff
changeset
|
338 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
339 |
elif code == b"text" or code == b"binary": |
25882
97a9f7602014
convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents:
25805
diff
changeset
|
340 |
contents.append(data) |
25775
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
341 |
|
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
342 |
lasterror = None |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
343 |
|
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
344 |
if not lasterror: |
220d9ae6a9a8
convert: if getting a file from Perforce fails try to get it one more time
Eugene Baranov <eug.baranov@gmail.com>
parents:
25760
diff
changeset
|
345 |
break |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
346 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
347 |
if mode is None: |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
22294
diff
changeset
|
348 |
return None, None |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
349 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 |
contents = b''.join(contents) |
25882
97a9f7602014
convert: when getting file from Perforce concatenate data at the end
Eugene Baranov <eug.baranov@gmail.com>
parents:
25805
diff
changeset
|
351 |
|
8829
ce4b92f5cea7
convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
8225
diff
changeset
|
352 |
if keywords: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 |
contents = keywords.sub(b"$\\1$", contents) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 |
if mode == b"l" and contents.endswith(b"\n"): |
8829
ce4b92f5cea7
convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
8225
diff
changeset
|
355 |
contents = contents[:-1] |
ce4b92f5cea7
convert: Make P4 conversion cope with keywords, binary files and symbolic links.
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
8225
diff
changeset
|
356 |
|
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
357 |
return contents, mode |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
358 |
|
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
359 |
def getchanges(self, rev, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
360 |
if full: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
361 |
raise error.Abort(_(b"convert from p4 does not support --full")) |
25751
17a9da909186
convert: handle copies when converting from Perforce (issue4744)
Eugene Baranov <eug.baranov@gmail.com>
parents:
25748
diff
changeset
|
362 |
return self.files[rev], self.copies[rev], set() |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
363 |
|
30608
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
364 |
def _construct_commit(self, obj, parents=None): |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
365 |
""" |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
366 |
Constructs a common.commit object from an unmarshalled |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
367 |
`p4 describe` output |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
368 |
""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
369 |
desc = self.recode(obj.get(b"desc", b"")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 |
date = (int(obj[b"time"]), 0) # timezone not set |
30608
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
371 |
if parents is None: |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
372 |
parents = [] |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
373 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
374 |
return common.commit( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
375 |
author=self.recode(obj[b"user"]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 |
date=dateutil.datestr(date, b'%Y-%m-%d %H:%M:%S %1%2'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
377 |
parents=parents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
378 |
desc=desc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
379 |
branch=None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 |
rev=obj[b'change'], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
381 |
extra={b"p4": obj[b'change'], b"convert_revision": obj[b'change']}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
382 |
) |
30608
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
383 |
|
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
384 |
def _fetch_revision(self, rev): |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
385 |
"""Return an output of `p4 describe` including author, commit date as |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
386 |
a dictionary.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
387 |
cmd = b"p4 -G describe -s %s" % rev |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
388 |
stdout = procutil.popen(cmd, mode=b'rb') |
30608
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
389 |
return marshal.load(stdout) |
db9e883566e8
convert: encapsulate commit data fetching and commit object creation
David Soria Parra <davidsp@fb.com>
parents:
30607
diff
changeset
|
390 |
|
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
391 |
def getcommit(self, rev): |
30609
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
392 |
if rev in self.changeset: |
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
393 |
return self.changeset[rev] |
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
394 |
elif rev in self.revmap: |
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
395 |
d = self._fetch_revision(rev) |
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
396 |
return self._construct_commit(d, parents=None) |
b654112a0119
convert: return commit objects for revisions in the revmap
David Soria Parra <davidsp@fb.com>
parents:
30608
diff
changeset
|
397 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
398 |
_(b"cannot find %s in the revmap or parsed changesets") % rev |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41768
diff
changeset
|
399 |
) |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
400 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
401 |
def gettags(self): |
30604
902c89df94e3
convert: remove unused dictionaries
David Soria Parra <davidsp@fb.com>
parents:
30603
diff
changeset
|
402 |
return {} |
7823
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
403 |
|
11efa41037e2
convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
diff
changeset
|
404 |
def getchangedfiles(self, rev, i): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8066
diff
changeset
|
405 |
return sorted([x[0] for x in self.files[rev]]) |