/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to processors/generic_processor.py

report lost branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
 
89
89
    def warning(self, msg, *args):
90
90
        """Output a warning but timestamp it."""
91
 
        msg = "%s %s" % (self._time_of_day(), msg)
 
91
        msg = "%s WARNING: %s" % (self._time_of_day(), msg)
92
92
        warning(msg, *args)
93
93
 
94
94
    def _time_of_day(self):
158
158
 
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
165
 
 
166
 
        # Update the working tree, if any
 
163
        branches_updated, branches_lost = updater.update()
 
164
        self._branch_count = len(branches_updated)
 
165
 
 
166
        # Tell the user about branches that were not created
 
167
        if branches_lost:
 
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)
 
174
 
 
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")
176
186
                self.note("Updating the working tree ...")
177
187
                self.working_tree.update(reporter)
178
188
                self._tree_count = 1
179
 
        else:
180
 
            self.note("NOTE: Use 'bzr update' to refresh your working trees")
 
189
                remind_about_update = False
181
190
        self.dump_stats()
 
191
        if remind_about_update:
 
192
            self.note("NOTE: To refresh working trees, use 'bzr update'")
182
193
 
183
194
    def init_stats(self):
184
195
        self._revision_count = 0
259
270
 
260
271
    def progress_handler(self, cmd):
261
272
        """Process a ProgressCommand."""
262
 
        # We could use a progress bar here but timestamped messages
263
 
        # is more useful for determining when things might complete
 
273
        # We could use a progress bar here instead
264
274
        self.note("progress %s" % (cmd.message,))
265
275
 
266
276
    def reset_handler(self, cmd):
605
615
        return basename, ie
606
616
 
607
617
 
608
 
class BranchUpdater(object):
 
618
class GenericBranchUpdater(object):
609
619
 
610
620
    def __init__(self, branch, cache_mgr, heads_by_ref, last_ref):
611
621
        """Create an object responsible for updating branches.
627
637
        as required. If it isn't, warnings are produced about the
628
638
        lost of information.
629
639
 
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
631
644
        """
632
645
        updated = []
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)
639
 
        return updated
 
652
        return updated, lost_heads
640
653
 
641
654
    def _get_matching_branches(self):
642
655
        """Get the Bazaar branches.
643
656
 
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
647
662
        """
648
 
        # simple for now
649
 
        return self.heads_by_ref[self.last_ref][0], []
650
 
 
651
 
        #names = sorted(heads.keys())
652
 
        #try:
653
 
        #    default_head = names.pop(names.index('refs/heads/master'))
654
 
        #except ValueError:
655
 
        #    # 1st one is as good as any
656
 
        #    default_head = names.pop(0)
657
 
        #default_tip = heads[default_head][0]
658
 
 
659
 
        # Get/Create missing branches
660
 
        #branch_tips = []
661
 
        #return default_tip, branch_tips
662
 
 
663
 
        #shared_repo = self.repo.is_shared()
664
 
        #for head in heads:
665
 
        #    # TODO
666
 
        #    pass
667
 
#
668
 
#        if not shared_repo:
669
 
#            # Tell the user about their loss
670
 
#            warning("unshared repository so not creating these branches:")
671
 
#            for head in heads:
672
 
#                # rev = ...
673
 
#                # warning("  %s -> %s", head)
674
 
#                warning("  %s", head)
675
 
#            branch_tips = []
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]
 
666
 
 
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)
 
671
 
 
672
        # Create/track missing branches
 
673
        branch_tips = []
 
674
        lost_heads = []
 
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]
 
679
            if shared_repo:
 
680
                # TODO: create the branch
 
681
                pass
 
682
            else:
 
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
 
687
 
 
688
    def _get_bzr_names_from_ref_names(self, ref_names):
 
689
        """Map reference names to Bazaar branch names."""
 
690
        bazaar_names = {}
 
691
        for ref_name in sorted(ref_names):
 
692
            parts = ref_name.split('/')
 
693
            if parts[0] == 'refs':
 
694
                parts.pop(0)
 
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
 
700
        return bazaar_names
677
701
 
678
702
    def _update_branch(self, br, last_mark):
679
703
        """Update a branch with last revision and tag information."""
684
708
        #if self.tags:
685
709
        #    br.tags._set_tag_dict(self.tags)
686
710
        note("\t branch %s has %d revisions", br.nick, revno)
687