/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 bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-17 17:57:15 UTC
  • mfrom: (4454 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4460.
  • Revision ID: john@arbash-meinel.com-20090617175715-p9ebpwx5rhc0qin1
Merge bzr.dev 4454 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
        self._revision_history_cache = None
92
92
        self._revision_id_to_revno_cache = None
93
93
        self._partial_revision_id_to_revno_cache = {}
 
94
        self._partial_revision_history_cache = []
94
95
        self._last_revision_info_cache = None
95
96
        self._merge_sorted_revisions_cache = None
96
97
        self._open_hook()
125
126
            raise errors.UnstackableRepositoryFormat(self.repository._format,
126
127
                self.repository.base)
127
128
 
 
129
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
 
130
        """Extend the partial history to include a given index
 
131
 
 
132
        If a stop_index is supplied, stop when that index has been reached.
 
133
        If a stop_revision is supplied, stop when that revision is
 
134
        encountered.  Otherwise, stop when the beginning of history is
 
135
        reached.
 
136
 
 
137
        :param stop_index: The index which should be present.  When it is
 
138
            present, history extension will stop.
 
139
        :param stop_revision: The revision id which should be present.  When
 
140
            it is encountered, history extension will stop.
 
141
        """
 
142
        if len(self._partial_revision_history_cache) == 0:
 
143
            self._partial_revision_history_cache = [self.last_revision()]
 
144
        repository._iter_for_revno(
 
145
            self.repository, self._partial_revision_history_cache,
 
146
            stop_index=stop_index, stop_revision=stop_revision)
 
147
        if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
 
148
            self._partial_revision_history_cache.pop()
 
149
 
128
150
    @staticmethod
129
151
    def open(base, _unsupported=False, possible_transports=None):
130
152
        """Open the branch rooted at base.
498
520
        """
499
521
        raise errors.UpgradeRequired(self.base)
500
522
 
 
523
    def set_append_revisions_only(self, enabled):
 
524
        if not self._format.supports_set_append_revisions_only():
 
525
            raise errors.UpgradeRequired(self.base)
 
526
        if enabled:
 
527
            value = 'True'
 
528
        else:
 
529
            value = 'False'
 
530
        self.get_config().set_user_option('append_revisions_only', value,
 
531
            warn_masked=True)
 
532
 
501
533
    def set_reference_info(self, file_id, tree_path, branch_location):
502
534
        """Set the branch location to use for a tree reference."""
503
535
        raise errors.UnsupportedOperation(self.set_reference_info, self)
698
730
        self._revision_id_to_revno_cache = None
699
731
        self._last_revision_info_cache = None
700
732
        self._merge_sorted_revisions_cache = None
 
733
        self._partial_revision_history_cache = []
 
734
        self._partial_revision_id_to_revno_cache = {}
701
735
 
702
736
    def _gen_revision_history(self):
703
737
        """Return sequence of revision hashes on to this branch.
742
776
        """Older format branches cannot bind or unbind."""
743
777
        raise errors.UpgradeRequired(self.base)
744
778
 
745
 
    def set_append_revisions_only(self, enabled):
746
 
        """Older format branches are never restricted to append-only"""
747
 
        raise errors.UpgradeRequired(self.base)
748
 
 
749
779
    def last_revision(self):
750
780
        """Return last revision id, or NULL_REVISION."""
751
781
        return self.last_revision_info()[1]
831
861
        except ValueError:
832
862
            raise errors.NoSuchRevision(self, revision_id)
833
863
 
 
864
    @needs_read_lock
834
865
    def get_rev_id(self, revno, history=None):
835
866
        """Find the revision id of the specified revno."""
836
867
        if revno == 0:
837
868
            return _mod_revision.NULL_REVISION
838
 
        if history is None:
839
 
            history = self.revision_history()
840
 
        if revno <= 0 or revno > len(history):
 
869
        last_revno, last_revid = self.last_revision_info()
 
870
        if revno == last_revno:
 
871
            return last_revid
 
872
        if revno <= 0 or revno > last_revno:
841
873
            raise errors.NoSuchRevision(self, revno)
842
 
        return history[revno - 1]
 
874
        distance_from_last = last_revno - revno
 
875
        if len(self._partial_revision_history_cache) <= distance_from_last:
 
876
            self._extend_partial_history(distance_from_last)
 
877
        return self._partial_revision_history_cache[distance_from_last]
843
878
 
844
879
    @needs_write_lock
845
880
    def pull(self, source, overwrite=False, stop_revision=None,
1085
1120
        source_revno, source_revision_id = self.last_revision_info()
1086
1121
        if revision_id is None:
1087
1122
            revno, revision_id = source_revno, source_revision_id
1088
 
        elif source_revision_id == revision_id:
1089
 
            # we know the revno without needing to walk all of history
1090
 
            revno = source_revno
1091
1123
        else:
1092
 
            # To figure out the revno for a random revision, we need to build
1093
 
            # the revision history, and count its length.
1094
 
            # We don't care about the order, just how long it is.
1095
 
            # Alternatively, we could start at the current location, and count
1096
 
            # backwards. But there is no guarantee that we will find it since
1097
 
            # it may be a merged revision.
1098
 
            revno = len(list(self.repository.iter_reverse_revision_history(
1099
 
                                                                revision_id)))
 
1124
            graph = self.repository.get_graph()
 
1125
            try:
 
1126
                revno = graph.find_distance_to_null(revision_id, 
 
1127
                    [(source_revision_id, source_revno)])
 
1128
            except errors.GhostRevisionsHaveNoRevno:
 
1129
                # Default to 1, if we can't find anything else
 
1130
                revno = 1
1100
1131
        destination.set_last_revision_info(revno, revision_id)
1101
1132
 
1102
1133
    @needs_read_lock
1147
1178
 
1148
1179
        :return: A BranchCheckResult.
1149
1180
        """
 
1181
        ret = BranchCheckResult(self)
1150
1182
        mainline_parent_id = None
1151
1183
        last_revno, last_revision_id = self.last_revision_info()
1152
 
        real_rev_history = list(self.repository.iter_reverse_revision_history(
1153
 
                                last_revision_id))
 
1184
        real_rev_history = []
 
1185
        try:
 
1186
            for revid in self.repository.iter_reverse_revision_history(
 
1187
                last_revision_id):
 
1188
                real_rev_history.append(revid)
 
1189
        except errors.RevisionNotPresent:
 
1190
            ret.ghosts_in_mainline = True
 
1191
        else:
 
1192
            ret.ghosts_in_mainline = False
1154
1193
        real_rev_history.reverse()
1155
1194
        if len(real_rev_history) != last_revno:
1156
1195
            raise errors.BzrCheckError('revno does not match len(mainline)'
1172
1211
                                        "parents of {%s}"
1173
1212
                                        % (mainline_parent_id, revision_id))
1174
1213
            mainline_parent_id = revision_id
1175
 
        return BranchCheckResult(self)
 
1214
        return ret
1176
1215
 
1177
1216
    def _get_checkout_format(self):
1178
1217
        """Return the most suitable metadir for a checkout of this branch.
1345
1384
    _formats = {}
1346
1385
    """The known formats."""
1347
1386
 
 
1387
    can_set_append_revisions_only = True
 
1388
 
1348
1389
    def __eq__(self, other):
1349
1390
        return self.__class__ is other.__class__
1350
1391
 
1503
1544
    def set_default_format(klass, format):
1504
1545
        klass._default_format = format
1505
1546
 
 
1547
    def supports_set_append_revisions_only(self):
 
1548
        """True if this format supports set_append_revisions_only."""
 
1549
        return False
 
1550
 
1506
1551
    def supports_stacking(self):
1507
1552
        """True if this format records a stacked-on branch."""
1508
1553
        return False
1790
1835
        """See bzrlib.branch.BranchFormat.make_tags()."""
1791
1836
        return BasicTags(branch)
1792
1837
 
 
1838
    def supports_set_append_revisions_only(self):
 
1839
        return True
1793
1840
 
1794
1841
 
1795
1842
class BzrBranchFormat8(BranchFormatMetadir):
1824
1871
        """See bzrlib.branch.BranchFormat.make_tags()."""
1825
1872
        return BasicTags(branch)
1826
1873
 
 
1874
    def supports_set_append_revisions_only(self):
 
1875
        return True
 
1876
 
1827
1877
    def supports_stacking(self):
1828
1878
        return True
1829
1879
 
1858
1908
        """See BranchFormat.get_format_description()."""
1859
1909
        return "Branch format 7"
1860
1910
 
 
1911
    def supports_set_append_revisions_only(self):
 
1912
        return True
 
1913
 
1861
1914
    supports_reference_locations = False
1862
1915
 
1863
1916
 
2372
2425
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2373
2426
        super(BzrBranch8, self).__init__(*args, **kwargs)
2374
2427
        self._last_revision_info_cache = None
2375
 
        self._partial_revision_history_cache = []
2376
2428
        self._reference_info = None
2377
2429
 
2378
2430
    def _clear_cached_state(self):
2379
2431
        super(BzrBranch8, self)._clear_cached_state()
2380
2432
        self._last_revision_info_cache = None
2381
 
        self._partial_revision_history_cache = []
2382
2433
        self._reference_info = None
2383
2434
 
2384
2435
    def _last_revision_info(self):
2440
2491
        self._extend_partial_history(stop_index=last_revno-1)
2441
2492
        return list(reversed(self._partial_revision_history_cache))
2442
2493
 
2443
 
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
2444
 
        """Extend the partial history to include a given index
2445
 
 
2446
 
        If a stop_index is supplied, stop when that index has been reached.
2447
 
        If a stop_revision is supplied, stop when that revision is
2448
 
        encountered.  Otherwise, stop when the beginning of history is
2449
 
        reached.
2450
 
 
2451
 
        :param stop_index: The index which should be present.  When it is
2452
 
            present, history extension will stop.
2453
 
        :param revision_id: The revision id which should be present.  When
2454
 
            it is encountered, history extension will stop.
2455
 
        """
2456
 
        repo = self.repository
2457
 
        if len(self._partial_revision_history_cache) == 0:
2458
 
            iterator = repo.iter_reverse_revision_history(self.last_revision())
2459
 
        else:
2460
 
            start_revision = self._partial_revision_history_cache[-1]
2461
 
            iterator = repo.iter_reverse_revision_history(start_revision)
2462
 
            #skip the last revision in the list
2463
 
            next_revision = iterator.next()
2464
 
        for revision_id in iterator:
2465
 
            self._partial_revision_history_cache.append(revision_id)
2466
 
            if (stop_index is not None and
2467
 
                len(self._partial_revision_history_cache) > stop_index):
2468
 
                break
2469
 
            if revision_id == stop_revision:
2470
 
                break
2471
 
 
2472
2494
    def _write_revision_history(self, history):
2473
2495
        """Factored out of set_revision_history.
2474
2496
 
2617
2639
            raise errors.NotStacked(self)
2618
2640
        return stacked_url
2619
2641
 
2620
 
    def set_append_revisions_only(self, enabled):
2621
 
        if enabled:
2622
 
            value = 'True'
2623
 
        else:
2624
 
            value = 'False'
2625
 
        self.get_config().set_user_option('append_revisions_only', value,
2626
 
            warn_masked=True)
2627
 
 
2628
2642
    def _get_append_revisions_only(self):
2629
2643
        value = self.get_config().get_user_option('append_revisions_only')
2630
2644
        return value == 'True'
2780
2794
 
2781
2795
    def __init__(self, branch):
2782
2796
        self.branch = branch
 
2797
        self.ghosts_in_mainline = False
2783
2798
 
2784
2799
    def report_results(self, verbose):
2785
2800
        """Report the check results via trace.note.
2790
2805
        note('checked branch %s format %s',
2791
2806
             self.branch.base,
2792
2807
             self.branch._format)
 
2808
        if self.ghosts_in_mainline:
 
2809
            note('branch contains ghosts in mainline')
2793
2810
 
2794
2811
 
2795
2812
class Converter5to6(object):