author | Boris Feld <boris.feld@octobus.net> |
Fri, 30 Jun 2017 03:34:14 +0200 | |
changeset 34162 | 15794577bcf3 |
parent 34161 | d54ebe5bb411 |
child 34163 | ed3ff1df715f |
permissions | -rw-r--r-- |
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 |
# |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
7875
diff
changeset
|
3 |
# Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
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 | 6 |
# GNU General Public License version 2 or any later version. |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
7 |
from __future__ import absolute_import |
3821
158fce02dc40
Teach convert-repo to deal with mixed charsets in git
Matt Mackall <mpm@selenic.com>
parents:
2657
diff
changeset
|
8 |
|
4536
cc9b79216a76
Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents:
4532
diff
changeset
|
9 |
import os |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
29051
diff
changeset
|
10 |
|
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
29051
diff
changeset
|
11 |
from mercurial.i18n import _ |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
12 |
from mercurial import ( |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
13 |
config, |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
14 |
error, |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
15 |
node as nodemod, |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
16 |
) |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
17 |
|
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
18 |
from . import ( |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
19 |
common, |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
20 |
) |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
21 |
|
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
22 |
class submodule(object): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
23 |
def __init__(self, path, node, url): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
24 |
self.path = path |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
25 |
self.node = node |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
26 |
self.url = url |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
27 |
|
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
28 |
def hgsub(self): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
29 |
return "%s = [git]%s" % (self.path, self.url) |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
30 |
|
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
31 |
def hgsubstate(self): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
32 |
return "%s %s" % (self.node, self.path) |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
33 |
|
30660
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
34 |
# 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
|
35 |
bannedextrakeys = { |
30660
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
36 |
# Git commit object built-ins. |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
37 |
'tree', |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
38 |
'parent', |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
39 |
'author', |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
40 |
'committer', |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
41 |
# Mercurial built-ins. |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
42 |
'branch', |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
43 |
'close', |
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
30815
diff
changeset
|
44 |
} |
30660
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
45 |
|
28670 | 46 |
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
|
47 |
# 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
|
48 |
# 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
|
49 |
# both issues. |
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
50 |
|
28659
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
51 |
def _gitcmd(self, cmd, *args, **kwargs): |
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
52 |
return cmd('--git-dir=%s' % self.path, *args, **kwargs) |
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
53 |
|
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
|
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
|
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
|
197eed39e3d5
convert: add new, non-clowny interface for shelling out to git (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
26779
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
|
28662
80cac1de6aea
convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28661
diff
changeset
|
66 |
def gitpipe(self, *args, **kwargs): |
80cac1de6aea
convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28661
diff
changeset
|
67 |
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
|
68 |
|
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25699
diff
changeset
|
69 |
def __init__(self, ui, path, revs=None): |
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25699
diff
changeset
|
70 |
super(convert_git, self).__init__(ui, path, revs=revs) |
28670 | 71 |
common.commandline.__init__(self, ui, 'git') |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25699
diff
changeset
|
72 |
|
29051
a56296f55a5e
convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents:
28817
diff
changeset
|
73 |
# 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
|
74 |
# as a URL |
a56296f55a5e
convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents:
28817
diff
changeset
|
75 |
path = os.path.abspath(path) |
a56296f55a5e
convert: pass absolute paths to git (SEC)
Blake Burkhart <bburky@bburky.com>
parents:
28817
diff
changeset
|
76 |
|
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
77 |
if os.path.isdir(path + "/.git"): |
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
78 |
path += "/.git" |
4102
06d65498f73b
convert-repo: use .git/objects/ rather than .git/HEAD to detect git repos
Matt Mackall <mpm@selenic.com>
parents:
4082
diff
changeset
|
79 |
if not os.path.exists(path + "/objects"): |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
80 |
raise common.NoRepo(_("%s does not look like a Git repository") % |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
81 |
path) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5404
diff
changeset
|
82 |
|
22512
6b6da715cb96
convert: change default for git rename detection to 50%
Siddharth Agarwal <sid0@fb.com>
parents:
22511
diff
changeset
|
83 |
# The default value (50) is based on the default for 'git diff'. |
6b6da715cb96
convert: change default for git rename detection to 50%
Siddharth Agarwal <sid0@fb.com>
parents:
22511
diff
changeset
|
84 |
similarity = ui.configint('convert', 'git.similarity', default=50) |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
85 |
if similarity < 0 or similarity > 100: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
86 |
raise error.Abort(_('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
|
87 |
if similarity > 0: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
88 |
self.simopt = ['-C%d%%' % similarity] |
34159
3e3327ced4ed
configitems: register the 'convert.git.findcopiesharder' config
Boris Feld <boris.feld@octobus.net>
parents:
34157
diff
changeset
|
89 |
findcopiesharder = ui.configbool('convert', 'git.findcopiesharder') |
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
|
90 |
if findcopiesharder: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
91 |
self.simopt.append('--find-copies-harder') |
30646
ea3540e66fd8
convert: config option for git rename limit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29205
diff
changeset
|
92 |
|
34161
d54ebe5bb411
configitems: register the 'convert.git.renamelimit' config
Boris Feld <boris.feld@octobus.net>
parents:
34160
diff
changeset
|
93 |
renamelimit = ui.configint('convert', 'git.renamelimit') |
30646
ea3540e66fd8
convert: config option for git rename limit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29205
diff
changeset
|
94 |
self.simopt.append('-l%d' % renamelimit) |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
95 |
else: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
96 |
self.simopt = [] |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
97 |
|
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
98 |
common.checktool('git', 'git') |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5404
diff
changeset
|
99 |
|
316 | 100 |
self.path = path |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
101 |
self.submodules = [] |
316 | 102 |
|
28662
80cac1de6aea
convert: rewrite gitpipe to use common.commandline (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28661
diff
changeset
|
103 |
self.catfilepipe = self.gitpipe('cat-file', '--batch') |
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
104 |
|
30660
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
105 |
self.copyextrakeys = self.ui.configlist('convert', 'git.extrakeys') |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
106 |
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
|
107 |
if banned: |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
108 |
raise error.Abort(_('copying of extra key is forbidden: %s') % |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
109 |
_(', ').join(sorted(banned))) |
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
110 |
|
34157
a608b46a5ed0
configitems: register the 'convert.git.committeractions' config
Boris Feld <boris.feld@octobus.net>
parents:
32291
diff
changeset
|
111 |
committeractions = self.ui.configlist('convert', 'git.committeractions') |
30813
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
112 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
113 |
messagedifferent = None |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
114 |
messagealways = None |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
115 |
for a in committeractions: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
116 |
if a.startswith(('messagedifferent', 'messagealways')): |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
117 |
k = a |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
118 |
v = None |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
119 |
if '=' in a: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
120 |
k, v = a.split('=', 1) |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
121 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
122 |
if k == 'messagedifferent': |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
123 |
messagedifferent = v or 'committer:' |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
124 |
elif k == 'messagealways': |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
125 |
messagealways = v or 'committer:' |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
126 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
127 |
if messagedifferent and messagealways: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
128 |
raise error.Abort(_('committeractions cannot define both ' |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
129 |
'messagedifferent and messagealways')) |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
130 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
131 |
dropcommitter = 'dropcommitter' in committeractions |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
132 |
replaceauthor = 'replaceauthor' in committeractions |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
133 |
|
30815
c5bf2e8ec18c
convert: remove "replacecommitter" action
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30813
diff
changeset
|
134 |
if dropcommitter and replaceauthor: |
30813
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
135 |
raise error.Abort(_('committeractions cannot define both ' |
30815
c5bf2e8ec18c
convert: remove "replacecommitter" action
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30813
diff
changeset
|
136 |
'dropcommitter and replaceauthor')) |
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 dropcommitter and messagealways: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
139 |
raise error.Abort(_('committeractions cannot define both ' |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
140 |
'dropcommitter and messagealways')) |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
141 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
142 |
if not messagedifferent and not messagealways: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
143 |
messagedifferent = 'committer:' |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
144 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
145 |
self.committeractions = { |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
146 |
'dropcommitter': dropcommitter, |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
147 |
'replaceauthor': replaceauthor, |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
148 |
'messagedifferent': messagedifferent, |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
149 |
'messagealways': messagealways, |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
150 |
} |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
151 |
|
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
152 |
def after(self): |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
153 |
for f in self.catfilepipe: |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
154 |
f.close() |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
155 |
|
316 | 156 |
def getheads(self): |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25699
diff
changeset
|
157 |
if not self.revs: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
158 |
output, status = self.gitrun('rev-parse', '--branches', '--remotes') |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
159 |
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
|
160 |
if status: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
161 |
raise error.Abort(_('cannot retrieve git heads')) |
4768
f52bfe566583
convert: import all branches from git repositories
Brendan Cully <brendan@kublai.com>
parents:
4767
diff
changeset
|
162 |
else: |
25749
f2748cc43b2a
convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
163 |
heads = [] |
f2748cc43b2a
convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
164 |
for rev in self.revs: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
165 |
rawhead, ret = self.gitrun('rev-parse', '--verify', rev) |
25749
f2748cc43b2a
convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
166 |
heads.append(rawhead[:-1]) |
f2748cc43b2a
convert: support multiple specifed revs in git source
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
167 |
if ret: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
168 |
raise error.Abort(_('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
|
169 |
return heads |
316 | 170 |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
171 |
def catfile(self, rev, type): |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
172 |
if rev == nodemod.nullhex: |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
173 |
raise IOError |
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
174 |
self.catfilepipe[0].write(rev+'\n') |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
175 |
self.catfilepipe[0].flush() |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
176 |
info = self.catfilepipe[1].readline().split() |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
177 |
if info[1] != type: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
178 |
raise error.Abort(_('cannot read %r object at %s') % (type, rev)) |
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
179 |
size = int(info[2]) |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
180 |
data = self.catfilepipe[1].read(size) |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
181 |
if len(data) < size: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
182 |
raise error.Abort(_('cannot read %r object at %s: unexpected size') |
21958
9663a7855798
convert: fix argument mismatch at formatting the abort message
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21873
diff
changeset
|
183 |
% (type, rev)) |
21630
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
184 |
# read the trailing newline |
a204fd9b5ba9
convert: drastically speed up git conversions
David Schleimer <dschleimer@fb.com>
parents:
20373
diff
changeset
|
185 |
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
|
186 |
return data |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
187 |
|
316 | 188 |
def getfile(self, name, rev): |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
189 |
if rev == nodemod.nullhex: |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21958
diff
changeset
|
190 |
return None, None |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
191 |
if name == '.hgsub': |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
192 |
data = '\n'.join([m.hgsub() for m in self.submoditer()]) |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
193 |
mode = '' |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
194 |
elif name == '.hgsubstate': |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
195 |
data = '\n'.join([m.hgsubstate() for m in self.submoditer()]) |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
196 |
mode = '' |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
197 |
else: |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
198 |
data = self.catfile(rev, "blob") |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
199 |
mode = self.modecache[(name, rev)] |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10987
diff
changeset
|
200 |
return data, mode |
3956
558f52943cd2
convert-repo: add CVS exec bit support
Matt Mackall <mpm@selenic.com>
parents:
3954
diff
changeset
|
201 |
|
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
202 |
def submoditer(self): |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
203 |
null = nodemod.nullhex |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
204 |
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
|
205 |
if m.node != null: |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
206 |
yield m |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
207 |
|
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
208 |
def parsegitmodules(self, content): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
209 |
"""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
|
210 |
[submodule "sub"]\n |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
211 |
\tpath = sub\n |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
212 |
\turl = git://giturl\n |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
213 |
""" |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
214 |
self.submodules = [] |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
215 |
c = config.config() |
25698
307370c2dda2
convert: handle .gitmodules with non-tab whitespaces
Durham Goode <durham@fb.com>
parents:
24395
diff
changeset
|
216 |
# Each item in .gitmodules starts with whitespace that cant be parsed |
307370c2dda2
convert: handle .gitmodules with non-tab whitespaces
Durham Goode <durham@fb.com>
parents:
24395
diff
changeset
|
217 |
c.parse('.gitmodules', '\n'.join(line.strip() for line in |
307370c2dda2
convert: handle .gitmodules with non-tab whitespaces
Durham Goode <durham@fb.com>
parents:
24395
diff
changeset
|
218 |
content.split('\n'))) |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
219 |
for sec in c.sections(): |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
220 |
s = c[sec] |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
221 |
if 'url' in s and 'path' in s: |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
222 |
self.submodules.append(submodule(s['path'], '', s['url'])) |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
223 |
|
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
224 |
def retrievegitmodules(self, version): |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
225 |
modules, ret = self.gitrun('show', '%s:%s' % (version, '.gitmodules')) |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
226 |
if ret: |
25699
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
227 |
# 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
|
228 |
# 160000, but there is no .gitmodules file. |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
229 |
self.ui.warn(_("warning: cannot read submodules config file in " |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
230 |
"%s\n") % version) |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
231 |
return |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
232 |
|
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
233 |
try: |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
234 |
self.parsegitmodules(modules) |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
235 |
except error.ParseError: |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
236 |
self.ui.warn(_("warning: unable to parse .gitmodules in %s\n") |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
237 |
% version) |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
238 |
return |
5c97a4ecbdd4
convert: improve support for unusual .gitmodules
Durham Goode <durham@fb.com>
parents:
25698
diff
changeset
|
239 |
|
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
240 |
for m in self.submodules: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
241 |
node, ret = self.gitrun('rev-parse', '%s:%s' % (version, m.path)) |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
242 |
if ret: |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
243 |
continue |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
244 |
m.node = node.strip() |
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
245 |
|
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
246 |
def getchanges(self, version, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
247 |
if full: |
26779
aaa33ec3c951
grammar: use does instead of do where appropriate
timeless@mozdev.org
parents:
26587
diff
changeset
|
248 |
raise error.Abort(_("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
|
249 |
self.modecache = {} |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
250 |
cmd = ['diff-tree','-z', '--root', '-m', '-r'] + self.simopt + [version] |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
251 |
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
|
252 |
if status: |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
253 |
raise error.Abort(_('cannot read changes in %s') % version) |
316 | 254 |
changes = [] |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
255 |
copies = {} |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8271
diff
changeset
|
256 |
seen = set() |
7242
d1dff8c492dd
convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents:
7222
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
subdeleted = [False] |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
260 |
difftree = output.split('\x00') |
22467
333d654783ad
convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents:
22413
diff
changeset
|
261 |
lcount = len(difftree) |
333d654783ad
convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents:
22413
diff
changeset
|
262 |
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
|
263 |
|
26077
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
264 |
skipsubmodules = self.ui.configbool('convert', 'git.skipsubmodules', |
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
265 |
False) |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
h = entry[3] |
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
269 |
p = (entry[1] == "100755") |
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
270 |
s = (entry[1] == "120000") |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
271 |
renamesource = (not isdest and entry[4][0] == '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
|
272 |
|
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
273 |
if f == '.gitmodules': |
26077
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
274 |
if skipsubmodules: |
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
275 |
return |
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
276 |
|
22469
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
277 |
subexists[0] = True |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
278 |
if entry[4] == '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
|
279 |
subdeleted[0] = True |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
280 |
changes.append(('.hgsub', nodemod.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
|
281 |
else: |
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
282 |
changes.append(('.hgsub', '')) |
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
283 |
elif entry[1] == '160000' or entry[0] == ':160000': |
26077
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
284 |
if not skipsubmodules: |
e63d05fbae84
convert: add convert.git.skipsubmodules option
Durham Goode <durham@fb.com>
parents:
25998
diff
changeset
|
285 |
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
|
286 |
else: |
22470
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
287 |
if renamesource: |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
288 |
h = nodemod.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
|
289 |
self.modecache[(f, h)] = (p and "x") or (s and "l") or "" |
15bc0431476b
convert: for git, factor out code to add entries to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
22468
diff
changeset
|
290 |
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
|
291 |
|
22467
333d654783ad
convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents:
22413
diff
changeset
|
292 |
while i < lcount: |
333d654783ad
convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents:
22413
diff
changeset
|
293 |
l = difftree[i] |
333d654783ad
convert: for git's getchanges, use explicit index for iteration
Siddharth Agarwal <sid0@fb.com>
parents:
22413
diff
changeset
|
294 |
i += 1 |
7242
d1dff8c492dd
convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents:
7222
diff
changeset
|
295 |
if not entry: |
d1dff8c492dd
convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents:
7222
diff
changeset
|
296 |
if not l.startswith(':'): |
d1dff8c492dd
convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents:
7222
diff
changeset
|
297 |
continue |
22468
5910184f1f7b
convert: for git's getchanges, always split entry line into components
Siddharth Agarwal <sid0@fb.com>
parents:
22467
diff
changeset
|
298 |
entry = 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
|
299 |
continue |
7242
d1dff8c492dd
convert: fix non-ASCII filenames retrieval from git sources (issue 1360)
Patrick Mezard <pmezard@gmail.com>
parents:
7222
diff
changeset
|
300 |
f = l |
25997
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
301 |
if entry[4][0] == 'C': |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
302 |
copysrc = f |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
303 |
copydest = difftree[i] |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
304 |
i += 1 |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
305 |
f = copydest |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
add(entry, f, False) |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
309 |
# 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
|
310 |
# simultaneously. So f can be repeated even if fdest isn't. |
25997
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
311 |
if entry[4][0] == 'R': |
d4e1e947444b
convert: fix git copy file content conversions
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
312 |
# 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
|
313 |
fdest = difftree[i] |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
314 |
i += 1 |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
315 |
if fdest not in seen: |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
316 |
add(entry, fdest, True) |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
317 |
# .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
|
318 |
# and fro doesn't really make sense |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
319 |
if f != '.gitmodules' and fdest != '.gitmodules': |
8e0c4df28eec
convert: add support to detect git renames and copies
Siddharth Agarwal <sid0@fb.com>
parents:
22469
diff
changeset
|
320 |
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
|
321 |
entry = None |
17929
0eed66327ad4
convert: add support for converting git submodule (issue3528)
YaNan Xu <robot9@fb.com>
parents:
16689
diff
changeset
|
322 |
|
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 |
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
|
324 |
if subdeleted[0]: |
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
325 |
changes.append(('.hgsubstate', nodemod.nullhex)) |
21868
3420346174b1
convert: detect removal of ".gitmodules" at git source revisions correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20373
diff
changeset
|
326 |
else: |
3420346174b1
convert: detect removal of ".gitmodules" at git source revisions correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20373
diff
changeset
|
327 |
self.retrievegitmodules(version) |
3420346174b1
convert: detect removal of ".gitmodules" at git source revisions correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20373
diff
changeset
|
328 |
changes.append(('.hgsubstate', '')) |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
23206
diff
changeset
|
329 |
return (changes, copies, set()) |
316 | 330 |
|
331 |
def getcommit(self, version): |
|
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
332 |
c = self.catfile(version, "commit") # read the commit hash |
316 | 333 |
end = c.find("\n\n") |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
334 |
message = c[end + 2:] |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4721
diff
changeset
|
335 |
message = self.recode(message) |
316 | 336 |
l = c[:end].splitlines() |
337 |
parents = [] |
|
8271
e3d3dad805f9
Add committer tag only when needed in git conversion
Richard Quirk <richard.quirk@gmail.com>
parents:
8250
diff
changeset
|
338 |
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
|
339 |
extra = {} |
316 | 340 |
for e in l[1:]: |
4532
c3a78a49d7f0
Some small cleanups for convert extension:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4521
diff
changeset
|
341 |
n, v = e.split(" ", 1) |
316 | 342 |
if n == "author": |
343 |
p = v.split() |
|
1385
adb3de56635b
convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents:
1335
diff
changeset
|
344 |
tm, tz = p[-2:] |
316 | 345 |
author = " ".join(p[:-2]) |
346 |
if author[0] == "<": author = author[1:-1] |
|
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4721
diff
changeset
|
347 |
author = self.recode(author) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
348 |
if n == "committer": |
431 | 349 |
p = v.split() |
1385
adb3de56635b
convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents:
1335
diff
changeset
|
350 |
tm, tz = p[-2:] |
431 | 351 |
committer = " ".join(p[:-2]) |
352 |
if committer[0] == "<": committer = committer[1:-1] |
|
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4721
diff
changeset
|
353 |
committer = self.recode(committer) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
354 |
if n == "parent": |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
extra[n] = v |
1385
adb3de56635b
convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents:
1335
diff
changeset
|
358 |
|
30813
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
359 |
if self.committeractions['dropcommitter']: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
360 |
committer = None |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
361 |
elif self.committeractions['replaceauthor']: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
362 |
author = committer |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
363 |
|
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
364 |
if committer: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
365 |
messagealways = self.committeractions['messagealways'] |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
366 |
messagedifferent = self.committeractions['messagedifferent'] |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
367 |
if messagealways: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
368 |
message += '\n%s %s\n' % (messagealways, committer) |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
369 |
elif messagedifferent and author != committer: |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
370 |
message += '\n%s %s\n' % (messagedifferent, committer) |
2cbbd4622ab0
convert: config option to control Git committer actions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30661
diff
changeset
|
371 |
|
1385
adb3de56635b
convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents:
1335
diff
changeset
|
372 |
tzs, tzh, tzm = tz[-5:-4] + "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
|
373 |
tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) |
1385
adb3de56635b
convert-repo: Fix timezone handling
Matt Mackall <mpm@selenic.com>
parents:
1335
diff
changeset
|
374 |
date = tm + " " + str(tz) |
34162
15794577bcf3
configitems: register the 'convert.git.saverev' config
Boris Feld <boris.feld@octobus.net>
parents:
34161
diff
changeset
|
375 |
saverev = self.ui.configbool('convert', 'git.saverev') |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
376 |
|
28365
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
377 |
c = common.commit(parents=parents, date=date, author=author, |
cd599bc179fb
convert: git use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
378 |
desc=message, |
30660
1f21a6835604
convert: add config option to copy extra keys from Git commits
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30646
diff
changeset
|
379 |
rev=version, |
30661
ced0d686ecb3
convert: add config option to control storing original revision
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30660
diff
changeset
|
380 |
extra=extra, |
ced0d686ecb3
convert: add config option to control storing original revision
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30660
diff
changeset
|
381 |
saverev=saverev) |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
382 |
return c |
316 | 383 |
|
22413
3cb0318bb2dd
convert: enable deterministic conversion progress bar for git
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
384 |
def numcommits(self): |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
385 |
output, ret = self.gitrunlines('rev-list', '--all') |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
386 |
if ret: |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
387 |
raise error.Abort(_('cannot retrieve number of commits in %s') \ |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
388 |
% self.path) |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
389 |
return len(output) |
22413
3cb0318bb2dd
convert: enable deterministic conversion progress bar for git
Augie Fackler <raf@durin42.com>
parents:
22300
diff
changeset
|
390 |
|
694 | 391 |
def gettags(self): |
392 |
tags = {} |
|
16259
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
393 |
alltags = {} |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
394 |
output, status = self.gitrunlines('ls-remote', '--tags', self.path) |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
395 |
|
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
396 |
if status: |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
397 |
raise error.Abort(_('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
|
398 |
prefix = 'refs/tags/' |
16259
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
399 |
|
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
400 |
# 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
|
401 |
for line in output: |
4062
516f883e3d79
convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4047
diff
changeset
|
402 |
line = line.strip() |
18572
5fe58f9332a4
git convert: some versions of git use fatal: instead of error:
Augie Fackler <raf@durin42.com>
parents:
18570
diff
changeset
|
403 |
if line.startswith("error:") or line.startswith("fatal:"): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26077
diff
changeset
|
404 |
raise error.Abort(_('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
|
405 |
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
|
406 |
if not tag.startswith(prefix): |
516f883e3d79
convert-repo: handle packed git tags
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4047
diff
changeset
|
407 |
continue |
16259
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
408 |
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
|
409 |
|
16259
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
410 |
# 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
|
411 |
for tag in alltags: |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
412 |
if tag.endswith('^{}'): |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
413 |
tags[tag[:-3]] = alltags[tag] |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
414 |
else: |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
415 |
if tag + '^{}' in alltags: |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
416 |
continue |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
417 |
else: |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
418 |
tags[tag] = alltags[tag] |
589aab2ca716
convert: support non annotated tags in git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
14945
diff
changeset
|
419 |
|
694 | 420 |
return tags |
5380
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
421 |
|
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
422 |
def getchangedfiles(self, version, i): |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
423 |
changes = [] |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
424 |
if i is None: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
425 |
output, status = self.gitrunlines('diff-tree', '--root', '-m', |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
426 |
'-r', version) |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
427 |
if status: |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
428 |
raise error.Abort(_('cannot read changes in %s') % version) |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
429 |
for l in output: |
5380
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
430 |
if "\t" not in l: |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
431 |
continue |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
432 |
m, f = l[:-1].split("\t") |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
433 |
changes.append(f) |
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
434 |
else: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
435 |
output, status = self.gitrunlines('diff-tree', '--name-only', |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
436 |
'--root', '-r', version, |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
437 |
'%s^%s' % (version, i + 1), '--') |
28816
f4a42bb7c2ec
convert: don't ignore errors from git diff-tree
Julien Cristau <julien.cristau@logilab.fr>
parents:
28671
diff
changeset
|
438 |
if status: |
f4a42bb7c2ec
convert: don't ignore errors from git diff-tree
Julien Cristau <julien.cristau@logilab.fr>
parents:
28671
diff
changeset
|
439 |
raise error.Abort(_('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
|
440 |
changes = [f.rstrip('\n') for f in output] |
5380
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
441 |
|
a5a7f7fd5554
convert_git: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5336
diff
changeset
|
442 |
return changes |
13756
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
443 |
|
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
444 |
def getbookmarks(self): |
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
445 |
bookmarks = {} |
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
446 |
|
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
447 |
# Handle local and remote branches |
34160
f74edb48c574
configitems: register the 'convert.git.remoteprefix' config
Boris Feld <boris.feld@octobus.net>
parents:
34159
diff
changeset
|
448 |
remoteprefix = self.ui.config('convert', 'git.remoteprefix') |
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
449 |
reftypes = [ |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
450 |
# (git prefix, hg prefix) |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
451 |
('refs/remotes/origin/', remoteprefix + '/'), |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
452 |
('refs/heads/', '') |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
453 |
] |
13756
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
454 |
|
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
30815
diff
changeset
|
455 |
exclude = { |
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
456 |
'refs/remotes/origin/HEAD', |
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
30815
diff
changeset
|
457 |
} |
13756
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
458 |
|
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
459 |
try: |
28660
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
460 |
output, status = self.gitrunlines('show-ref') |
cdda7b96afff
convert: rewrite calls to Git to use the new shelling mechanism (SEC)
Mateusz Kwapich <mitrandir@fb.com>
parents:
28659
diff
changeset
|
461 |
for line in output: |
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
462 |
line = line.strip() |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
463 |
rev, name = line.split(None, 1) |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
464 |
# Process each type of branch |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
465 |
for gitprefix, hgprefix in reftypes: |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
466 |
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
|
467 |
continue |
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
468 |
name = '%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
|
469 |
bookmarks[name] = rev |
25905
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
470 |
except Exception: |
80149d0b6842
convert: fix git convert using servers branches
Durham Goode <durham@fb.com>
parents:
25787
diff
changeset
|
471 |
pass |
13756
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
472 |
|
6b7077df4aa5
convert: add bookmarks reading support to git backend
Edouard Gomez <ed.gomez@free.fr>
parents:
12144
diff
changeset
|
473 |
return bookmarks |
19121
478a04605ce1
splicemap: improve error handling when source is git (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18572
diff
changeset
|
474 |
|
20373
e8203629371b
convert: add mapname parameter to checkrevformat
Sean Farley <sean.michael.farley@gmail.com>
parents:
19121
diff
changeset
|
475 |
def checkrevformat(self, revstr, mapname='splicemap'): |
19121
478a04605ce1
splicemap: improve error handling when source is git (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18572
diff
changeset
|
476 |
""" 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
|
477 |
self.checkhexformat(revstr, mapname) |