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
=== modified file 'breezy/branch.py'
--- breezy/branch.py 2019-10-19 23:18:56 +0000
+++ breezy/branch.py 2020-01-18 15:06:59 +0000
@@ -1281,18 +1281,7 @@
1281 def update_references(self, target):1281 def update_references(self, target):
1282 if not getattr(self._format, 'supports_reference_locations', False):1282 if not getattr(self._format, 'supports_reference_locations', False):
1283 return1283 return
1284 reference_dict = self._get_all_reference_info()1284 return InterBranch.get(self, target).update_references()
1285 if len(reference_dict) == 0:
1286 return
1287 old_base = self.base
1288 new_base = target.base
1289 target_reference_dict = target._get_all_reference_info()
1290 for tree_path, (branch_location, file_id) in viewitems(reference_dict):
1291 branch_location = urlutils.rebase_url(branch_location,
1292 old_base, new_base)
1293 target_reference_dict.setdefault(
1294 tree_path, (branch_location, file_id))
1295 target._set_all_reference_info(target_reference_dict)
12961285
1297 def check(self, refs):1286 def check(self, refs):
1298 """Check consistency of the branch.1287 """Check consistency of the branch.
@@ -2119,6 +2108,11 @@
2119 """2108 """
2120 raise NotImplementedError(self.fetch)2109 raise NotImplementedError(self.fetch)
21212110
2111 def update_references(self):
2112 """Import reference information from source to target.
2113 """
2114 raise NotImplementedError(self.update_references)
2115
21222116
2123def _fix_overwrite_type(overwrite):2117def _fix_overwrite_type(overwrite):
2124 if isinstance(overwrite, bool):2118 if isinstance(overwrite, bool):
@@ -2155,8 +2149,8 @@
2155 be truncated to end with revision_id.2149 be truncated to end with revision_id.
2156 """2150 """
2157 with self.source.lock_read(), self.target.lock_write():2151 with self.source.lock_read(), self.target.lock_write():
2158 self.source.update_references(self.target)
2159 self.source._synchronize_history(self.target, revision_id)2152 self.source._synchronize_history(self.target, revision_id)
2153 self.update_references()
2160 try:2154 try:
2161 parent = self.source.get_parent()2155 parent = self.source.get_parent()
2162 except errors.InaccessibleParent as e:2156 except errors.InaccessibleParent as e:
@@ -2325,7 +2319,6 @@
2325 result.source_branch = self.source2319 result.source_branch = self.source
2326 result.target_branch = self.target2320 result.target_branch = self.target
2327 result.old_revno, result.old_revid = self.target.last_revision_info()2321 result.old_revno, result.old_revid = self.target.last_revision_info()
2328 self.source.update_references(self.target)
2329 overwrite = _fix_overwrite_type(overwrite)2322 overwrite = _fix_overwrite_type(overwrite)
2330 if result.old_revid != stop_revision:2323 if result.old_revid != stop_revision:
2331 # We assume that during 'push' this repository is closer than2324 # We assume that during 'push' this repository is closer than
@@ -2337,6 +2330,7 @@
2337 result.tag_updates, result.tag_conflicts = (2330 result.tag_updates, result.tag_conflicts = (
2338 self.source.tags.merge_to(2331 self.source.tags.merge_to(
2339 self.target.tags, "tags" in overwrite))2332 self.target.tags, "tags" in overwrite))
2333 self.update_references()
2340 result.new_revno, result.new_revid = self.target.last_revision_info()2334 result.new_revno, result.new_revid = self.target.last_revision_info()
2341 return result2335 return result
23422336
@@ -2372,7 +2366,6 @@
2372 with self.source.lock_read():2366 with self.source.lock_read():
2373 # We assume that during 'pull' the target repository is closer than2367 # We assume that during 'pull' the target repository is closer than
2374 # the source one.2368 # the source one.
2375 self.source.update_references(self.target)
2376 graph = self.target.repository.get_graph(self.source.repository)2369 graph = self.target.repository.get_graph(self.source.repository)
2377 # TODO: Branch formats should have a flag that indicates2370 # TODO: Branch formats should have a flag that indicates
2378 # that revno's are expensive, and pull() should honor that flag.2371 # that revno's are expensive, and pull() should honor that flag.
@@ -2389,6 +2382,7 @@
2389 self.source.tags.merge_to(2382 self.source.tags.merge_to(
2390 self.target.tags, "tags" in overwrite,2383 self.target.tags, "tags" in overwrite,
2391 ignore_master=not merge_tags_to_master))2384 ignore_master=not merge_tags_to_master))
2385 self.update_references()
2392 result.new_revno, result.new_revid = (2386 result.new_revno, result.new_revid = (
2393 self.target.last_revision_info())2387 self.target.last_revision_info())
2394 if _hook_master:2388 if _hook_master:
@@ -2402,5 +2396,21 @@
2402 hook(result)2396 hook(result)
2403 return result2397 return result
24042398
2399 def update_references(self):
2400 if not getattr(self.source._format, 'supports_reference_locations', False):
2401 return
2402 reference_dict = self.source._get_all_reference_info()
2403 if len(reference_dict) == 0:
2404 return
2405 old_base = self.source.base
2406 new_base = self.target.base
2407 target_reference_dict = self.target._get_all_reference_info()
2408 for tree_path, (branch_location, file_id) in viewitems(reference_dict):
2409 branch_location = urlutils.rebase_url(branch_location,
2410 old_base, new_base)
2411 target_reference_dict.setdefault(
2412 tree_path, (branch_location, file_id))
2413 self.target._set_all_reference_info(target_reference_dict)
2414
24052415
2406InterBranch.register_optimiser(GenericInterBranch)2416InterBranch.register_optimiser(GenericInterBranch)
24072417
=== modified file 'breezy/git/branch.py'
--- breezy/git/branch.py 2020-01-16 23:24:40 +0000
+++ breezy/git/branch.py 2020-01-18 15:06:59 +0000
@@ -22,6 +22,11 @@
22from io import BytesIO22from io import BytesIO
23from collections import defaultdict23from collections import defaultdict
2424
25from dulwich.config import (
26 ConfigFile as GitConfigFile,
27 parse_submodules,
28 )
29
25from dulwich.objects import (30from dulwich.objects import (
26 NotCommitError,31 NotCommitError,
27 ZERO_SHA,32 ZERO_SHA,
@@ -980,6 +985,20 @@
980 other_branch=self.source)985 other_branch=self.source)
981 return head, refs986 return head, refs
982987
988 def update_references(self, revid=None):
989 if revid is None:
990 revid = self.target.last_revision()
991 tree = self.target.repository.revision_tree(revid)
992 try:
993 with tree.get_file('.gitmodules') as f:
994 for path, url, section in parse_submodules(
995 GitConfigFile.from_file(f)):
996 self.target.set_reference_info(
997 path.decode('utf-8'), url.decode('utf-8'),
998 tree.path2id(path.decode('utf-8')))
999 except errors.NoSuchFile:
1000 pass
1001
983 def _basic_pull(self, stop_revision, overwrite, run_hooks,1002 def _basic_pull(self, stop_revision, overwrite, run_hooks,
984 _override_hook_target, _hook_master):1003 _override_hook_target, _hook_master):
985 if overwrite is True:1004 if overwrite is True:
@@ -1007,6 +1026,7 @@
1007 result.tag_conflicts = tags_ret1026 result.tag_conflicts = tags_ret
1008 (result.new_revno, result.new_revid) = \1027 (result.new_revno, result.new_revid) = \
1009 self.target.last_revision_info()1028 self.target.last_revision_info()
1029 self.update_references(revid=result.new_revid)
1010 if _hook_master:1030 if _hook_master:
1011 result.master_branch = _hook_master1031 result.master_branch = _hook_master
1012 result.local_branch = result.target_branch1032 result.local_branch = result.target_branch
@@ -1075,6 +1095,7 @@
1075 self.target.tags, "tags" in overwrite, ignore_master=True)1095 self.target.tags, "tags" in overwrite, ignore_master=True)
1076 (result.tag_updates, result.tag_conflicts) = tags_ret1096 (result.tag_updates, result.tag_conflicts) = tags_ret
1077 result.new_revno, result.new_revid = self.target.last_revision_info()1097 result.new_revno, result.new_revid = self.target.last_revision_info()
1098 self.update_references(revid=result.new_revid)
1078 return result1099 return result
10791100
10801101

Subscribers

People subscribed via source and target branches