Merge lp:~jelmer/brz/interbranch-update-references into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/interbranch-update-references
Merge into: lp:brz
Diff against target: 150 lines (+46/-15)
2 files modified
breezy/branch.py (+25/-15)
breezy/git/branch.py (+21/-0)
To merge this branch: bzr merge lp:~jelmer/brz/interbranch-update-references
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+377797@code.launchpad.net

Commit message

Support importing tree reference info from Git.

Description of the change

Move the update_references method to InterBranch.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/branch.py'
2--- breezy/branch.py 2019-10-19 23:18:56 +0000
3+++ breezy/branch.py 2020-01-18 15:06:59 +0000
4@@ -1281,18 +1281,7 @@
5 def update_references(self, target):
6 if not getattr(self._format, 'supports_reference_locations', False):
7 return
8- reference_dict = self._get_all_reference_info()
9- if len(reference_dict) == 0:
10- return
11- old_base = self.base
12- new_base = target.base
13- target_reference_dict = target._get_all_reference_info()
14- for tree_path, (branch_location, file_id) in viewitems(reference_dict):
15- branch_location = urlutils.rebase_url(branch_location,
16- old_base, new_base)
17- target_reference_dict.setdefault(
18- tree_path, (branch_location, file_id))
19- target._set_all_reference_info(target_reference_dict)
20+ return InterBranch.get(self, target).update_references()
21
22 def check(self, refs):
23 """Check consistency of the branch.
24@@ -2119,6 +2108,11 @@
25 """
26 raise NotImplementedError(self.fetch)
27
28+ def update_references(self):
29+ """Import reference information from source to target.
30+ """
31+ raise NotImplementedError(self.update_references)
32+
33
34 def _fix_overwrite_type(overwrite):
35 if isinstance(overwrite, bool):
36@@ -2155,8 +2149,8 @@
37 be truncated to end with revision_id.
38 """
39 with self.source.lock_read(), self.target.lock_write():
40- self.source.update_references(self.target)
41 self.source._synchronize_history(self.target, revision_id)
42+ self.update_references()
43 try:
44 parent = self.source.get_parent()
45 except errors.InaccessibleParent as e:
46@@ -2325,7 +2319,6 @@
47 result.source_branch = self.source
48 result.target_branch = self.target
49 result.old_revno, result.old_revid = self.target.last_revision_info()
50- self.source.update_references(self.target)
51 overwrite = _fix_overwrite_type(overwrite)
52 if result.old_revid != stop_revision:
53 # We assume that during 'push' this repository is closer than
54@@ -2337,6 +2330,7 @@
55 result.tag_updates, result.tag_conflicts = (
56 self.source.tags.merge_to(
57 self.target.tags, "tags" in overwrite))
58+ self.update_references()
59 result.new_revno, result.new_revid = self.target.last_revision_info()
60 return result
61
62@@ -2372,7 +2366,6 @@
63 with self.source.lock_read():
64 # We assume that during 'pull' the target repository is closer than
65 # the source one.
66- self.source.update_references(self.target)
67 graph = self.target.repository.get_graph(self.source.repository)
68 # TODO: Branch formats should have a flag that indicates
69 # that revno's are expensive, and pull() should honor that flag.
70@@ -2389,6 +2382,7 @@
71 self.source.tags.merge_to(
72 self.target.tags, "tags" in overwrite,
73 ignore_master=not merge_tags_to_master))
74+ self.update_references()
75 result.new_revno, result.new_revid = (
76 self.target.last_revision_info())
77 if _hook_master:
78@@ -2402,5 +2396,21 @@
79 hook(result)
80 return result
81
82+ def update_references(self):
83+ if not getattr(self.source._format, 'supports_reference_locations', False):
84+ return
85+ reference_dict = self.source._get_all_reference_info()
86+ if len(reference_dict) == 0:
87+ return
88+ old_base = self.source.base
89+ new_base = self.target.base
90+ target_reference_dict = self.target._get_all_reference_info()
91+ for tree_path, (branch_location, file_id) in viewitems(reference_dict):
92+ branch_location = urlutils.rebase_url(branch_location,
93+ old_base, new_base)
94+ target_reference_dict.setdefault(
95+ tree_path, (branch_location, file_id))
96+ self.target._set_all_reference_info(target_reference_dict)
97+
98
99 InterBranch.register_optimiser(GenericInterBranch)
100
101=== modified file 'breezy/git/branch.py'
102--- breezy/git/branch.py 2020-01-16 23:24:40 +0000
103+++ breezy/git/branch.py 2020-01-18 15:06:59 +0000
104@@ -22,6 +22,11 @@
105 from io import BytesIO
106 from collections import defaultdict
107
108+from dulwich.config import (
109+ ConfigFile as GitConfigFile,
110+ parse_submodules,
111+ )
112+
113 from dulwich.objects import (
114 NotCommitError,
115 ZERO_SHA,
116@@ -980,6 +985,20 @@
117 other_branch=self.source)
118 return head, refs
119
120+ def update_references(self, revid=None):
121+ if revid is None:
122+ revid = self.target.last_revision()
123+ tree = self.target.repository.revision_tree(revid)
124+ try:
125+ with tree.get_file('.gitmodules') as f:
126+ for path, url, section in parse_submodules(
127+ GitConfigFile.from_file(f)):
128+ self.target.set_reference_info(
129+ path.decode('utf-8'), url.decode('utf-8'),
130+ tree.path2id(path.decode('utf-8')))
131+ except errors.NoSuchFile:
132+ pass
133+
134 def _basic_pull(self, stop_revision, overwrite, run_hooks,
135 _override_hook_target, _hook_master):
136 if overwrite is True:
137@@ -1007,6 +1026,7 @@
138 result.tag_conflicts = tags_ret
139 (result.new_revno, result.new_revid) = \
140 self.target.last_revision_info()
141+ self.update_references(revid=result.new_revid)
142 if _hook_master:
143 result.master_branch = _hook_master
144 result.local_branch = result.target_branch
145@@ -1075,6 +1095,7 @@
146 self.target.tags, "tags" in overwrite, ignore_master=True)
147 (result.tag_updates, result.tag_conflicts) = tags_ret
148 result.new_revno, result.new_revid = self.target.last_revision_info()
149+ self.update_references(revid=result.new_revid)
150 return result
151
152

Subscribers

People subscribed via source and target branches