~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-17 16:37:11 UTC
  • mfrom: (4454 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4466.
  • Revision ID: v.ladeuil+lp@free.fr-20090617163711-iqubyv0tlqr8ayvl
Merge trunk@4454

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,
1349
1384
    _formats = {}
1350
1385
    """The known formats."""
1351
1386
 
 
1387
    can_set_append_revisions_only = True
 
1388
 
1352
1389
    def __eq__(self, other):
1353
1390
        return self.__class__ is other.__class__
1354
1391
 
1507
1544
    def set_default_format(klass, format):
1508
1545
        klass._default_format = format
1509
1546
 
 
1547
    def supports_set_append_revisions_only(self):
 
1548
        """True if this format supports set_append_revisions_only."""
 
1549
        return False
 
1550
 
1510
1551
    def supports_stacking(self):
1511
1552
        """True if this format records a stacked-on branch."""
1512
1553
        return False
1794
1835
        """See bzrlib.branch.BranchFormat.make_tags()."""
1795
1836
        return BasicTags(branch)
1796
1837
 
 
1838
    def supports_set_append_revisions_only(self):
 
1839
        return True
1797
1840
 
1798
1841
 
1799
1842
class BzrBranchFormat8(BranchFormatMetadir):
1828
1871
        """See bzrlib.branch.BranchFormat.make_tags()."""
1829
1872
        return BasicTags(branch)
1830
1873
 
 
1874
    def supports_set_append_revisions_only(self):
 
1875
        return True
 
1876
 
1831
1877
    def supports_stacking(self):
1832
1878
        return True
1833
1879
 
1862
1908
        """See BranchFormat.get_format_description()."""
1863
1909
        return "Branch format 7"
1864
1910
 
 
1911
    def supports_set_append_revisions_only(self):
 
1912
        return True
 
1913
 
1865
1914
    supports_reference_locations = False
1866
1915
 
1867
1916
 
2376
2425
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2377
2426
        super(BzrBranch8, self).__init__(*args, **kwargs)
2378
2427
        self._last_revision_info_cache = None
2379
 
        self._partial_revision_history_cache = []
2380
2428
        self._reference_info = None
2381
2429
 
2382
2430
    def _clear_cached_state(self):
2383
2431
        super(BzrBranch8, self)._clear_cached_state()
2384
2432
        self._last_revision_info_cache = None
2385
 
        self._partial_revision_history_cache = []
2386
2433
        self._reference_info = None
2387
2434
 
2388
2435
    def _last_revision_info(self):
2444
2491
        self._extend_partial_history(stop_index=last_revno-1)
2445
2492
        return list(reversed(self._partial_revision_history_cache))
2446
2493
 
2447
 
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
2448
 
        """Extend the partial history to include a given index
2449
 
 
2450
 
        If a stop_index is supplied, stop when that index has been reached.
2451
 
        If a stop_revision is supplied, stop when that revision is
2452
 
        encountered.  Otherwise, stop when the beginning of history is
2453
 
        reached.
2454
 
 
2455
 
        :param stop_index: The index which should be present.  When it is
2456
 
            present, history extension will stop.
2457
 
        :param revision_id: The revision id which should be present.  When
2458
 
            it is encountered, history extension will stop.
2459
 
        """
2460
 
        repo = self.repository
2461
 
        if len(self._partial_revision_history_cache) == 0:
2462
 
            iterator = repo.iter_reverse_revision_history(self.last_revision())
2463
 
        else:
2464
 
            start_revision = self._partial_revision_history_cache[-1]
2465
 
            iterator = repo.iter_reverse_revision_history(start_revision)
2466
 
            #skip the last revision in the list
2467
 
            next_revision = iterator.next()
2468
 
        for revision_id in iterator:
2469
 
            self._partial_revision_history_cache.append(revision_id)
2470
 
            if (stop_index is not None and
2471
 
                len(self._partial_revision_history_cache) > stop_index):
2472
 
                break
2473
 
            if revision_id == stop_revision:
2474
 
                break
2475
 
 
2476
2494
    def _write_revision_history(self, history):
2477
2495
        """Factored out of set_revision_history.
2478
2496
 
2621
2639
            raise errors.NotStacked(self)
2622
2640
        return stacked_url
2623
2641
 
2624
 
    def set_append_revisions_only(self, enabled):
2625
 
        if enabled:
2626
 
            value = 'True'
2627
 
        else:
2628
 
            value = 'False'
2629
 
        self.get_config().set_user_option('append_revisions_only', value,
2630
 
            warn_masked=True)
2631
 
 
2632
2642
    def _get_append_revisions_only(self):
2633
2643
        value = self.get_config().get_user_option('append_revisions_only')
2634
2644
        return value == 'True'