159
159
# Update the branches
160
160
self.note("Updating branch information ...")
161
updater = BranchUpdater(self.branch, self.cache_mgr,
161
updater = GenericBranchUpdater(self.branch, self.cache_mgr,
162
162
helpers.invert_dict(self.heads), self.last_ref)
163
branches_updated = updater.update()
164
self._branch_count = 1
166
# Update the working tree, if any
163
branches_updated, branches_lost = updater.update()
164
self._branch_count = len(branches_updated)
166
# Tell the user about branches that were not created
168
self.warning("Unshared repository - not creating branches for "
169
"these head revisions:")
170
for lost_info in branches_lost:
171
head_revision = lost_info[1]
172
branch_name = lost_info[0]
173
note("\t %s = %s", head_revision, branch_name)
175
# Update the working trees as requested and dump stats
167
176
self._tree_count = 0
177
remind_about_update = True
168
178
if self.params.get('trees'):
169
179
if self.working_tree is None:
170
180
self.warning("No working tree available to update")
627
637
as required. If it isn't, warnings are produced about the
628
638
lost of information.
630
:return: the list of branches updated
640
:return: updated, lost_heads where
641
updated = the list of branches updated
642
lost_heads = a list of (bazaar-name,revision) for branches that
643
would have been created had the repository been shared
633
default_tip, branch_tips = self._get_matching_branches()
646
default_tip, branch_tips, lost_heads = self._get_matching_branches()
634
647
self._update_branch(self.branch, default_tip)
635
648
updated.append(self.branch)
636
649
for br, tip in branch_tips:
637
650
self._update_branch(br, tip)
638
651
updated.append(br)
652
return updated, lost_heads
641
654
def _get_matching_branches(self):
642
655
"""Get the Bazaar branches.
644
:return: default_tip, branch_tips where
657
:return: default_tip, branch_tips, lost_tips where
645
658
default_tip = the last commit mark for the default branch
646
659
branch_tips = a list of (branch,tip) tuples for other branches.
660
lost_heads = a list of (bazaar-name,revision) for branches that
661
would have been created had the repository been shared
649
return self.heads_by_ref[self.last_ref][0], []
651
#names = sorted(heads.keys())
653
# default_head = names.pop(names.index('refs/heads/master'))
655
# # 1st one is as good as any
656
# default_head = names.pop(0)
657
#default_tip = heads[default_head][0]
659
# Get/Create missing branches
661
#return default_tip, branch_tips
663
#shared_repo = self.repo.is_shared()
668
# if not shared_repo:
669
# # Tell the user about their loss
670
# warning("unshared repository so not creating these branches:")
673
# # warning(" %s -> %s", head)
674
# warning(" %s", head)
676
# return default_tip, branch_tips
663
# Until there's a good reason to be more sellective,
664
# use the last imported revision as the tip of the default branch
665
default_tip = self.heads_by_ref[self.last_ref][0]
667
# Convert the reference names into Bazaar speak
668
ref_names = self.heads_by_ref.keys()
669
ref_names.remove(self.last_ref)
670
bzr_names = self._get_bzr_names_from_ref_names(ref_names)
672
# Create/track missing branches
675
shared_repo = self.repo.is_shared()
676
for name in sorted(bzr_names.keys()):
677
ref_name = bzr_names[name]
678
tip = self.heads_by_ref[ref_name][0]
680
# TODO: create the branch
683
lost_head = self.cache_mgr.revision_ids[tip]
684
lost_info = (name, lost_head)
685
lost_heads.append(lost_info)
686
return default_tip, branch_tips, lost_heads
688
def _get_bzr_names_from_ref_names(self, ref_names):
689
"""Map reference names to Bazaar branch names."""
691
for ref_name in sorted(ref_names):
692
parts = ref_name.split('/')
693
if parts[0] == 'refs':
695
full_name = "--".join(parts)
696
bazaar_name = parts[-1]
697
if bazaar_name in bazaar_names:
698
bazaar_name = full_name
699
bazaar_names[bazaar_name] = ref_name
678
702
def _update_branch(self, br, last_mark):
679
703
"""Update a branch with last revision and tag information."""