Merge lp:~jelmer/brz/fix-submodule-import into lp:brz

Proposed by Jelmer Vernooij on 2020-01-24
Status: Merged
Approved by: Jelmer Vernooij on 2020-01-24
Approved revision: 7460
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/fix-submodule-import
Merge into: lp:brz
Diff against target: 162 lines (+49/-9)
7 files modified
breezy/git/branch.py (+2/-2)
breezy/git/fetch.py (+3/-2)
breezy/git/tests/__init__.py (+6/-0)
breezy/git/tests/test_branch.py (+29/-0)
breezy/git/tests/test_fetch.py (+1/-1)
breezy/tree.py (+4/-4)
doc/en/release-notes/brz-3.1.txt (+4/-0)
To merge this branch: bzr merge lp:~jelmer/brz/fix-submodule-import
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve on 2020-01-24
Review via email: mp+378021@code.launchpad.net

Commit message

Support importing Git submodules as tree references.

Description of the change

Support importing Git submodules as tree references.

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve
lp:~jelmer/brz/fix-submodule-import updated on 2020-01-24
7460. By Jelmer Vernooij on 2020-01-24

Fix tests on Python 3.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/git/branch.py'
2--- breezy/git/branch.py 2020-01-20 00:51:05 +0000
3+++ breezy/git/branch.py 2020-01-24 02:05:30 +0000
4@@ -987,8 +987,8 @@
5 for path, url, section in parse_submodules(
6 GitConfigFile.from_file(f)):
7 self.target.set_reference_info(
8- path.decode('utf-8'), url.decode('utf-8'),
9- tree.path2id(path.decode('utf-8')))
10+ tree.path2id(path.decode('utf-8')), url.decode('utf-8'),
11+ path.decode('utf-8'))
12 except errors.NoSuchFile:
13 pass
14
15
16=== modified file 'breezy/git/fetch.py'
17--- breezy/git/fetch.py 2020-01-18 00:08:16 +0000
18+++ breezy/git/fetch.py 2020-01-24 02:05:30 +0000
19@@ -126,7 +126,7 @@
20 # Check what revision we should store
21 parent_keys = []
22 for ptree in parent_bzr_trees:
23- ppath = find_previous_path(base_bzr_tree, ptree, decoded_path, file_id)
24+ ppath = find_previous_path(base_bzr_tree, ptree, decoded_path, file_id, recurse='none')
25 if ppath is None:
26 continue
27 pkind = ptree.kind(ppath)
28@@ -182,12 +182,13 @@
29 (base_mode, mode) = modes
30 if base_hexsha == hexsha and base_mode == mode:
31 return [], {}
32+ path = path.decode('utf-8')
33 file_id = lookup_file_id(path)
34 invdelta = []
35 ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
36 ie.revision = revision_id
37 if base_hexsha is not None:
38- old_path = path.decode("utf-8") # Renames are not supported yet
39+ old_path = path # Renames are not supported yet
40 if stat.S_ISDIR(base_mode):
41 invdelta.extend(remove_disappeared_children(
42 base_bzr_tree, old_path, lookup_object(base_hexsha), [],
43
44=== modified file 'breezy/git/tests/__init__.py'
45--- breezy/git/tests/__init__.py 2018-11-11 04:08:32 +0000
46+++ breezy/git/tests/__init__.py 2020-01-24 02:05:30 +0000
47@@ -96,6 +96,12 @@
48 self.commit_info.append(b'M %s :%d %s\n'
49 % (mode, mark, self._encode_path(path)))
50
51+ def set_submodule(self, path, commit_sha):
52+ """Create or update submodule at a given path."""
53+ mode = b'160000'
54+ self.commit_info.append(
55+ b'M %s %s %s\n' % (mode, commit_sha, self._encode_path(path)))
56+
57 def set_file(self, path, content, executable):
58 """Create or update content at a given path."""
59 mark = self._create_blob(content)
60
61=== modified file 'breezy/git/tests/test_branch.py'
62--- breezy/git/tests/test_branch.py 2019-02-15 18:31:22 +0000
63+++ breezy/git/tests/test_branch.py 2020-01-24 02:05:30 +0000
64@@ -245,6 +245,35 @@
65 # Dulwich raises a UserWarning for tags with invalid target
66 self.assertIn(('ref refs/tags/lala points at non-present sha ' + ("aa" * 20), ), [w.args for w in warnings])
67
68+ def test_interbranch_pull_submodule(self):
69+ path = "d"
70+ os.mkdir(path)
71+ os.chdir(path)
72+ GitRepo.init('.')
73+ bb = tests.GitBranchBuilder()
74+ bb.set_file("foobar", b"foo\nbar\n", False)
75+ mark1 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
76+ bb.set_submodule("core", b'102ee7206ebc4227bec8ac02450972e6738f4a33')
77+ bb.set_file('.gitmodules', b"""\
78+[submodule "core"]
79+ path = core
80+ url = https://github.com/phhusson/QuasselC.git
81+""", False)
82+ mark2 = bb.commit(b"Somebody <somebody@someorg.org>", b"mymsg")
83+ marks = bb.finish()
84+ os.chdir("..")
85+ gitsha1 = marks[mark1]
86+ gitsha2 = marks[mark2]
87+ oldrepo = Repository.open(path)
88+ revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
89+ newbranch = self.make_branch('g')
90+ inter_branch = InterBranch.get(Branch.open(path), newbranch)
91+ inter_branch.pull()
92+ self.assertEqual(revid2, newbranch.last_revision())
93+ self.assertEqual(
94+ ('https://github.com/phhusson/QuasselC.git', 'core'),
95+ newbranch.get_reference_info(newbranch.basis_tree().path2id('core')))
96+
97 def test_interbranch_pull(self):
98 path, (gitsha1, gitsha2) = self.make_tworev_branch()
99 oldrepo = Repository.open(path)
100
101=== modified file 'breezy/git/tests/test_fetch.py'
102--- breezy/git/tests/test_fetch.py 2018-11-11 04:08:32 +0000
103+++ breezy/git/tests/test_fetch.py 2020-01-24 02:05:30 +0000
104@@ -502,7 +502,7 @@
105 self.assertEqual(2, len(ret))
106 self.assertEqual(
107 ret[0], ("foo/bar", None, base_inv.path2id("foo/bar"), None))
108- self.assertEqual(ret[1][:3], ("foo", b"foo",
109+ self.assertEqual(ret[1][:3], ("foo", "foo",
110 self._mapping.generate_file_id("foo")))
111 ie = ret[1][3]
112 self.assertEqual(ie.kind, "tree-reference")
113
114=== modified file 'breezy/tree.py'
115--- breezy/tree.py 2020-01-19 14:53:22 +0000
116+++ breezy/tree.py 2020-01-24 02:05:30 +0000
117@@ -1207,7 +1207,7 @@
118 InterTree.register_optimiser(InterTree)
119
120
121-def find_previous_paths(from_tree, to_tree, paths):
122+def find_previous_paths(from_tree, to_tree, paths, recurse='none'):
123 """Find previous tree paths.
124
125 :param from_tree: From tree
126@@ -1218,11 +1218,11 @@
127 """
128 ret = {}
129 for path in paths:
130- ret[path] = find_previous_path(from_tree, to_tree, path)
131+ ret[path] = find_previous_path(from_tree, to_tree, path, recurse=recurse)
132 return ret
133
134
135-def find_previous_path(from_tree, to_tree, path, file_id=None):
136+def find_previous_path(from_tree, to_tree, path, file_id=None, recurse='none'):
137 """Find previous tree path.
138
139 :param from_tree: From tree
140@@ -1236,7 +1236,7 @@
141 if file_id is None:
142 raise errors.NoSuchFile(path)
143 try:
144- return to_tree.id2path(file_id)
145+ return to_tree.id2path(file_id, recurse=recurse)
146 except errors.NoSuchId:
147 return None
148
149
150=== modified file 'doc/en/release-notes/brz-3.1.txt'
151--- doc/en/release-notes/brz-3.1.txt 2020-01-19 15:58:34 +0000
152+++ doc/en/release-notes/brz-3.1.txt 2020-01-24 02:05:30 +0000
153@@ -99,6 +99,10 @@
154 * CVS pserver URLs now indicate that the pserver protocol is not
155 supported. (Jelmer Vernooń≥)
156
157+ * Git repositories with submodules can now be imported into 2a
158+ branches; submodules are converted to nested trees.
159+ (Jelmer Vernooń≥, #402814)
160+
161 Bug Fixes
162 *********
163

Subscribers

People subscribed via source and target branches