annotate hgext/convert/git.py @ 52148:1dbbb957bbe6 stable

run-tests: add a --hg-wheel options to test a pre-built wheel This will be useful to test the wheel we intend to publish. A future changeset will integrate this in the CI.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 27 Oct 2024 08:54:48 +0100
parents f4733654f144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8250
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 7875
diff changeset
1 # git.py - git support for the convert extension
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 7875
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46425
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: 7875
diff changeset
4 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 7875
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8456
diff changeset
6 # GNU General Public License version 2 or any later version.
3821
158fce02dc40 Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents: 2657
diff changeset
7
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
8 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 48946
diff changeset
9
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
10 import os
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29051
diff changeset
11
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29051
diff changeset
12 from mercurial.i18n import _
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
13 from mercurial.node import sha1nodeconstants
28365
cd599bc179fb convert: git use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
14 from mercurial import (
cd599bc179fb convert: git use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
15 config,
cd599bc179fb convert: git use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
16 error,
41478
8e0dd36f7a97 git: a little pycompat.bytestring() love to make this code work in py3
Augie Fackler <augie@google.com>
parents: 37581
diff changeset
17 pycompat,
47633
770fd64a63e0 windows: use abspath in convert.git
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47128
diff changeset
18 util,
28365
cd599bc179fb convert: git use absolute_import
timeless <timeless@mozdev.org>
parents: 26779
diff changeset
19 )
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
21 from . import common
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
22
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
23
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
24 class submodule:
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
25 def __init__(self, path, node, url):
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
26 self.path = path
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
27 self.node = node
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
28 self.url = url
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
29
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
30 def hgsub(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
31 return b"%s = [git]%s" % (self.path, self.url)
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
32
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
33 def hgsubstate(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
34 return b"%s %s" % (self.node, self.path)
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
35
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
36
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
37 # Keys in extra fields that should not be copied if the user requests.
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30815
diff changeset
38 bannedextrakeys = {
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
39 # Git commit object built-ins.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
40 b'tree',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
41 b'parent',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
42 b'author',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
43 b'committer',
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
44 # Mercurial built-ins.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
45 b'branch',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
46 b'close',
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30815
diff changeset
47 }
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
48
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
49
28670
ff0d3b6b287f merge with stable
Matt Mackall <mpm@selenic.com>
parents: 28365 28662
diff changeset
50 class convert_git(common.converter_source, common.commandline):
5217
149742a628fd convert: fix issue702 about GIT_DIR= construct unsupported under Windows.
Patrick Mezard <pmezard@gmail.com>
parents: 5216
diff changeset
51 # Windows does not support GIT_DIR= construct while other systems
149742a628fd convert: fix issue702 about GIT_DIR= construct unsupported under Windows.
Patrick Mezard <pmezard@gmail.com>
parents: 5216
diff changeset
52 # cannot remove environment variable. Just assume none have
149742a628fd convert: fix issue702 about GIT_DIR= construct unsupported under Windows.
Patrick Mezard <pmezard@gmail.com>
parents: 5216
diff changeset
53 # both issues.
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
54
28659
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
55 def _gitcmd(self, cmd, *args, **kwargs):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
56 return cmd(b'--git-dir=%s' % self.path, *args, **kwargs)
28659
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
57
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
58 def gitrun0(self, *args, **kwargs):
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
59 return self._gitcmd(self.run0, *args, **kwargs)
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
60
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
61 def gitrun(self, *args, **kwargs):
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
62 return self._gitcmd(self.run, *args, **kwargs)
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
63
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
64 def gitrunlines0(self, *args, **kwargs):
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
65 return self._gitcmd(self.runlines0, *args, **kwargs)
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
66
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
67 def gitrunlines(self, *args, **kwargs):
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
68 return self._gitcmd(self.runlines, *args, **kwargs)
197eed39e3d5 convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 26779
diff changeset
69
28662
80cac1de6aea convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28661
diff changeset
70 def gitpipe(self, *args, **kwargs):
80cac1de6aea convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28661
diff changeset
71 return self._gitcmd(self._run3, *args, **kwargs)
80cac1de6aea convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28661
diff changeset
72
35176
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 34164
diff changeset
73 def __init__(self, ui, repotype, path, revs=None):
671aba341d90 convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents: 34164
diff changeset
74 super(convert_git, self).__init__(ui, repotype, path, revs=revs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
75 common.commandline.__init__(self, ui, b'git')
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25699
diff changeset
76
29051
a56296f55a5e convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents: 28817
diff changeset
77 # Pass an absolute path to git to prevent from ever being interpreted
a56296f55a5e convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents: 28817
diff changeset
78 # as a URL
47633
770fd64a63e0 windows: use abspath in convert.git
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47128
diff changeset
79 path = util.abspath(path)
29051
a56296f55a5e convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents: 28817
diff changeset
80
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
81 if os.path.isdir(path + b"/.git"):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
82 path += b"/.git"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
83 if not os.path.exists(path + b"/objects"):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
84 raise common.NoRepo(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
85 _(b"%s does not look like a Git repository") % path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
86 )
5497
f0a3918abd42 convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents: 5404
diff changeset
87
22512
6b6da715cb96 convert: change default for git rename detection to 50%
Siddharth Agarwal <sid0@fb.com>
parents: 22511
diff changeset
88 # The default value (50) is based on the default for 'git diff'.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
89 similarity = ui.configint(b'convert', b'git.similarity')
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
90 if similarity < 0 or similarity > 100:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
91 raise error.Abort(_(b'similarity must be between 0 and 100'))
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
92 if similarity > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
93 self.simopt = [b'-C%d%%' % similarity]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
94 findcopiesharder = ui.configbool(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 b'convert', b'git.findcopiesharder'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
96 )
22471
cc5f94db672b convert: add support to find git copies from all files in the working copy
Siddharth Agarwal <sid0@fb.com>
parents: 22470
diff changeset
97 if findcopiesharder:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
98 self.simopt.append(b'--find-copies-harder')
30646
ea3540e66fd8 convert: config option for git rename limit
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29205
diff changeset
99
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
100 renamelimit = ui.configint(b'convert', b'git.renamelimit')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
101 self.simopt.append(b'-l%d' % renamelimit)
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
102 else:
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
103 self.simopt = []
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
104
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
105 common.checktool(b'git', b'git')
5497
f0a3918abd42 convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents: 5404
diff changeset
106
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
107 self.path = path
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
108 self.submodules = []
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
109
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
110 self.catfilepipe = self.gitpipe(b'cat-file', b'--batch')
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
111
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
112 self.copyextrakeys = self.ui.configlist(b'convert', b'git.extrakeys')
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
113 banned = set(self.copyextrakeys) & bannedextrakeys
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
114 if banned:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
115 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
116 _(b'copying of extra key is forbidden: %s')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
117 % _(b', ').join(sorted(banned))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
118 )
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
119
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
120 committeractions = self.ui.configlist(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
121 b'convert', b'git.committeractions'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
122 )
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
123
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
124 messagedifferent = None
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
125 messagealways = None
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
126 for a in committeractions:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
127 if a.startswith((b'messagedifferent', b'messagealways')):
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
128 k = a
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
129 v = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
130 if b'=' in a:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
131 k, v = a.split(b'=', 1)
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
132
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
133 if k == b'messagedifferent':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
134 messagedifferent = v or b'committer:'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
135 elif k == b'messagealways':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
136 messagealways = v or b'committer:'
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
137
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
138 if messagedifferent and messagealways:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
139 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
140 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
141 b'committeractions cannot define both '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
142 b'messagedifferent and messagealways'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
143 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
144 )
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
145
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
146 dropcommitter = b'dropcommitter' in committeractions
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
147 replaceauthor = b'replaceauthor' in committeractions
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
148
30815
c5bf2e8ec18c convert: remove "replacecommitter" action
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30813
diff changeset
149 if dropcommitter and replaceauthor:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
150 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
151 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
152 b'committeractions cannot define both '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
153 b'dropcommitter and replaceauthor'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
154 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
155 )
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
156
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
157 if dropcommitter and messagealways:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
158 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
159 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
160 b'committeractions cannot define both '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
161 b'dropcommitter and messagealways'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
162 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
163 )
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
164
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
165 if not messagedifferent and not messagealways:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
166 messagedifferent = b'committer:'
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
167
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
168 self.committeractions = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
169 b'dropcommitter': dropcommitter,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
170 b'replaceauthor': replaceauthor,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
171 b'messagedifferent': messagedifferent,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
172 b'messagealways': messagealways,
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
173 }
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
174
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
175 def after(self):
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
176 for f in self.catfilepipe:
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
177 f.close()
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
178
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
179 def getheads(self):
25748
baea47cafe75 convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents: 25699
diff changeset
180 if not self.revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
181 output, status = self.gitrun(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 b'rev-parse', b'--branches', b'--remotes'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
183 )
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
184 heads = output.splitlines()
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
185 if status:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
186 raise error.Abort(_(b'cannot retrieve git heads'))
4768
f52bfe566583 convert: import all branches from git repositories
Brendan Cully <brendan@kublai.com>
parents: 4767
diff changeset
187 else:
25749
f2748cc43b2a convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents: 25748
diff changeset
188 heads = []
f2748cc43b2a convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents: 25748
diff changeset
189 for rev in self.revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
190 rawhead, ret = self.gitrun(b'rev-parse', b'--verify', rev)
25749
f2748cc43b2a convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents: 25748
diff changeset
191 heads.append(rawhead[:-1])
f2748cc43b2a convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents: 25748
diff changeset
192 if ret:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
193 raise error.Abort(_(b'cannot retrieve git head "%s"') % rev)
10986
610f047326b9 convert/git: check status when reading the whole output
Patrick Mezard <pmezard@gmail.com>
parents: 10985
diff changeset
194 return heads
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
195
36332
aefb75730ea3 convert: don't use type as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35628
diff changeset
196 def catfile(self, rev, ftype):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
197 if rev == sha1nodeconstants.nullhex:
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
198 raise IOError
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
199 self.catfilepipe[0].write(rev + b'\n')
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
200 self.catfilepipe[0].flush()
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
201 info = self.catfilepipe[1].readline().split()
36332
aefb75730ea3 convert: don't use type as a variable name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35628
diff changeset
202 if info[1] != ftype:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
203 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
204 _(b'cannot read %r object at %s')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
205 % (pycompat.bytestr(ftype), rev)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
206 )
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
207 size = int(info[2])
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
208 data = self.catfilepipe[1].read(size)
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
209 if len(data) < size:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
210 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
211 _(b'cannot read %r object at %s: unexpected size')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
212 % (ftype, rev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
213 )
21630
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
214 # read the trailing newline
a204fd9b5ba9 convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents: 20373
diff changeset
215 self.catfilepipe[1].read(1)
10986
610f047326b9 convert/git: check status when reading the whole output
Patrick Mezard <pmezard@gmail.com>
parents: 10985
diff changeset
216 return data
692
695dd9a491da convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents: 450
diff changeset
217
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
218 def getfile(self, name, rev):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
219 if rev == sha1nodeconstants.nullhex:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 21958
diff changeset
220 return None, None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
221 if name == b'.hgsub':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
222 data = b'\n'.join([m.hgsub() for m in self.submoditer()])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
223 mode = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
224 elif name == b'.hgsubstate':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
225 data = b'\n'.join([m.hgsubstate() for m in self.submoditer()])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
226 mode = b''
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
227 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
228 data = self.catfile(rev, b"blob")
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
229 mode = self.modecache[(name, rev)]
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10987
diff changeset
230 return data, mode
3956
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
231
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
232 def submoditer(self):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
233 null = sha1nodeconstants.nullhex
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
234 for m in sorted(self.submodules, key=lambda p: p.path):
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
235 if m.node != null:
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
236 yield m
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
237
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
238 def parsegitmodules(self, content):
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
239 """Parse the formatted .gitmodules file, example file format:
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
240 [submodule "sub"]\n
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
241 \tpath = sub\n
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
242 \turl = git://giturl\n
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
243 """
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
244 self.submodules = []
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
245 c = config.config()
25698
307370c2dda2 convert: handle .gitmodules with non-tab whitespaces
Durham Goode <durham@fb.com>
parents: 24395
diff changeset
246 # Each item in .gitmodules starts with whitespace that cant be parsed
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
247 c.parse(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
248 b'.gitmodules',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
249 b'\n'.join(line.strip() for line in content.split(b'\n')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
250 )
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
251 for sec in c.sections():
46425
f7621fa14b84 config: use the right API to access git-submodule
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46113
diff changeset
252 # turn the config object into a real dict
f7621fa14b84 config: use the right API to access git-submodule
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46113
diff changeset
253 s = dict(c.items(sec))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
254 if b'url' in s and b'path' in s:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
255 self.submodules.append(submodule(s[b'path'], b'', s[b'url']))
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
256
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
257 def retrievegitmodules(self, version):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
258 modules, ret = self.gitrun(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
259 b'show', b'%s:%s' % (version, b'.gitmodules')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
260 )
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
261 if ret:
25699
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
262 # This can happen if a file is in the repo that has permissions
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
263 # 160000, but there is no .gitmodules file.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
264 self.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
265 _(b"warning: cannot read submodules config file in %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
266 % version
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
267 )
25699
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
268 return
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
269
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
270 try:
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
271 self.parsegitmodules(modules)
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
272 except error.ParseError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
273 self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
274 _(b"warning: unable to parse .gitmodules in %s\n") % version
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
275 )
25699
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
276 return
5c97a4ecbdd4 convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents: 25698
diff changeset
277
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
278 for m in self.submodules:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
279 node, ret = self.gitrun(b'rev-parse', b'%s:%s' % (version, m.path))
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
280 if ret:
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
281 continue
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
282 m.node = node.strip()
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
283
22300
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
284 def getchanges(self, version, full):
35ab037de989 convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
285 if full:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
286 raise error.Abort(_(b"convert from git does not support --full"))
3956
558f52943cd2 convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents: 3954
diff changeset
287 self.modecache = {}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
288 cmd = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
289 [b'diff-tree', b'-z', b'--root', b'-m', b'-r']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
290 + self.simopt
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
291 + [version]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
292 )
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
293 output, status = self.gitrun(*cmd)
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
294 if status:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
295 raise error.Abort(_(b'cannot read changes in %s') % version)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
296 changes = []
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
297 copies = {}
8456
e9e2a2c9b294 convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8271
diff changeset
298 seen = set()
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
299 entry = None
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
300 subexists = [False]
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
301 subdeleted = [False]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
302 difftree = output.split(b'\x00')
22467
333d654783ad convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents: 22413
diff changeset
303 lcount = len(difftree)
333d654783ad convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents: 22413
diff changeset
304 i = 0
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
305
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
306 skipsubmodules = self.ui.configbool(b'convert', b'git.skipsubmodules')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
307
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
308 def add(entry, f, isdest):
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
309 seen.add(f)
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
310 h = entry[3]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
311 p = entry[1] == b"100755"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
312 s = entry[1] == b"120000"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
313 renamesource = not isdest and entry[4][0] == b'R'
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
314
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
315 if f == b'.gitmodules':
26077
e63d05fbae84 convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents: 25998
diff changeset
316 if skipsubmodules:
e63d05fbae84 convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents: 25998
diff changeset
317 return
e63d05fbae84 convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents: 25998
diff changeset
318
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
319 subexists[0] = True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
320 if entry[4] == b'D' or renamesource:
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
321 subdeleted[0] = True
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
322 changes.append((b'.hgsub', sha1nodeconstants.nullhex))
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
323 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
324 changes.append((b'.hgsub', b''))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
325 elif entry[1] == b'160000' or entry[0] == b':160000':
26077
e63d05fbae84 convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents: 25998
diff changeset
326 if not skipsubmodules:
e63d05fbae84 convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents: 25998
diff changeset
327 subexists[0] = True
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
328 else:
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
329 if renamesource:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
330 h = sha1nodeconstants.nullhex
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
331 self.modecache[(f, h)] = (p and b"x") or (s and b"l") or b""
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
332 changes.append((f, h))
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
333
22467
333d654783ad convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents: 22413
diff changeset
334 while i < lcount:
333d654783ad convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents: 22413
diff changeset
335 l = difftree[i]
333d654783ad convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents: 22413
diff changeset
336 i += 1
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
337 if not entry:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
338 if not l.startswith(b':'):
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
339 continue
41478
8e0dd36f7a97 git: a little pycompat.bytestring() love to make this code work in py3
Augie Fackler <augie@google.com>
parents: 37581
diff changeset
340 entry = tuple(pycompat.bytestr(p) for p in l.split())
5335
88e931f74e8b convert_git: avoid returning two entries for the same file in getchanges
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5220
diff changeset
341 continue
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
342 f = l
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
343 if entry[4][0] == b'C':
25997
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
344 copysrc = f
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
345 copydest = difftree[i]
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
346 i += 1
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
347 f = copydest
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
348 copies[copydest] = copysrc
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
349 if f not in seen:
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
350 add(entry, f, False)
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
351 # A file can be copied multiple times, or modified and copied
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
352 # simultaneously. So f can be repeated even if fdest isn't.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
353 if entry[4][0] == b'R':
25997
d4e1e947444b convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
354 # rename: next line is the destination
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
355 fdest = difftree[i]
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
356 i += 1
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
357 if fdest not in seen:
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
358 add(entry, fdest, True)
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
359 # .gitmodules isn't imported at all, so it being copied to
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
360 # and fro doesn't really make sense
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
361 if f != b'.gitmodules' and fdest != b'.gitmodules':
22470
8e0c4df28eec convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents: 22469
diff changeset
362 copies[fdest] = f
7242
d1dff8c492dd convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents: 7222
diff changeset
363 entry = None
17929
0eed66327ad4 convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents: 16689
diff changeset
364
22469
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
365 if subexists[0]:
15bc0431476b convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents: 22468
diff changeset
366 if subdeleted[0]:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
367 changes.append((b'.hgsubstate', sha1nodeconstants.nullhex))
21868
3420346174b1 convert: detect removal of ".gitmodules" at git source revisions correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20373
diff changeset
368 else:
3420346174b1 convert: detect removal of ".gitmodules" at git source revisions correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20373
diff changeset
369 self.retrievegitmodules(version)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
370 changes.append((b'.hgsubstate', b''))
24395
216fa1ba9993 convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents: 23206
diff changeset
371 return (changes, copies, set())
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
372
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
373 def getcommit(self, version):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
374 c = self.catfile(version, b"commit") # read the commit hash
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
375 end = c.find(b"\n\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
376 message = c[end + 2 :]
4759
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4721
diff changeset
377 message = self.recode(message)
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
378 l = c[:end].splitlines()
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
379 parents = []
8271
e3d3dad805f9 Add committer tag only when needed in git conversion
Richard Quirk <richard.quirk@gmail.com>
parents: 8250
diff changeset
380 author = committer = None
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
381 extra = {}
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
382 for e in l[1:]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
383 n, v = e.split(b" ", 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
384 if n == b"author":
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
385 p = v.split()
1385
adb3de56635b convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents: 1335
diff changeset
386 tm, tz = p[-2:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
387 author = b" ".join(p[:-2])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
388 if author[0] == b"<":
35628
ab11af15a149 style: remove multiple statement on a single line
Boris Feld <boris.feld@octobus.net>
parents: 35176
diff changeset
389 author = author[1:-1]
4759
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4721
diff changeset
390 author = self.recode(author)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
391 if n == b"committer":
431
dfc44f3f587c convert-repo fixups
mpm@selenic.com
parents: 316
diff changeset
392 p = v.split()
1385
adb3de56635b convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents: 1335
diff changeset
393 tm, tz = p[-2:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
394 committer = b" ".join(p[:-2])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
395 if committer[0] == b"<":
35628
ab11af15a149 style: remove multiple statement on a single line
Boris Feld <boris.feld@octobus.net>
parents: 35176
diff changeset
396 committer = committer[1:-1]
4759
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4721
diff changeset
397 committer = self.recode(committer)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
398 if n == b"parent":
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
399 parents.append(v)
30660
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
400 if n in self.copyextrakeys:
1f21a6835604 convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30646
diff changeset
401 extra[n] = v
1385
adb3de56635b convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents: 1335
diff changeset
402
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
403 if self.committeractions[b'dropcommitter']:
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
404 committer = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
405 elif self.committeractions[b'replaceauthor']:
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
406 author = committer
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
407
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
408 if committer:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
409 messagealways = self.committeractions[b'messagealways']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
410 messagedifferent = self.committeractions[b'messagedifferent']
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
411 if messagealways:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
412 message += b'\n%s %s\n' % (messagealways, committer)
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
413 elif messagedifferent and author != committer:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
414 message += b'\n%s %s\n' % (messagedifferent, committer)
30813
2cbbd4622ab0 convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30661
diff changeset
415
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
416 tzs, tzh, tzm = tz[-5:-4] + b"1", tz[-4:-2], tz[-2:]
2093
5cc414722587 convert-repo: fix reversed time zone offset
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1715
diff changeset
417 tz = -int(tzs) * (int(tzh) * 3600 + int(tzm))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
418 date = tm + b" " + (b"%d" % tz)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
419 saverev = self.ui.configbool(b'convert', b'git.saverev')
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
420
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
421 c = common.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
422 parents=parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
423 date=date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
424 author=author,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
425 desc=message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
426 rev=version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
427 extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
428 saverev=saverev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
429 )
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
430 return c
316
c48d069163d6 Add new convert-repo script
mpm@selenic.com
parents:
diff changeset
431
22413
3cb0318bb2dd convert: enable deterministic conversion progress bar for git
Augie Fackler <raf@durin42.com>
parents: 22300
diff changeset
432 def numcommits(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
433 output, ret = self.gitrunlines(b'rev-list', b'--all')
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
434 if ret:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
435 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
436 _(b'cannot retrieve number of commits in %s') % self.path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
437 )
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
438 return len(output)
22413
3cb0318bb2dd convert: enable deterministic conversion progress bar for git
Augie Fackler <raf@durin42.com>
parents: 22300
diff changeset
439
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
440 def gettags(self):
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
441 tags = {}
16259
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
442 alltags = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
443 output, status = self.gitrunlines(b'ls-remote', b'--tags', self.path)
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
444
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
445 if status:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
446 raise error.Abort(_(b'cannot read tags from %s') % self.path)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
447 prefix = b'refs/tags/'
16259
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
448
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
449 # Build complete list of tags, both annotated and bare ones
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
450 for line in output:
4062
516f883e3d79 convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4047
diff changeset
451 line = line.strip()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
452 if line.startswith(b"error:") or line.startswith(b"fatal:"):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
453 raise error.Abort(_(b'cannot read tags from %s') % self.path)
4062
516f883e3d79 convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4047
diff changeset
454 node, tag = line.split(None, 1)
516f883e3d79 convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4047
diff changeset
455 if not tag.startswith(prefix):
516f883e3d79 convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4047
diff changeset
456 continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
457 alltags[tag[len(prefix) :]] = node
4062
516f883e3d79 convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4047
diff changeset
458
16259
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
459 # Filter out tag objects for annotated tag refs
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
460 for tag in alltags:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
461 if tag.endswith(b'^{}'):
16259
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
462 tags[tag[:-3]] = alltags[tag]
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
463 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
464 if tag + b'^{}' in alltags:
16259
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
465 continue
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
466 else:
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
467 tags[tag] = alltags[tag]
589aab2ca716 convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 14945
diff changeset
468
694
51eb248d3348 Teach convert-repo about tags
mpm@selenic.com
parents: 692
diff changeset
469 return tags
5380
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
470
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
471 def getchangedfiles(self, version, i):
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
472 changes = []
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
473 if i is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
474 output, status = self.gitrunlines(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
475 b'diff-tree', b'--root', b'-m', b'-r', version
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
476 )
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
477 if status:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
478 raise error.Abort(_(b'cannot read changes in %s') % version)
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
479 for l in output:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
480 if b"\t" not in l:
5380
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
481 continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
482 m, f = l[:-1].split(b"\t")
5380
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
483 changes.append(f)
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
484 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
485 output, status = self.gitrunlines(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
486 b'diff-tree',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
487 b'--name-only',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
488 b'--root',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
489 b'-r',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
490 version,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
491 b'%s^%d' % (version, i + 1),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
492 b'--',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
493 )
28816
f4a42bb7c2ec convert: don't ignore errors from git diff-tree
Julien Cristau <julien.cristau@logilab.fr>
parents: 28671
diff changeset
494 if status:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
495 raise error.Abort(_(b'cannot read changes in %s') % version)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
496 changes = [f.rstrip(b'\n') for f in output]
5380
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
497
a5a7f7fd5554 convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5336
diff changeset
498 return changes
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
499
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
500 def getbookmarks(self):
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
501 bookmarks = {}
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
502
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
503 # Handle local and remote branches
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
504 remoteprefix = self.ui.config(b'convert', b'git.remoteprefix')
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
505 reftypes = [
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
506 # (git prefix, hg prefix)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
507 (b'refs/remotes/origin/', remoteprefix + b'/'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
508 (b'refs/heads/', b''),
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
509 ]
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
510
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30815
diff changeset
511 exclude = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
512 b'refs/remotes/origin/HEAD',
32291
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 30815
diff changeset
513 }
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
514
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
515 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
516 output, status = self.gitrunlines(b'show-ref')
28660
cdda7b96afff convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents: 28659
diff changeset
517 for line in output:
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
518 line = line.strip()
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
519 rev, name = line.split(None, 1)
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
520 # Process each type of branch
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
521 for gitprefix, hgprefix in reftypes:
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
522 if not name.startswith(gitprefix) or name in exclude:
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
523 continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
524 name = b'%s%s' % (hgprefix, name[len(gitprefix) :])
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
525 bookmarks[name] = rev
25905
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
526 except Exception:
80149d0b6842 convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents: 25787
diff changeset
527 pass
13756
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
528
6b7077df4aa5 convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents: 12144
diff changeset
529 return bookmarks
19121
478a04605ce1 splicemap: improve error handling when source is git (issue2084)
Ben Goswami <bengoswami@fb.com>
parents: 18572
diff changeset
530
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
531 def checkrevformat(self, revstr, mapname=b'splicemap'):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 46819
diff changeset
532 """git revision string is a 40 byte hex"""
20373
e8203629371b convert: add mapname parameter to checkrevformat
Sean Farley <sean.michael.farley@gmail.com>
parents: 19121
diff changeset
533 self.checkhexformat(revstr, mapname)