~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: James Blackwell
  • Date: 2006-05-05 01:05:04 UTC
  • mfrom: (1697 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1700.
  • Revision ID: jblack@merconline.com-20060505010504-264cb48507e53b64
mergedĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
        assert cfg.get_option("nickname") == nick
155
155
 
156
156
    nick = property(_get_nick, _set_nick)
157
 
        
 
157
 
 
158
    def is_locked(self):
 
159
        raise NotImplementedError('is_locked is abstract')
 
160
 
158
161
    def lock_write(self):
159
162
        raise NotImplementedError('lock_write is abstract')
160
 
        
 
163
 
161
164
    def lock_read(self):
162
165
        raise NotImplementedError('lock_read is abstract')
163
166
 
168
171
        """Return lock mode for the Branch: 'r', 'w' or None"""
169
172
        raise NotImplementedError(self.peek_lock_mode)
170
173
 
 
174
    def get_physical_lock_status(self):
 
175
        raise NotImplementedError('get_physical_lock_status is abstract')
 
176
 
171
177
    def abspath(self, name):
172
178
        """Return absolute filename for something in the branch
173
179
        
197
203
        (copied, failures).
198
204
        """
199
205
        if self.base == from_branch.base:
200
 
            raise Exception("can't fetch from a branch to itself %s, %s" % 
201
 
                            (self.base, to_branch.base))
 
206
            return (0, [])
202
207
        if pb is None:
203
208
            nested_pb = bzrlib.ui.ui_factory.nested_progress_bar()
204
209
            pb = nested_pb
224
229
            from_branch.unlock()
225
230
 
226
231
    def get_bound_location(self):
227
 
        """Return the URL of the rbanch we are bound to.
 
232
        """Return the URL of the branch we are bound to.
228
233
 
229
234
        Older format branches cannot bind, please be sure to use a metadir
230
235
        branch.
334
339
        """
335
340
        raise NotImplementedError('update_revisions is abstract')
336
341
 
337
 
    def pullable_revisions(self, other, stop_revision):
338
 
        raise NotImplementedError('pullable_revisions is abstract')
339
 
        
340
342
    def revision_id_to_revno(self, revision_id):
341
343
        """Given a revision id, return its revno"""
342
344
        if revision_id is None:
567
569
        """Return the ASCII format string that identifies this format."""
568
570
        raise NotImplementedError(self.get_format_string)
569
571
 
 
572
    def get_format_description(self):
 
573
        """Return the short format description for this format."""
 
574
        raise NotImplementedError(self.get_format_string)
 
575
 
570
576
    def initialize(self, a_bzrdir):
571
577
        """Create a branch of this format in a_bzrdir."""
572
578
        raise NotImplementedError(self.initialized)
601
607
        assert klass._formats[format.get_format_string()] is format
602
608
        del klass._formats[format.get_format_string()]
603
609
 
 
610
    def __str__(self):
 
611
        return self.get_format_string().rstrip()
 
612
 
604
613
 
605
614
class BzrBranchFormat4(BranchFormat):
606
615
    """Bzr branch format 4.
610
619
     - a branch-lock lock file [ to be shared with the bzrdir ]
611
620
    """
612
621
 
 
622
    def get_format_description(self):
 
623
        """See BranchFormat.get_format_description()."""
 
624
        return "Branch format 4"
 
625
 
613
626
    def initialize(self, a_bzrdir):
614
627
        """Create a branch of this format in a_bzrdir."""
615
628
        mutter('creating branch in %s', a_bzrdir.transport.base)
646
659
                         a_bzrdir=a_bzrdir,
647
660
                         _repository=a_bzrdir.open_repository())
648
661
 
 
662
    def __str__(self):
 
663
        return "Bazaar-NG branch format 4"
 
664
 
649
665
 
650
666
class BzrBranchFormat5(BranchFormat):
651
667
    """Bzr branch format 5.
663
679
    def get_format_string(self):
664
680
        """See BranchFormat.get_format_string()."""
665
681
        return "Bazaar-NG branch format 5\n"
 
682
 
 
683
    def get_format_description(self):
 
684
        """See BranchFormat.get_format_description()."""
 
685
        return "Branch format 5"
666
686
        
667
687
    def initialize(self, a_bzrdir):
668
688
        """Create a branch of this format in a_bzrdir."""
720
740
    def get_format_string(self):
721
741
        """See BranchFormat.get_format_string()."""
722
742
        return "Bazaar-NG Branch Reference Format 1\n"
 
743
 
 
744
    def get_format_description(self):
 
745
        """See BranchFormat.get_format_description()."""
 
746
        return "Checkout reference format 1"
723
747
        
724
748
    def initialize(self, a_bzrdir, target_branch=None):
725
749
        """Create a branch of this format in a_bzrdir."""
921
945
        tree = self.repository.revision_tree(self.last_revision())
922
946
        return tree.inventory.root.file_id
923
947
 
 
948
    def is_locked(self):
 
949
        return self.control_files.is_locked()
 
950
 
924
951
    def lock_write(self):
925
952
        # TODO: test for failed two phase locks. This is known broken.
926
953
        self.control_files.lock_write()
942
969
        else:
943
970
            return self.control_files._lock_mode
944
971
 
 
972
    def get_physical_lock_status(self):
 
973
        return self.control_files.get_physical_lock_status()
 
974
 
945
975
    @needs_read_lock
946
976
    def print_file(self, file, revision_id):
947
977
        """See Branch.print_file."""
1011
1041
        # transaction.register_clean(history, precious=True)
1012
1042
        return list(history)
1013
1043
 
 
1044
    @needs_write_lock
1014
1045
    def update_revisions(self, other, stop_revision=None):
1015
1046
        """See Branch.update_revisions."""
1016
 
        if stop_revision is None:
1017
 
            stop_revision = other.last_revision()
1018
 
        ### Should this be checking is_ancestor instead of revision_history?
1019
 
        if (stop_revision is not None and 
1020
 
            stop_revision in self.revision_history()):
1021
 
            return
1022
 
        self.fetch(other, stop_revision)
1023
 
        pullable_revs = self.pullable_revisions(other, stop_revision)
1024
 
        if len(pullable_revs) > 0:
1025
 
            self.append_revision(*pullable_revs)
 
1047
        other.lock_read()
 
1048
        try:
 
1049
            if stop_revision is None:
 
1050
                stop_revision = other.last_revision()
 
1051
                if stop_revision is None:
 
1052
                    # if there are no commits, we're done.
 
1053
                    return
 
1054
            # whats the current last revision, before we fetch [and change it
 
1055
            # possibly]
 
1056
            last_rev = self.last_revision()
 
1057
            # we fetch here regardless of whether we need to so that we pickup
 
1058
            # filled in ghosts.
 
1059
            self.fetch(other, stop_revision)
 
1060
            my_ancestry = self.repository.get_ancestry(last_rev)
 
1061
            if stop_revision in my_ancestry:
 
1062
                # last_revision is a descendant of stop_revision
 
1063
                return
 
1064
            # stop_revision must be a descendant of last_revision
 
1065
            stop_graph = self.repository.get_revision_graph(stop_revision)
 
1066
            if last_rev is not None and last_rev not in stop_graph:
 
1067
                # our previous tip is not merged into stop_revision
 
1068
                raise errors.DivergedBranches(self, other)
 
1069
            # make a new revision history from the graph
 
1070
            current_rev_id = stop_revision
 
1071
            new_history = []
 
1072
            while current_rev_id not in (None, NULL_REVISION):
 
1073
                new_history.append(current_rev_id)
 
1074
                current_rev_id_parents = stop_graph[current_rev_id]
 
1075
                try:
 
1076
                    current_rev_id = current_rev_id_parents[0]
 
1077
                except IndexError:
 
1078
                    current_rev_id = None
 
1079
            new_history.reverse()
 
1080
            self.set_revision_history(new_history)
 
1081
        finally:
 
1082
            other.unlock()
1026
1083
 
 
1084
    @deprecated_method(zero_eight)
1027
1085
    def pullable_revisions(self, other, stop_revision):
 
1086
        """Please use bzrlib.missing instead."""
1028
1087
        other_revno = other.revision_id_to_revno(stop_revision)
1029
1088
        try:
1030
1089
            return self.missing_revisions(other, other_revno)
1103
1162
        # FIXUP this and get_parent in a future branch format bump:
1104
1163
        # read and rewrite the file, and have the new format code read
1105
1164
        # using .get not .get_utf8. RBC 20060125
1106
 
        self.control_files.put_utf8('parent', url + '\n')
 
1165
        if url is None:
 
1166
            self.control_files._transport.delete('parent')
 
1167
        else:
 
1168
            self.control_files.put_utf8('parent', url + '\n')
1107
1169
 
1108
1170
    def tree_config(self):
1109
1171
        return TreeConfig(self)