author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 14 Feb 2023 23:05:18 +0100 | |
changeset 50002 | e358f6e0e50e |
parent 49866 | 2ac60a71c240 |
child 51014 | ed65e97db7bc |
permissions | -rw-r--r-- |
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
1 |
# hg.py - hg backend for convert extension |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
2 |
# |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46113
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:
8209
diff
changeset
|
4 |
# |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
7 |
|
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
8 |
# Notes for hg->hg conversion: |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
9 |
# |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
10 |
# * Old versions of Mercurial didn't trim the whitespace from the ends |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
11 |
# of commit messages, but new versions do. Changesets created by |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
12 |
# those older versions, then converted, may thus have different |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
13 |
# hashes for changesets that are otherwise identical. |
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
14 |
# |
8596
a58a95e523aa
convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents:
8495
diff
changeset
|
15 |
# * Using "--config convert.hg.saverev=true" will make the source |
a58a95e523aa
convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents:
8495
diff
changeset
|
16 |
# identifier to be stored in the converted revision. This will cause |
a58a95e523aa
convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents:
8495
diff
changeset
|
17 |
# the converted revision to have a different identity than the |
a58a95e523aa
convert/hg: update documentation
Patrick Mezard <pmezard@gmail.com>
parents:
8495
diff
changeset
|
18 |
# source. |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
19 |
|
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
20 |
import os |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
21 |
import re |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
22 |
import time |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
23 |
|
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28900
diff
changeset
|
24 |
from mercurial.i18n import _ |
43085
eef9a2d67051
py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
25 |
from mercurial.pycompat import open |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
26 |
from mercurial.node import ( |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
27 |
bin, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
28 |
hex, |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
29 |
sha1nodeconstants, |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
30 |
) |
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
31 |
from mercurial import ( |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
32 |
bookmarks, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
33 |
context, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
34 |
error, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
35 |
exchange, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
36 |
hg, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
37 |
lock as lockmod, |
48116
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
47128
diff
changeset
|
38 |
logcmdutil, |
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
39 |
merge as mergemod, |
48710
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48241
diff
changeset
|
40 |
mergestate, |
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
41 |
phases, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
42 |
util, |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
43 |
) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36340
diff
changeset
|
44 |
from mercurial.utils import dateutil |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
45 |
|
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28370
diff
changeset
|
46 |
stringio = util.stringio |
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28370
diff
changeset
|
47 |
|
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
48 |
from . import common |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
49 |
|
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
50 |
mapfile = common.mapfile |
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
51 |
NoRepo = common.NoRepo |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
52 |
|
36134
2a28bdb63f05
convert: make hg sha1 regex consistently be a bytes
Augie Fackler <augie@google.com>
parents:
36132
diff
changeset
|
53 |
sha1re = re.compile(br'\b[0-9a-f]{12,40}\b') |
20372
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
54 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
55 |
|
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
56 |
class mercurial_sink(common.converter_sink): |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34172
diff
changeset
|
57 |
def __init__(self, ui, repotype, path): |
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34172
diff
changeset
|
58 |
common.converter_sink.__init__(self, ui, repotype, path) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 |
self.branchnames = ui.configbool(b'convert', b'hg.usebranchnames') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 |
self.clonebranches = ui.configbool(b'convert', b'hg.clonebranches') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 |
self.tagsbranch = ui.config(b'convert', b'hg.tagsbranch') |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
62 |
self.lastbranch = None |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
63 |
if os.path.isdir(path) and len(os.listdir(path)) > 0: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
64 |
try: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
65 |
self.repo = hg.repository(self.ui, path) |
5918
1716c8a0bd09
convert: mercurial sink must be local
Patrick Mezard <pmezard@gmail.com>
parents:
5522
diff
changeset
|
66 |
if not self.repo.local(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
67 |
raise NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 |
_(b'%s is not a local Mercurial repository') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
69 |
) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25589
diff
changeset
|
70 |
except error.RepoError as err: |
8206
cce63ef1045b
ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents:
8112
diff
changeset
|
71 |
ui.traceback() |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
72 |
raise NoRepo(err.args[0]) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
73 |
else: |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
74 |
try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
75 |
ui.status(_(b'initializing destination %s repository\n') % path) |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
76 |
self.repo = hg.repository(self.ui, path, create=True) |
5918
1716c8a0bd09
convert: mercurial sink must be local
Patrick Mezard <pmezard@gmail.com>
parents:
5522
diff
changeset
|
77 |
if not self.repo.local(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
78 |
raise NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 |
_(b'%s is not a local Mercurial repository') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
80 |
) |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
81 |
self.created.append(path) |
7875
553aa0cbeab6
cleanup: drop unused assignments
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7874
diff
changeset
|
82 |
except error.RepoError: |
8206
cce63ef1045b
ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents:
8112
diff
changeset
|
83 |
ui.traceback() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
84 |
raise NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
85 |
_(b"could not create hg repository %s as sink") % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
86 |
) |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
87 |
self.lock = None |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
88 |
self.wlock = None |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
89 |
self.filemapmode = False |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
90 |
self.subrevmaps = {} |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
91 |
|
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
92 |
def before(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
93 |
self.ui.debug(b'run hg sink pre-conversion action\n') |
5052
a11e8a181bd5
convert: fix locking order
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5038
diff
changeset
|
94 |
self.wlock = self.repo.wlock() |
5014
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
95 |
self.lock = self.repo.lock() |
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
96 |
|
914054ca532e
convert: acquire/release locks periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
5013
diff
changeset
|
97 |
def after(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 |
self.ui.debug(b'run hg sink post-conversion action\n') |
10086
e388f5ee7bf5
convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents:
9546
diff
changeset
|
99 |
if self.lock: |
e388f5ee7bf5
convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents:
9546
diff
changeset
|
100 |
self.lock.release() |
e388f5ee7bf5
convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents:
9546
diff
changeset
|
101 |
if self.wlock: |
e388f5ee7bf5
convert: make hg sink cleanup safer
Matt Mackall <mpm@selenic.com>
parents:
9546
diff
changeset
|
102 |
self.wlock.release() |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
103 |
|
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
104 |
def revmapfile(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
105 |
return self.repo.vfs.join(b"shamap") |
316 | 106 |
|
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
107 |
def authorfile(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
108 |
return self.repo.vfs.join(b"authormap") |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
109 |
|
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
110 |
def setbranch(self, branch, pbranches): |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
111 |
if not self.clonebranches: |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
112 |
return |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
113 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
114 |
setbranch = branch != self.lastbranch |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
115 |
self.lastbranch = branch |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
116 |
if not branch: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
117 |
branch = b'default' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
118 |
pbranches = [(b[0], b[1] and b[1] or b'default') for b in pbranches] |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
119 |
|
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
120 |
branchpath = os.path.join(self.path, branch) |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
121 |
if setbranch: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
122 |
self.after() |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
123 |
try: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
124 |
self.repo = hg.repository(self.ui, branchpath) |
16689
f366d4c2ff34
cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents:
16687
diff
changeset
|
125 |
except Exception: |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
126 |
self.repo = hg.repository(self.ui, branchpath, create=True) |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
127 |
self.before() |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
128 |
|
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
129 |
# pbranches may bring revisions from other branches (merge parents) |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
130 |
# Make sure we have them, or pull them. |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
131 |
missings = {} |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
132 |
for b in pbranches: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
133 |
try: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
134 |
self.repo.lookup(b[0]) |
16689
f366d4c2ff34
cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents:
16687
diff
changeset
|
135 |
except Exception: |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
136 |
missings.setdefault(b[1], []).append(b[0]) |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5959
diff
changeset
|
137 |
|
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
138 |
if missings: |
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
139 |
self.after() |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
140 |
for pbranch, heads in sorted(missings.items()): |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
141 |
pbranchpath = os.path.join(self.path, pbranch) |
14556
517e1d88bf7e
hg: change various repository() users to use peer() where appropriate
Matt Mackall <mpm@selenic.com>
parents:
14151
diff
changeset
|
142 |
prepo = hg.peer(self.ui, {}, pbranchpath) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 |
self.ui.note( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
144 |
_(b'pulling from %s into %s\n') % (pbranch, branch) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
145 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
146 |
exchange.pull( |
48241
7d1e60244561
path: keep the path instance in the `pulloperation`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48116
diff
changeset
|
147 |
self.repo, prepo, heads=[prepo.lookup(h) for h in heads] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
148 |
) |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5918
diff
changeset
|
149 |
self.before() |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
150 |
|
21076
5236c7a72a2d
convert: backout b75a04502ced and 9616b03113ce - tagmap
Mads Kiilerich <madski@unity3d.com>
parents:
20397
diff
changeset
|
151 |
def _rewritetags(self, source, revmap, data): |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28370
diff
changeset
|
152 |
fp = stringio() |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
153 |
for line in data.splitlines(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
154 |
s = line.split(b' ', 1) |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
155 |
if len(s) != 2: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 |
self.ui.warn(_(b'invalid tag entry: "%s"\n') % line) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 |
fp.write(b'%s\n' % line) # Bogus, but keep for hash stability |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
158 |
continue |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
159 |
revid = revmap.get(source.lookuprev(s[0])) |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
160 |
if not revid: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
161 |
if s[0] == sha1nodeconstants.nullhex: |
25305
884ef09cf658
convert: properly pass null ids through .hgtags (issue4678)
Matt Mackall <mpm@selenic.com>
parents:
24395
diff
changeset
|
162 |
revid = s[0] |
884ef09cf658
convert: properly pass null ids through .hgtags (issue4678)
Matt Mackall <mpm@selenic.com>
parents:
24395
diff
changeset
|
163 |
else: |
39021
7e023ce26c7f
convert: don't drop missing or corrupt tag entries
Matt Harbison <matt_harbison@yahoo.com>
parents:
37579
diff
changeset
|
164 |
# missing, but keep for hash stability |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 |
self.ui.warn(_(b'missing tag entry: "%s"\n') % line) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 |
fp.write(b'%s\n' % line) |
25305
884ef09cf658
convert: properly pass null ids through .hgtags (issue4678)
Matt Mackall <mpm@selenic.com>
parents:
24395
diff
changeset
|
167 |
continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
168 |
fp.write(b'%s %s\n' % (revid, s[1])) |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
169 |
return fp.getvalue() |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
170 |
|
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
171 |
def _rewritesubstate(self, source, data): |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28370
diff
changeset
|
172 |
fp = stringio() |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
173 |
for line in data.splitlines(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 |
s = line.split(b' ', 1) |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
175 |
if len(s) != 2: |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
176 |
continue |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
177 |
|
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
178 |
revid = s[0] |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
179 |
subpath = s[1] |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
180 |
if revid != sha1nodeconstants.nullhex: |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
181 |
revmap = self.subrevmaps.get(subpath) |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
182 |
if revmap is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
183 |
revmap = mapfile( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
184 |
self.ui, self.repo.wjoin(subpath, b'.hg/shamap') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
185 |
) |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
186 |
self.subrevmaps[subpath] = revmap |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
187 |
|
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
188 |
# It is reasonable that one or more of the subrepos don't |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
189 |
# need to be converted, in which case they can be cloned |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
190 |
# into place instead of converted. Therefore, only warn |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
191 |
# once. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
192 |
msg = _(b'no ".hgsubstate" updates will be made for "%s"\n') |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
193 |
if len(revmap) == 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
194 |
sub = self.repo.wvfs.reljoin(subpath, b'.hg') |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
195 |
|
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
196 |
if self.repo.wvfs.exists(sub): |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
197 |
self.ui.warn(msg % subpath) |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
198 |
|
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
199 |
newid = revmap.get(revid) |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
200 |
if not newid: |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
201 |
if len(revmap) > 0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
202 |
self.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 |
_(b"%s is missing from %s/.hg/shamap\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
204 |
% (revid, subpath) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
205 |
) |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
206 |
else: |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
207 |
revid = newid |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
208 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
209 |
fp.write(b'%s %s\n' % (revid, subpath)) |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
210 |
|
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
211 |
return fp.getvalue() |
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
212 |
|
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
213 |
def _calculatemergedfiles(self, source, p1ctx, p2ctx): |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
214 |
"""Calculates the files from p2 that we need to pull in when merging p1 |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
215 |
and p2, given that the merge is coming from the given source. |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
216 |
|
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
217 |
This prevents us from losing files that only exist in the target p2 and |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
218 |
that don't come from the source repo (like if you're merging multiple |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
219 |
repositories together). |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
220 |
""" |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
221 |
anc = [p1ctx.ancestor(p2ctx)] |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
222 |
# Calculate what files are coming from p2 |
45275
8e8d513941b4
merge: introduce 'commitinfo' in mergeresult
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45274
diff
changeset
|
223 |
# TODO: mresult.commitinfo might be able to get that info |
45274
0e18861f96ab
merge: return a mergeresult obj from manifestmerge(), calculateupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44452
diff
changeset
|
224 |
mresult = mergemod.calculateupdates( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
225 |
self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
226 |
p1ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
227 |
p2ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
228 |
anc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
229 |
branchmerge=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
230 |
force=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
231 |
acceptremote=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
232 |
followcopies=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
233 |
) |
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
234 |
|
45346
3c783ff08d40
mergeresult: introduce filemap() which yields filename based mapping
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45275
diff
changeset
|
235 |
for file, (action, info, msg) in mresult.filemap(): |
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
236 |
if source.targetfilebelongstosource(file): |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
237 |
# If the file belongs to the source repo, ignore the p2 |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
238 |
# since it will be covered by the existing fileset. |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
239 |
continue |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
240 |
|
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
241 |
# If the file requires actual merging, abort. We don't have enough |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
242 |
# context to resolve merges correctly. |
48710
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48241
diff
changeset
|
243 |
if action in mergestate.CONVERT_MERGE_ACTIONS: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
244 |
raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
245 |
_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 |
b"unable to convert merge commit " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
247 |
b"since target parents do not merge cleanly (file " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
248 |
b"%s, parents %s and %s)" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
249 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
250 |
% (file, p1ctx, p2ctx) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
251 |
) |
48710
b0aa9b0b9c21
convert: use the merge action constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48241
diff
changeset
|
252 |
elif action == mergestate.ACTION_KEEP: |
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
253 |
# 'keep' means nothing changed from p1 |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
254 |
continue |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
255 |
else: |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
256 |
# Any other change means we want to take the p2 version |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
257 |
yield file |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
258 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
259 |
def putcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
260 |
self, files, copies, parents, commit, source, revmap, full, cleanp2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
261 |
): |
6717
2011bb8ada9a
convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents:
6716
diff
changeset
|
262 |
files = dict(files) |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
263 |
|
6717
2011bb8ada9a
convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents:
6716
diff
changeset
|
264 |
def getfilectx(repo, memctx, f): |
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
265 |
if p2ctx and f in p2files and f not in copies: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
266 |
self.ui.debug(b'reusing %s from p2\n' % f) |
26078
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
267 |
try: |
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
268 |
return p2ctx[f] |
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
269 |
except error.ManifestLookupError: |
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
270 |
# If the file doesn't exist in p2, then we're syncing a |
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
271 |
# delete, so just return None. |
5ca587348875
convert: fix syncing deletes from p2 merge commit
Durham Goode <durham@fb.com>
parents:
26037
diff
changeset
|
272 |
return None |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
273 |
try: |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
274 |
v = files[f] |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
275 |
except KeyError: |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
276 |
return None |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
277 |
data, mode = source.getfile(f, v) |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21765
diff
changeset
|
278 |
if data is None: |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21765
diff
changeset
|
279 |
return None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
280 |
if f == b'.hgtags': |
21076
5236c7a72a2d
convert: backout b75a04502ced and 9616b03113ce - tagmap
Mads Kiilerich <madski@unity3d.com>
parents:
20397
diff
changeset
|
281 |
data = self._rewritetags(source, revmap, data) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
282 |
if f == b'.hgsubstate': |
25558
daf9f7ee2a5c
convert: support incremental conversion with hg subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
25305
diff
changeset
|
283 |
data = self._rewritesubstate(source, data) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
284 |
return context.memfilectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
285 |
self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
286 |
memctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
287 |
f, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
288 |
data, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
289 |
b'l' in mode, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
290 |
b'x' in mode, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
291 |
copies.get(f), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
292 |
) |
6717
2011bb8ada9a
convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents:
6716
diff
changeset
|
293 |
|
431 | 294 |
pl = [] |
295 |
for p in parents: |
|
6717
2011bb8ada9a
convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents:
6716
diff
changeset
|
296 |
if p not in pl: |
431 | 297 |
pl.append(p) |
298 |
parents = pl |
|
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
299 |
nparents = len(parents) |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
300 |
if self.filemapmode and nparents == 1: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
301 |
m1node = self.repo.changelog.read(bin(parents[0]))[0] |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
302 |
parent = parents[0] |
316 | 303 |
|
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
304 |
if len(parents) < 2: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
305 |
parents.append(self.repo.nullid) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
306 |
if len(parents) < 2: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
307 |
parents.append(self.repo.nullid) |
431 | 308 |
p2 = parents.pop(0) |
692
695dd9a491da
convert-repo: deal with packed git and other fixes
mpm@selenic.com
parents:
450
diff
changeset
|
309 |
|
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
310 |
text = commit.desc |
20372
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
311 |
|
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
312 |
sha1s = re.findall(sha1re, text) |
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
313 |
for sha1 in sha1s: |
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
314 |
oldrev = source.lookuprev(sha1) |
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
315 |
newrev = revmap.get(oldrev) |
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
316 |
if newrev is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
317 |
text = text.replace(sha1, newrev[: len(sha1)]) |
20372
45562379ce4e
convert: replace old sha1s in the description
Sean Farley <sean.michael.farley@gmail.com>
parents:
19891
diff
changeset
|
318 |
|
5439
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5437
diff
changeset
|
319 |
extra = commit.extra.copy() |
21765
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
320 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
321 |
sourcename = self.repo.ui.config(b'convert', b'hg.sourcename') |
25750
c9093d4d1ff6
convert: add config for recording the source name
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
322 |
if sourcename: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
323 |
extra[b'convert_source'] = sourcename |
25750
c9093d4d1ff6
convert: add config for recording the source name
Durham Goode <durham@fb.com>
parents:
25748
diff
changeset
|
324 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
325 |
for label in ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
326 |
b'source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
327 |
b'transplant_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
328 |
b'rebase_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
329 |
b'intermediate-source', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
330 |
): |
21765
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
331 |
node = extra.get(label) |
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
332 |
|
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
333 |
if node is None: |
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
334 |
continue |
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
335 |
|
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
336 |
# Only transplant stores its reference in binary |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
337 |
if label == b'transplant_source': |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
338 |
node = hex(node) |
21765
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
339 |
|
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
340 |
newrev = revmap.get(node) |
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
341 |
if newrev is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
342 |
if label == b'transplant_source': |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
343 |
newrev = bin(newrev) |
21765
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
344 |
|
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
345 |
extra[label] = newrev |
44255f7ce886
convert: update the transplant, rebase and graft references in 'extra'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21689
diff
changeset
|
346 |
|
5038
8f157190075e
convert: add config option to turn off use of branch names
Bryan O'Sullivan <bos@serpentine.com>
parents:
5017
diff
changeset
|
347 |
if self.branchnames and commit.branch: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
348 |
extra[b'branch'] = commit.branch |
25570
7cc1d33f0ba6
convert: always track the hg source revision in the internal commit object
Matt Harbison <matt_harbison@yahoo.com>
parents:
25558
diff
changeset
|
349 |
if commit.rev and commit.saverev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 |
extra[b'convert_revision'] = commit.rev |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4873
diff
changeset
|
351 |
|
431 | 352 |
while parents: |
353 |
p1 = p2 |
|
354 |
p2 = parents.pop(0) |
|
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
355 |
p1ctx = self.repo[p1] |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
356 |
p2ctx = None |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
357 |
if p2 != self.repo.nullid: |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
358 |
p2ctx = self.repo[p2] |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
359 |
fileset = set(files) |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
360 |
if full: |
22360
3e483253213e
convert: don't use multi-argument set.update
Mads Kiilerich <madski@unity3d.com>
parents:
22300
diff
changeset
|
361 |
fileset.update(self.repo[p1]) |
3e483253213e
convert: don't use multi-argument set.update
Mads Kiilerich <madski@unity3d.com>
parents:
22300
diff
changeset
|
362 |
fileset.update(self.repo[p2]) |
26037
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
363 |
|
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
364 |
if p2ctx: |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
365 |
p2files = set(cleanp2) |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
366 |
for file in self._calculatemergedfiles(source, p1ctx, p2ctx): |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
367 |
p2files.add(file) |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
368 |
fileset.add(file) |
a75d24539aba
convert: fix convert dropping p2 contents during filemap merge
Durham Goode <durham@fb.com>
parents:
25750
diff
changeset
|
369 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
370 |
ctx = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
371 |
self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
372 |
(p1, p2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
373 |
text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
374 |
fileset, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
375 |
getfilectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
376 |
commit.author, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
377 |
commit.date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
378 |
extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
379 |
) |
25571
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
380 |
|
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
381 |
# We won't know if the conversion changes the node until after the |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
382 |
# commit, so copy the source's phase for now. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
383 |
self.repo.ui.setconfig( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
384 |
b'phases', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
385 |
b'new-commit', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
386 |
phases.phasenames[commit.phase], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
387 |
b'convert', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
388 |
) |
25571
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
389 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
390 |
with self.repo.transaction(b"convert") as tr: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
391 |
if self.repo.ui.config(b'convert', b'hg.preserve-hash'): |
42620
d98ec36be808
convert: add a config option to help doing identity hg->hg conversion
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
41771
diff
changeset
|
392 |
origctx = commit.ctx |
d98ec36be808
convert: add a config option to help doing identity hg->hg conversion
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
41771
diff
changeset
|
393 |
else: |
d98ec36be808
convert: add a config option to help doing identity hg->hg conversion
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
41771
diff
changeset
|
394 |
origctx = None |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
395 |
node = hex(self.repo.commitctx(ctx, origctx=origctx)) |
25571
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
396 |
|
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
397 |
# If the node value has changed, but the phase is lower than |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
398 |
# draft, set it back to draft since it hasn't been exposed |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
399 |
# anywhere. |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
400 |
if commit.rev != node: |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
401 |
ctx = self.repo[node] |
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
402 |
if ctx.phase() < phases.draft: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
403 |
phases.registernew( |
45790
5d65e04b6a80
phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents:
45346
diff
changeset
|
404 |
self.repo, tr, phases.draft, [ctx.rev()] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
405 |
) |
25571
1abfe639a70c
convert: apply the appropriate phases to the destination (issue4165)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25570
diff
changeset
|
406 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
407 |
text = b"(octopus merge fixup)\n" |
25697
1538e72209fd
convert: fix bug with converting the same commit twice
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
408 |
p2 = node |
431 | 409 |
|
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
410 |
if self.filemapmode and nparents == 1: |
39244
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39021
diff
changeset
|
411 |
man = self.repo.manifestlog.getstorage(b'') |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
412 |
mnode = self.repo.changelog.read(bin(p2))[0] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
413 |
closed = b'close' in commit.extra |
11673
a2f11188e2d2
convert: handle closed branch heads in hg-hg conversion (issue2185)
Matt Mackall <mpm@selenic.com>
parents:
11134
diff
changeset
|
414 |
if not closed and not man.cmp(m1node, man.revision(mnode)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
415 |
self.ui.status(_(b"filtering out empty revision\n")) |
15193
a84e3ed661cb
convert: fix crazy rollback call, broken by recent rollback safety checks
Matt Mackall <mpm@selenic.com>
parents:
15069
diff
changeset
|
416 |
self.repo.rollback(force=True) |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
417 |
return parent |
1389
9b3ef6f3cef5
convert-repo: fix up octopus merge conversion
Matt Mackall <mpm@selenic.com>
parents:
1388
diff
changeset
|
418 |
return p2 |
316 | 419 |
|
694 | 420 |
def puttags(self, tags): |
37395
810413b745ff
convert: look up branch only among branches
Martin von Zweigbergk <martinvonz@google.com>
parents:
37394
diff
changeset
|
421 |
tagparent = self.repo.branchtip(self.tagsbranch, ignoremissing=True) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
422 |
tagparent = tagparent or self.repo.nullid |
694 | 423 |
|
20376
7a4797910205
convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents:
20373
diff
changeset
|
424 |
oldlines = set() |
48914
417a1691a273
convert: remove pycompat.iteritems()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
425 |
for branch, heads in self.repo.branchmap().items(): |
20376
7a4797910205
convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents:
20373
diff
changeset
|
426 |
for h in heads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
427 |
if b'.hgtags' in self.repo[h]: |
20376
7a4797910205
convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents:
20373
diff
changeset
|
428 |
oldlines.update( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
429 |
set(self.repo[h][b'.hgtags'].data().splitlines(True)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
430 |
) |
20376
7a4797910205
convert: compare tags from all heads instead of just one
Sean Farley <sean.michael.farley@gmail.com>
parents:
20373
diff
changeset
|
431 |
oldlines = sorted(list(oldlines)) |
694 | 432 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
433 |
newlines = sorted([(b"%s %s\n" % (tags[tag], tag)) for tag in tags]) |
7877
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7875
diff
changeset
|
434 |
if newlines == oldlines: |
9431
d1b135f2f415
convert: fix history topology when using hg.tagsbranch
Patrick Mezard <pmezard@gmail.com>
parents:
8693
diff
changeset
|
435 |
return None, None |
20377
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
436 |
|
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
437 |
# if the old and new tags match, then there is nothing to update |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
438 |
oldtags = set() |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
439 |
newtags = set() |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
440 |
for line in oldlines: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
441 |
s = line.strip().split(b' ', 1) |
20377
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
442 |
if len(s) != 2: |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
443 |
continue |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
444 |
oldtags.add(s[1]) |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
445 |
for line in newlines: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
446 |
s = line.strip().split(b' ', 1) |
20377
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
447 |
if len(s) != 2: |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
448 |
continue |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
449 |
if s[1] not in oldtags: |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
450 |
newtags.add(s[1].strip()) |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
451 |
|
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
452 |
if not newtags: |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
453 |
return None, None |
5842d63cfe56
convert: avoid updating tags when there is nothing new
Sean Farley <sean.michael.farley@gmail.com>
parents:
20376
diff
changeset
|
454 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
455 |
data = b"".join(newlines) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
456 |
|
7877
eba7f12b0c51
cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7875
diff
changeset
|
457 |
def getfilectx(repo, memctx, f): |
35400
8a0cac20a1ad
memfilectx: make changectx argument mandatory in constructor (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
35176
diff
changeset
|
458 |
return context.memfilectx(repo, memctx, f, data, False, False, None) |
6717
2011bb8ada9a
convert: hg sink commits without working dir
Patrick Mezard <pmezard@gmail.com>
parents:
6716
diff
changeset
|
459 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
460 |
self.ui.status(_(b"updating tags\n")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
461 |
date = b"%d 0" % int(time.mktime(time.gmtime())) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
462 |
extra = {b'branch': self.tagsbranch} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
463 |
ctx = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
464 |
self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
465 |
(tagparent, None), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
466 |
b"update tags", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
467 |
[b".hgtags"], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
468 |
getfilectx, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 |
b"convert-repo", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
470 |
date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
471 |
extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
472 |
) |
25697
1538e72209fd
convert: fix bug with converting the same commit twice
Durham Goode <durham@fb.com>
parents:
25660
diff
changeset
|
473 |
node = self.repo.commitctx(ctx) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
474 |
return hex(node), hex(tagparent) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
475 |
|
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
476 |
def setfilemapmode(self, active): |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
477 |
self.filemapmode = active |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5360
diff
changeset
|
478 |
|
13746
d80b768545cb
convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents:
11673
diff
changeset
|
479 |
def putbookmarks(self, updatedbookmark): |
d80b768545cb
convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents:
11673
diff
changeset
|
480 |
if not len(updatedbookmark): |
d80b768545cb
convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents:
11673
diff
changeset
|
481 |
return |
26974
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
482 |
wlock = lock = tr = None |
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
483 |
try: |
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
484 |
wlock = self.repo.wlock() |
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
485 |
lock = self.repo.lock() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
486 |
tr = self.repo.transaction(b'bookmark') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
487 |
self.ui.status(_(b"updating bookmarks\n")) |
26973
fdd63acf3215
convert: indentation change to make the next patch more legible
Laurent Charignon <lcharignon@fb.com>
parents:
26587
diff
changeset
|
488 |
destmarks = self.repo._bookmarks |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
489 |
changes = [ |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
490 |
(bookmark, bin(updatedbookmark[bookmark])) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
491 |
for bookmark in updatedbookmark |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
492 |
] |
33487
a050d37c2c70
bookmark: use 'applychanges' in the convert extension
Boris Feld <boris.feld@octobus.net>
parents:
33455
diff
changeset
|
493 |
destmarks.applychanges(self.repo, tr, changes) |
26974
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
494 |
tr.close() |
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
495 |
finally: |
4b5dc0d9e899
convert: use repo._bookmarks.recordchange instead of repo._bookmarks.write
Laurent Charignon <lcharignon@fb.com>
parents:
26973
diff
changeset
|
496 |
lockmod.release(lock, wlock, tr) |
13746
d80b768545cb
convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents:
11673
diff
changeset
|
497 |
|
21635
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
498 |
def hascommitfrommap(self, rev): |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
499 |
# the exact semantics of clonebranches is unclear so we can't say no |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
500 |
return rev in self.repo or self.clonebranches |
5f2cc464e502
convert: introduce hascommitfrommap sink method
Mads Kiilerich <madski@unity3d.com>
parents:
21634
diff
changeset
|
501 |
|
21634
23b24d6a70c8
convert: rename sink hascommit to hascommitforsplicemap
Mads Kiilerich <madski@unity3d.com>
parents:
21498
diff
changeset
|
502 |
def hascommitforsplicemap(self, rev): |
16686
67964cda8701
cleanup: "not x in y" -> "x not in y"
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
503 |
if rev not in self.repo and self.clonebranches: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
504 |
raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
505 |
_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
506 |
b'revision %s not found in destination ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
507 |
b'repository (lookups with clonebranches=true ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 |
b'are not implemented)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
509 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
510 |
% rev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
511 |
) |
16106
d75aa756149b
convert: use splicemap entries when sorting revisions (issue1748)
Patrick Mezard <patrick@mezard.eu>
parents:
15193
diff
changeset
|
512 |
return rev in self.repo |
13746
d80b768545cb
convert: add bookmark support to the hg sink
Edouard Gomez <ed.gomez@free.fr>
parents:
11673
diff
changeset
|
513 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
514 |
|
28370
c1878afb063a
convert: hg use absolute_import
timeless <timeless@mozdev.org>
parents:
27863
diff
changeset
|
515 |
class mercurial_source(common.converter_source): |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34172
diff
changeset
|
516 |
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:
34172
diff
changeset
|
517 |
common.converter_source.__init__(self, ui, repotype, path, revs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
518 |
self.ignoreerrors = ui.configbool(b'convert', b'hg.ignoreerrors') |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
519 |
self.ignored = set() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 |
self.saverev = ui.configbool(b'convert', b'hg.saverev') |
5358
4fbd27bf04b1
convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents:
5352
diff
changeset
|
521 |
try: |
4fbd27bf04b1
convert: fail properly if we can't read a source hg repository
Bryan O'Sullivan <bos@serpentine.com>
parents:
5352
diff
changeset
|
522 |
self.repo = hg.repository(self.ui, path) |
5437
4d34f8b12a9e
convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents:
5402
diff
changeset
|
523 |
# try to provoke an exception if this isn't really a hg |
4d34f8b12a9e
convert: report errors more meaningfully if run with --traceback
Bryan O'Sullivan <bos@serpentine.com>
parents:
5402
diff
changeset
|
524 |
# repo, but some other bogus compatible-looking url |
5522
f5345a2d2391
convert: make sure mercurial_source has a local hg repo
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5521
diff
changeset
|
525 |
if not self.repo.local(): |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
16686
diff
changeset
|
526 |
raise error.RepoError |
7637 | 527 |
except error.RepoError: |
8206
cce63ef1045b
ui: print_exc() -> traceback()
Matt Mackall <mpm@selenic.com>
parents:
8112
diff
changeset
|
528 |
ui.traceback() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
529 |
raise NoRepo(_(b"%s is not a local Mercurial repository") % path) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
530 |
self.lastrev = None |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
531 |
self.lastctx = None |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
532 |
self._changescache = None, None |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
533 |
self.convertfp = None |
6885
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
534 |
# Restrict converted revisions to startrev descendants |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 |
startnode = ui.config(b'convert', b'hg.startrev') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
536 |
hgrevs = ui.config(b'convert', b'hg.revs') |
19891
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
537 |
if hgrevs is None: |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
538 |
if startnode is not None: |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
539 |
try: |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
540 |
startnode = self.repo.lookup(startnode) |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
541 |
except error.RepoError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
542 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
543 |
_(b'%s is not a valid start revision') % startnode |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
544 |
) |
19891
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
545 |
startrev = self.repo.changelog.rev(startnode) |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
546 |
children = {startnode: 1} |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
547 |
for r in self.repo.changelog.descendants([startrev]): |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
548 |
children[self.repo.changelog.node(r)] = 1 |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
549 |
self.keep = children.__contains__ |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
550 |
else: |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
551 |
self.keep = util.always |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25697
diff
changeset
|
552 |
if revs: |
37361
e45545f7895e
convert: use repo.lookup() for converting to nodeid
Martin von Zweigbergk <martinvonz@google.com>
parents:
36607
diff
changeset
|
553 |
self._heads = [self.repo.lookup(r) for r in revs] |
19891
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
554 |
else: |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
555 |
self._heads = self.repo.heads() |
6885
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
556 |
else: |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
25697
diff
changeset
|
557 |
if revs or startnode is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
558 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
559 |
_( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
560 |
b'hg.revs cannot be combined with ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 |
b'hg.startrev or --rev' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
562 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
563 |
) |
19891
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
564 |
nodes = set() |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
565 |
parents = set() |
48116
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
47128
diff
changeset
|
566 |
for r in logcmdutil.revrange(self.repo, [hgrevs]): |
19891
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
567 |
ctx = self.repo[r] |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
568 |
nodes.add(ctx.node()) |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
569 |
parents.update(p.node() for p in ctx.parents()) |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
570 |
self.keep = nodes.__contains__ |
e271970b9821
convert: introduce hg.revs to replace hg.startrev and --rev with a revset
Mads Kiilerich <madski@unity3d.com>
parents:
19890
diff
changeset
|
571 |
self._heads = nodes - parents |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
572 |
|
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
573 |
def _changectx(self, rev): |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
574 |
if self.lastrev != rev: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6717
diff
changeset
|
575 |
self.lastctx = self.repo[rev] |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
576 |
self.lastrev = rev |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
577 |
return self.lastctx |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
578 |
|
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
579 |
def _parents(self, ctx): |
9531
a2f36a082449
convert/hg: make parents() return changectx, not nodes
Patrick Mezard <pmezard@gmail.com>
parents:
9431
diff
changeset
|
580 |
return [p for p in ctx.parents() if p and self.keep(p.node())] |
6885
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
581 |
|
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
582 |
def getheads(self): |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
583 |
return [hex(h) for h in self._heads if self.keep(h)] |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
584 |
|
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
585 |
def getfile(self, name, rev): |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
586 |
try: |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
587 |
fctx = self._changectx(rev)[name] |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
588 |
return fctx.data(), fctx.flags() |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21765
diff
changeset
|
589 |
except error.LookupError: |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
21765
diff
changeset
|
590 |
return None, None |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
591 |
|
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
592 |
def _changedfiles(self, ctx1, ctx2): |
27719
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
593 |
ma, r = [], [] |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
594 |
maappend = ma.append |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
595 |
rappend = r.append |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
596 |
d = ctx1.manifest().diff(ctx2.manifest()) |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
597 |
for f, ((node1, flag1), (node2, flag2)) in d.items(): |
27719
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
598 |
if node2 is None: |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
599 |
rappend(f) |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
600 |
else: |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
601 |
maappend(f) |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
602 |
return ma, r |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
603 |
|
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
604 |
def getchanges(self, rev, full): |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
605 |
ctx = self._changectx(rev) |
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
606 |
parents = self._parents(ctx) |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
607 |
if full or not parents: |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
608 |
files = copyfiles = ctx.manifest() |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
609 |
if parents: |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
610 |
if self._changescache[0] == rev: |
49866
2ac60a71c240
typing: suppress a couple of attribute-errors in convert
Matt Harbison <matt_harbison@yahoo.com>
parents:
48914
diff
changeset
|
611 |
# TODO: add type hints to avoid this warning, instead of |
2ac60a71c240
typing: suppress a couple of attribute-errors in convert
Matt Harbison <matt_harbison@yahoo.com>
parents:
48914
diff
changeset
|
612 |
# suppressing it: |
2ac60a71c240
typing: suppress a couple of attribute-errors in convert
Matt Harbison <matt_harbison@yahoo.com>
parents:
48914
diff
changeset
|
613 |
# No attribute '__iter__' on None [attribute-error] |
2ac60a71c240
typing: suppress a couple of attribute-errors in convert
Matt Harbison <matt_harbison@yahoo.com>
parents:
48914
diff
changeset
|
614 |
ma, r = self._changescache[1] # pytype: disable=attribute-error |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
615 |
else: |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
616 |
ma, r = self._changedfiles(parents[0], ctx) |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22299
diff
changeset
|
617 |
if not full: |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
618 |
files = ma + r |
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
619 |
copyfiles = ma |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
620 |
# _getcopies() is also run for roots and before filtering so missing |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
621 |
# revlogs are detected early |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
622 |
copies = self._getcopies(ctx, parents, copyfiles) |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
623 |
cleanp2 = set() |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
624 |
if len(parents) == 2: |
27719
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
625 |
d = parents[1].manifest().diff(ctx.manifest(), clean=True) |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
626 |
for f, value in d.items(): |
27719
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
627 |
if value is None: |
7ce8a13b8d77
convert: use manifest.diff() instead of ctx.status()
Martin von Zweigbergk <martinvonz@google.com>
parents:
27718
diff
changeset
|
628 |
cleanp2.add(f) |
22299
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
629 |
changes = [(f, rev) for f in files if f not in self.ignored] |
98aafdf4cbf6
convert: refactor hg getchanges and caching
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
630 |
changes.sort() |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
24306
diff
changeset
|
631 |
return changes, copies, cleanp2 |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
632 |
|
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
633 |
def _getcopies(self, ctx, parents, files): |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
634 |
copies = {} |
5280
11e1e574da02
convert: mercurial_source: also search for copies in modified files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5279
diff
changeset
|
635 |
for name in files: |
7231
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
636 |
if name in self.ignored: |
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
637 |
continue |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
638 |
try: |
41771
1312afae2d51
convert: migrate to new method for getting copy source
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
639 |
copysource = ctx.filectx(name).copysource() |
19457
948df0f10ec1
convert: fix bad conversion of copies when hg.startrev is specified
Mads Kiilerich <madski@unity3d.com>
parents:
19120
diff
changeset
|
640 |
if copysource in self.ignored: |
7231
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
641 |
continue |
9532
989cb39d1df4
convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents:
9531
diff
changeset
|
642 |
# Ignore copy sources not in parent revisions |
36340
06464d1ce6cd
convert: don't reimplement any()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36148
diff
changeset
|
643 |
if not any(copysource in p for p in parents): |
9532
989cb39d1df4
convert/hg: handle bogus copy records (issue1843)
Patrick Mezard <pmezard@gmail.com>
parents:
9531
diff
changeset
|
644 |
continue |
7231
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
645 |
copies[name] = copysource |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
646 |
except TypeError: |
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
647 |
pass |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25589
diff
changeset
|
648 |
except error.LookupError as e: |
7231
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
649 |
if not self.ignoreerrors: |
8e7130a10f3b
convert: ignore hg source errors with hg.ignoreerrors (issue 1357)
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
650 |
raise |
8456
e9e2a2c9b294
convert: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
651 |
self.ignored.add(name) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
652 |
self.ui.warn(_(b'ignoring: %s\n') % e) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
653 |
return copies |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5131
diff
changeset
|
654 |
|
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
655 |
def getcommit(self, rev): |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
656 |
ctx = self._changectx(rev) |
28900
b65966f50058
convert: keep converted hg parents that are outside convert.hg.revs (BC)
Mads Kiilerich <madski@unity3d.com>
parents:
28861
diff
changeset
|
657 |
_parents = self._parents(ctx) |
b65966f50058
convert: keep converted hg parents that are outside convert.hg.revs (BC)
Mads Kiilerich <madski@unity3d.com>
parents:
28861
diff
changeset
|
658 |
parents = [p.hex() for p in _parents] |
b65966f50058
convert: keep converted hg parents that are outside convert.hg.revs (BC)
Mads Kiilerich <madski@unity3d.com>
parents:
28861
diff
changeset
|
659 |
optparents = [p.hex() for p in ctx.parents() if p and p not in _parents] |
25570
7cc1d33f0ba6
convert: always track the hg source revision in the internal commit object
Matt Harbison <matt_harbison@yahoo.com>
parents:
25558
diff
changeset
|
660 |
crev = rev |
7cc1d33f0ba6
convert: always track the hg source revision in the internal commit object
Matt Harbison <matt_harbison@yahoo.com>
parents:
25558
diff
changeset
|
661 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
662 |
return common.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
663 |
author=ctx.user(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
664 |
date=dateutil.datestr(ctx.date(), b'%Y-%m-%d %H:%M:%S %1%2'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
665 |
desc=ctx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
666 |
rev=crev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
667 |
parents=parents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
668 |
optparents=optparents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
669 |
branch=ctx.branch(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
670 |
extra=ctx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
671 |
sortkey=ctx.rev(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
672 |
saverev=self.saverev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
673 |
phase=ctx.phase(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
674 |
ctx=ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
675 |
) |
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
676 |
|
41179
77088fa862df
convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents:
39244
diff
changeset
|
677 |
def numcommits(self): |
77088fa862df
convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents:
39244
diff
changeset
|
678 |
return len(self.repo) |
77088fa862df
convert: add missing numcommits() override to hg sources
Matt Harbison <matt_harbison@yahoo.com>
parents:
39244
diff
changeset
|
679 |
|
5013
6c1029aacc9a
convert: Support Mercurial as a source, as well as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
680 |
def gettags(self): |
21498
6b8daeea638a
convert: mercurial source: convert global tags only - not local tags
Mads Kiilerich <madski@unity3d.com>
parents:
21076
diff
changeset
|
681 |
# This will get written to .hgtags, filter non global tags out. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
682 |
tags = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
683 |
t |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
684 |
for t in self.repo.tagslist() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
685 |
if self.repo.tagtype(t[0]) == b'global' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42979
diff
changeset
|
686 |
] |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
687 |
return {name: hex(node) for name, node in tags if self.keep(node)} |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
688 |
|
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
689 |
def getchangedfiles(self, rev, i): |
27717
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
690 |
ctx = self._changectx(rev) |
5deff127286f
convert: use _ prefix for private methods in hg sink
Martin von Zweigbergk <martinvonz@google.com>
parents:
27345
diff
changeset
|
691 |
parents = self._parents(ctx) |
6885
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
692 |
if not parents and i is None: |
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
693 |
i = 0 |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
694 |
ma, r = ctx.manifest().keys(), [] |
6885
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
695 |
else: |
6e253aa04ff7
convert: implement startrev for hg source
Patrick Mezard <pmezard@gmail.com>
parents:
6762
diff
changeset
|
696 |
i = i or 0 |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
697 |
ma, r = self._changedfiles(parents[i], ctx) |
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
698 |
ma, r = [[f for f in l if f not in self.ignored] for l in (ma, r)] |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
699 |
|
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
700 |
if i == 0: |
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
701 |
self._changescache = (rev, (ma, r)) |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
702 |
|
27718
6e1fba0fe453
convert: replace cache of (m,a,r) by (ma,r)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27717
diff
changeset
|
703 |
return ma + r |
5379
d3e51dc804f8
mercurial_source: add --filemap support
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
704 |
|
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
705 |
def converted(self, rev, destrev): |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
706 |
if self.convertfp is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
707 |
self.convertfp = open(self.repo.vfs.join(b'shamap'), b'ab') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
708 |
self.convertfp.write(util.tonativeeol(b'%s %s\n' % (destrev, rev))) |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5553
diff
changeset
|
709 |
self.convertfp.flush() |
5805
e422305e0853
test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents:
5556
diff
changeset
|
710 |
|
e422305e0853
test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents:
5556
diff
changeset
|
711 |
def before(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
712 |
self.ui.debug(b'run hg source pre-conversion action\n') |
5805
e422305e0853
test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents:
5556
diff
changeset
|
713 |
|
e422305e0853
test-convert: test before() and after() conversion actions
Patrick Mezard <pmezard@gmail.com>
parents:
5556
diff
changeset
|
714 |
def after(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
715 |
self.ui.debug(b'run hg source post-conversion action\n') |
8691
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
716 |
|
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
717 |
def hasnativeorder(self): |
a0a541d6fed6
convert: fail fast if source does not support --sourcesort
Patrick Mezard <pmezard@gmail.com>
parents:
8690
diff
changeset
|
718 |
return True |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
719 |
|
18819
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18373
diff
changeset
|
720 |
def hasnativeclose(self): |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18373
diff
changeset
|
721 |
return True |
05acdf8e1f23
convert: add closesort algorithm to mercurial sources
Constantine Linnick <theaspect@gmail.com>
parents:
18373
diff
changeset
|
722 |
|
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
723 |
def lookuprev(self, rev): |
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
724 |
try: |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
45790
diff
changeset
|
725 |
return hex(self.repo.lookup(rev)) |
23926
fea3416f2440
convert: handle LookupError in mercurial_source.lookuprev()
Matt Harbison <matt_harbison@yahoo.com>
parents:
22698
diff
changeset
|
726 |
except (error.RepoError, error.LookupError): |
8693
68e0a55eee6e
convert: rewrite tags when converting from hg to hg
Patrick Mezard <pmezard@gmail.com>
parents:
8691
diff
changeset
|
727 |
return None |
13757
043238abda94
convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents:
13746
diff
changeset
|
728 |
|
043238abda94
convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents:
13746
diff
changeset
|
729 |
def getbookmarks(self): |
043238abda94
convert: add bookmark support to hg source
Edouard Gomez <ed.gomez@free.fr>
parents:
13746
diff
changeset
|
730 |
return bookmarks.listbookmarks(self.repo) |
19120
58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
Ben Goswami <bengoswami@fb.com>
parents:
18819
diff
changeset
|
731 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
732 |
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
|
733 |
"""Mercurial, revision string is a 40 byte hex""" |
20373
e8203629371b
convert: add mapname parameter to checkrevformat
Sean Farley <sean.michael.farley@gmail.com>
parents:
20372
diff
changeset
|
734 |
self.checkhexformat(revstr, mapname) |