/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: Andrew Bennetts
  • Date: 2008-03-12 20:13:07 UTC
  • mfrom: (3267 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080312201307-ngd5bynt2nvhnlb7
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
from cStringIO import StringIO
19
 
 
20
18
from bzrlib.lazy_import import lazy_import
21
19
lazy_import(globals(), """
22
 
from warnings import warn
23
 
 
24
 
import bzrlib
25
20
from bzrlib import (
26
21
        bzrdir,
27
22
        cache_utf8,
30
25
        errors,
31
26
        lockdir,
32
27
        lockable_files,
33
 
        osutils,
34
28
        revision as _mod_revision,
35
29
        transport,
36
 
        tree,
37
30
        tsort,
38
31
        ui,
39
32
        urlutils,
40
33
        )
41
 
from bzrlib.config import BranchConfig, TreeConfig
42
 
from bzrlib.lockable_files import LockableFiles, TransportLock
 
34
from bzrlib.config import BranchConfig
43
35
from bzrlib.tag import (
44
36
    BasicTags,
45
37
    DisabledTags,
47
39
""")
48
40
 
49
41
from bzrlib.decorators import needs_read_lock, needs_write_lock
50
 
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
51
 
                           HistoryMissing, InvalidRevisionId,
52
 
                           InvalidRevisionNumber, LockError, NoSuchFile,
53
 
                           NoSuchRevision, NotVersionedError,
54
 
                           NotBranchError, UninitializableFormat,
55
 
                           UnlistableStore, UnlistableBranch,
56
 
                           )
57
42
from bzrlib.hooks import Hooks
58
 
from bzrlib.symbol_versioning import (deprecated_function,
59
 
                                      deprecated_method,
60
 
                                      DEPRECATED_PARAMETER,
61
 
                                      deprecated_passed,
62
 
                                      zero_eight, zero_nine, zero_sixteen,
63
 
                                      zero_ninetyone,
 
43
from bzrlib.symbol_versioning import (deprecated_method,
 
44
                                      zero_sixteen,
64
45
                                      )
65
46
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
66
47
 
279
260
            if last_revision is None:
280
261
                pb.update('get source history')
281
262
                last_revision = from_branch.last_revision()
282
 
                if last_revision is None:
283
 
                    last_revision = _mod_revision.NULL_REVISION
 
263
                last_revision = _mod_revision.ensure_null(last_revision)
284
264
            return self.repository.fetch(from_branch.repository,
285
265
                                         revision_id=last_revision,
286
266
                                         pb=nested_pb)
338
318
        assert isinstance(revno, int)
339
319
        rh = self.revision_history()
340
320
        if not (1 <= revno <= len(rh)):
341
 
            raise InvalidRevisionNumber(revno)
 
321
            raise errors.InvalidRevisionNumber(revno)
342
322
        return self.repository.get_revision_delta(rh[revno-1])
343
323
 
344
324
    @deprecated_method(zero_sixteen)
464
444
        common_index = min(self_len, other_len) -1
465
445
        if common_index >= 0 and \
466
446
            self_history[common_index] != other_history[common_index]:
467
 
            raise DivergedBranches(self, other)
 
447
            raise errors.DivergedBranches(self, other)
468
448
 
469
449
        if stop_revision is None:
470
450
            stop_revision = other_len
643
623
        Zero (the NULL revision) is considered invalid
644
624
        """
645
625
        if revno < 1 or revno > self.revno():
646
 
            raise InvalidRevisionNumber(revno)
 
626
            raise errors.InvalidRevisionNumber(revno)
647
627
 
648
628
    @needs_read_lock
649
629
    def clone(self, to_bzrdir, revision_id=None):
753
733
        return format
754
734
 
755
735
    def create_checkout(self, to_location, revision_id=None,
756
 
                        lightweight=False, accelerator_tree=None):
 
736
                        lightweight=False, accelerator_tree=None,
 
737
                        hardlink=False):
757
738
        """Create a checkout of a branch.
758
739
        
759
740
        :param to_location: The url to produce the checkout at
764
745
            contents more quickly than the revision tree, i.e. a workingtree.
765
746
            The revision tree will be used for cases where accelerator_tree's
766
747
            content is different.
 
748
        :param hardlink: If true, hard-link files from accelerator_tree,
 
749
            where possible.
767
750
        :return: The tree of the created checkout
768
751
        """
769
752
        t = transport.get_transport(to_location)
784
767
            from_branch=None
785
768
        tree = checkout.create_workingtree(revision_id,
786
769
                                           from_branch=from_branch,
787
 
                                           accelerator_tree=accelerator_tree)
 
770
                                           accelerator_tree=accelerator_tree,
 
771
                                           hardlink=hardlink)
788
772
        basis_tree = tree.basis_tree()
789
773
        basis_tree.lock_read()
790
774
        try:
847
831
            transport = a_bzrdir.get_branch_transport(None)
848
832
            format_string = transport.get("format").read()
849
833
            return klass._formats[format_string]
850
 
        except NoSuchFile:
851
 
            raise NotBranchError(path=transport.base)
 
834
        except errors.NoSuchFile:
 
835
            raise errors.NotBranchError(path=transport.base)
852
836
        except KeyError:
853
 
            raise errors.UnknownFormatError(format=format_string)
 
837
            raise errors.UnknownFormatError(format=format_string, kind='branch')
854
838
 
855
839
    @classmethod
856
840
    def get_default_format(klass):
1136
1120
                              _control_files=control_files,
1137
1121
                              a_bzrdir=a_bzrdir,
1138
1122
                              _repository=a_bzrdir.find_repository())
1139
 
        except NoSuchFile:
1140
 
            raise NotBranchError(path=transport.base)
 
1123
        except errors.NoSuchFile:
 
1124
            raise errors.NotBranchError(path=transport.base)
1141
1125
 
1142
1126
 
1143
1127
class BzrBranchFormat6(BzrBranchFormat5):
1409
1393
        configured to check constraints on history, in which case this may not
1410
1394
        be permitted.
1411
1395
        """
 
1396
        revision_id = _mod_revision.ensure_null(revision_id)
1412
1397
        history = self._lefthand_history(revision_id)
1413
1398
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1414
1399
        self.set_revision_history(history)
1425
1410
        if 'evil' in debug.debug_flags:
1426
1411
            mutter_callsite(4, "_lefthand_history scales with history.")
1427
1412
        # stop_revision must be a descendant of last_revision
1428
 
        stop_graph = self.repository.get_revision_graph(revision_id)
1429
 
        if (last_rev is not None and last_rev != _mod_revision.NULL_REVISION
1430
 
            and last_rev not in stop_graph):
1431
 
            # our previous tip is not merged into stop_revision
1432
 
            raise errors.DivergedBranches(self, other_branch)
 
1413
        graph = self.repository.get_graph()
 
1414
        if last_rev is not None:
 
1415
            if not graph.is_ancestor(last_rev, revision_id):
 
1416
                # our previous tip is not merged into stop_revision
 
1417
                raise errors.DivergedBranches(self, other_branch)
1433
1418
        # make a new revision history from the graph
 
1419
        parents_map = graph.get_parent_map([revision_id])
 
1420
        if revision_id not in parents_map:
 
1421
            raise errors.NoSuchRevision(self, revision_id)
1434
1422
        current_rev_id = revision_id
1435
1423
        new_history = []
1436
 
        while current_rev_id not in (None, _mod_revision.NULL_REVISION):
 
1424
        # Do not include ghosts or graph origin in revision_history
 
1425
        while (current_rev_id in parents_map and
 
1426
               len(parents_map[current_rev_id]) > 0):
1437
1427
            new_history.append(current_rev_id)
1438
 
            current_rev_id_parents = stop_graph[current_rev_id]
1439
 
            try:
1440
 
                current_rev_id = current_rev_id_parents[0]
1441
 
            except IndexError:
1442
 
                current_rev_id = None
 
1428
            current_rev_id = parents_map[current_rev_id][0]
 
1429
            parents_map = graph.get_parent_map([current_rev_id])
1443
1430
        new_history.reverse()
1444
1431
        return new_history
1445
1432
 
1544
1531
        for l in _locs:
1545
1532
            try:
1546
1533
                return self.control_files.get(l).read().strip('\n')
1547
 
            except NoSuchFile:
 
1534
            except errors.NoSuchFile:
1548
1535
                pass
1549
1536
        return None
1550
1537
 
1628
1615
        result.old_revno, result.old_revid = target.last_revision_info()
1629
1616
        try:
1630
1617
            target.update_revisions(self, stop_revision)
1631
 
        except DivergedBranches:
 
1618
        except errors.DivergedBranches:
1632
1619
            if not overwrite:
1633
1620
                raise
1634
1621
        if overwrite:
1767
1754
        else:
1768
1755
            try:
1769
1756
                self.control_files._transport.delete('bound')
1770
 
            except NoSuchFile:
 
1757
            except errors.NoSuchFile:
1771
1758
                return False
1772
1759
            return True
1773
1760
 
1839
1826
        Intended to be called by set_last_revision_info and
1840
1827
        _write_revision_history.
1841
1828
        """
1842
 
        if revision_id is None:
1843
 
            revision_id = 'null:'
 
1829
        assert revision_id is not None, "Use NULL_REVISION, not None"
1844
1830
        out_string = '%d %s\n' % (revno, revision_id)
1845
1831
        self.control_files.put_bytes('last-revision', out_string)
1846
1832
 
1847
1833
    @needs_write_lock
1848
1834
    def set_last_revision_info(self, revno, revision_id):
 
1835
        revision_id = _mod_revision.ensure_null(revision_id)
1849
1836
        if self._get_append_revisions_only():
1850
1837
            self._check_history_violation(revision_id)
1851
1838
        self._write_last_revision_info(revno, revision_id)
1974
1961
    def _make_tags(self):
1975
1962
        return BasicTags(self)
1976
1963
 
 
1964
    @needs_write_lock
 
1965
    def generate_revision_history(self, revision_id, last_rev=None,
 
1966
                                  other_branch=None):
 
1967
        """See BzrBranch5.generate_revision_history"""
 
1968
        history = self._lefthand_history(revision_id, last_rev, other_branch)
 
1969
        revno = len(history)
 
1970
        self.set_last_revision_info(revno, revision_id)
 
1971
 
1977
1972
 
1978
1973
######################################################################
1979
1974
# results of operations
2084
2079
        new_branch.control_files._transport.delete('revision-history')
2085
2080
        try:
2086
2081
            branch.set_parent(None)
2087
 
        except NoSuchFile:
 
2082
        except errors.NoSuchFile:
2088
2083
            pass
2089
2084
        branch.set_bound_location(None)