~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jonathan Lange
  • Date: 2009-06-26 08:46:52 UTC
  • mto: (4484.1.1 bring-1.16.1-back)
  • mto: This revision was merged to the branch mainline in revision 4485.
  • Revision ID: jml@canonical.com-20090626084652-x7wn8yimd3fj0j0y
Tweak NEWS slightly based on mbp's feedback.

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 = []
95
94
        self._last_revision_info_cache = None
96
95
        self._merge_sorted_revisions_cache = None
97
96
        self._open_hook()
105
104
    def _activate_fallback_location(self, url):
106
105
        """Activate the branch/repository from url as a fallback repository."""
107
106
        repo = self._get_fallback_repository(url)
108
 
        if repo.has_same_location(self.repository):
109
 
            raise errors.UnstackableLocationError(self.base, url)
110
107
        self.repository.add_fallback_repository(repo)
111
108
 
112
109
    def break_lock(self):
128
125
            raise errors.UnstackableRepositoryFormat(self.repository._format,
129
126
                self.repository.base)
130
127
 
131
 
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
132
 
        """Extend the partial history to include a given index
133
 
 
134
 
        If a stop_index is supplied, stop when that index has been reached.
135
 
        If a stop_revision is supplied, stop when that revision is
136
 
        encountered.  Otherwise, stop when the beginning of history is
137
 
        reached.
138
 
 
139
 
        :param stop_index: The index which should be present.  When it is
140
 
            present, history extension will stop.
141
 
        :param stop_revision: The revision id which should be present.  When
142
 
            it is encountered, history extension will stop.
143
 
        """
144
 
        if len(self._partial_revision_history_cache) == 0:
145
 
            self._partial_revision_history_cache = [self.last_revision()]
146
 
        repository._iter_for_revno(
147
 
            self.repository, self._partial_revision_history_cache,
148
 
            stop_index=stop_index, stop_revision=stop_revision)
149
 
        if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
150
 
            self._partial_revision_history_cache.pop()
151
 
 
152
128
    @staticmethod
153
129
    def open(base, _unsupported=False, possible_transports=None):
154
130
        """Open the branch rooted at base.
522
498
        """
523
499
        raise errors.UpgradeRequired(self.base)
524
500
 
525
 
    def set_append_revisions_only(self, enabled):
526
 
        if not self._format.supports_set_append_revisions_only():
527
 
            raise errors.UpgradeRequired(self.base)
528
 
        if enabled:
529
 
            value = 'True'
530
 
        else:
531
 
            value = 'False'
532
 
        self.get_config().set_user_option('append_revisions_only', value,
533
 
            warn_masked=True)
534
 
 
535
501
    def set_reference_info(self, file_id, tree_path, branch_location):
536
502
        """Set the branch location to use for a tree reference."""
537
503
        raise errors.UnsupportedOperation(self.set_reference_info, self)
732
698
        self._revision_id_to_revno_cache = None
733
699
        self._last_revision_info_cache = None
734
700
        self._merge_sorted_revisions_cache = None
735
 
        self._partial_revision_history_cache = []
736
 
        self._partial_revision_id_to_revno_cache = {}
737
701
 
738
702
    def _gen_revision_history(self):
739
703
        """Return sequence of revision hashes on to this branch.
778
742
        """Older format branches cannot bind or unbind."""
779
743
        raise errors.UpgradeRequired(self.base)
780
744
 
 
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
 
781
749
    def last_revision(self):
782
750
        """Return last revision id, or NULL_REVISION."""
783
751
        return self.last_revision_info()[1]
863
831
        except ValueError:
864
832
            raise errors.NoSuchRevision(self, revision_id)
865
833
 
866
 
    @needs_read_lock
867
834
    def get_rev_id(self, revno, history=None):
868
835
        """Find the revision id of the specified revno."""
869
836
        if revno == 0:
870
837
            return _mod_revision.NULL_REVISION
871
 
        last_revno, last_revid = self.last_revision_info()
872
 
        if revno == last_revno:
873
 
            return last_revid
874
 
        if revno <= 0 or revno > last_revno:
 
838
        if history is None:
 
839
            history = self.revision_history()
 
840
        if revno <= 0 or revno > len(history):
875
841
            raise errors.NoSuchRevision(self, revno)
876
 
        distance_from_last = last_revno - revno
877
 
        if len(self._partial_revision_history_cache) <= distance_from_last:
878
 
            self._extend_partial_history(distance_from_last)
879
 
        return self._partial_revision_history_cache[distance_from_last]
 
842
        return history[revno - 1]
880
843
 
881
844
    @needs_write_lock
882
845
    def pull(self, source, overwrite=False, stop_revision=None,
1386
1349
    _formats = {}
1387
1350
    """The known formats."""
1388
1351
 
1389
 
    can_set_append_revisions_only = True
1390
 
 
1391
1352
    def __eq__(self, other):
1392
1353
        return self.__class__ is other.__class__
1393
1354
 
1546
1507
    def set_default_format(klass, format):
1547
1508
        klass._default_format = format
1548
1509
 
1549
 
    def supports_set_append_revisions_only(self):
1550
 
        """True if this format supports set_append_revisions_only."""
1551
 
        return False
1552
 
 
1553
1510
    def supports_stacking(self):
1554
1511
        """True if this format records a stacked-on branch."""
1555
1512
        return False
1837
1794
        """See bzrlib.branch.BranchFormat.make_tags()."""
1838
1795
        return BasicTags(branch)
1839
1796
 
1840
 
    def supports_set_append_revisions_only(self):
1841
 
        return True
1842
1797
 
1843
1798
 
1844
1799
class BzrBranchFormat8(BranchFormatMetadir):
1873
1828
        """See bzrlib.branch.BranchFormat.make_tags()."""
1874
1829
        return BasicTags(branch)
1875
1830
 
1876
 
    def supports_set_append_revisions_only(self):
1877
 
        return True
1878
 
 
1879
1831
    def supports_stacking(self):
1880
1832
        return True
1881
1833
 
1910
1862
        """See BranchFormat.get_format_description()."""
1911
1863
        return "Branch format 7"
1912
1864
 
1913
 
    def supports_set_append_revisions_only(self):
1914
 
        return True
1915
 
 
1916
1865
    supports_reference_locations = False
1917
1866
 
1918
1867
 
2427
2376
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2428
2377
        super(BzrBranch8, self).__init__(*args, **kwargs)
2429
2378
        self._last_revision_info_cache = None
 
2379
        self._partial_revision_history_cache = []
2430
2380
        self._reference_info = None
2431
2381
 
2432
2382
    def _clear_cached_state(self):
2433
2383
        super(BzrBranch8, self)._clear_cached_state()
2434
2384
        self._last_revision_info_cache = None
 
2385
        self._partial_revision_history_cache = []
2435
2386
        self._reference_info = None
2436
2387
 
2437
2388
    def _last_revision_info(self):
2493
2444
        self._extend_partial_history(stop_index=last_revno-1)
2494
2445
        return list(reversed(self._partial_revision_history_cache))
2495
2446
 
 
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
 
2496
2476
    def _write_revision_history(self, history):
2497
2477
        """Factored out of set_revision_history.
2498
2478
 
2641
2621
            raise errors.NotStacked(self)
2642
2622
        return stacked_url
2643
2623
 
 
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
 
2644
2632
    def _get_append_revisions_only(self):
2645
2633
        value = self.get_config().get_user_option('append_revisions_only')
2646
2634
        return value == 'True'