~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2008-03-03 16:52:41 UTC
  • mfrom: (3144.3.11 fix-conflict-handling)
  • mto: This revision was merged to the branch mainline in revision 3250.
  • Revision ID: aaron@aaronbentley.com-20080303165241-0k2c7ggs6kr9q6hf
Merge with fix-conflict-handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
                                      zero_eight, zero_nine, zero_sixteen,
63
63
                                      zero_ninetyone,
64
64
                                      )
65
 
from bzrlib.trace import mutter, mutter_callsite, note
 
65
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
66
66
 
67
67
 
68
68
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
436
436
        raise errors.UpgradeRequired(self.base)
437
437
 
438
438
    def last_revision(self):
439
 
        """Return last revision id, or None"""
440
 
        ph = self.revision_history()
441
 
        if ph:
442
 
            return ph[-1]
443
 
        else:
444
 
            return _mod_revision.NULL_REVISION
 
439
        """Return last revision id, or NULL_REVISION."""
 
440
        return self.last_revision_info()[1]
445
441
 
446
442
    def last_revision_info(self):
447
443
        """Return information about the last revision.
757
753
        return format
758
754
 
759
755
    def create_checkout(self, to_location, revision_id=None,
760
 
                        lightweight=False, accelerator_tree=None):
 
756
                        lightweight=False, accelerator_tree=None,
 
757
                        hardlink=False):
761
758
        """Create a checkout of a branch.
762
759
        
763
760
        :param to_location: The url to produce the checkout at
768
765
            contents more quickly than the revision tree, i.e. a workingtree.
769
766
            The revision tree will be used for cases where accelerator_tree's
770
767
            content is different.
 
768
        :param hardlink: If true, hard-link files from accelerator_tree,
 
769
            where possible.
771
770
        :return: The tree of the created checkout
772
771
        """
773
772
        t = transport.get_transport(to_location)
788
787
            from_branch=None
789
788
        tree = checkout.create_workingtree(revision_id,
790
789
                                           from_branch=from_branch,
791
 
                                           accelerator_tree=accelerator_tree)
 
790
                                           accelerator_tree=accelerator_tree,
 
791
                                           hardlink=hardlink)
792
792
        basis_tree = tree.basis_tree()
793
793
        basis_tree.lock_read()
794
794
        try:
1824
1824
        return None
1825
1825
 
1826
1826
 
1827
 
class BzrBranchExperimental(BzrBranch5):
1828
 
    """Bzr experimental branch format
1829
 
 
1830
 
    This format has:
1831
 
     - a revision-history file.
1832
 
     - a format string
1833
 
     - a lock dir guarding the branch itself
1834
 
     - all of this stored in a branch/ subdirectory
1835
 
     - works with shared repositories.
1836
 
     - a tag dictionary in the branch
1837
 
 
1838
 
    This format is new in bzr 0.15, but shouldn't be used for real data, 
1839
 
    only for testing.
1840
 
 
1841
 
    This class acts as it's own BranchFormat.
1842
 
    """
1843
 
 
1844
 
    _matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1845
 
 
1846
 
    @classmethod
1847
 
    def get_format_string(cls):
1848
 
        """See BranchFormat.get_format_string()."""
1849
 
        return "Bazaar-NG branch format experimental\n"
1850
 
 
1851
 
    @classmethod
1852
 
    def get_format_description(cls):
1853
 
        """See BranchFormat.get_format_description()."""
1854
 
        return "Experimental branch format"
1855
 
 
1856
 
    @classmethod
1857
 
    def get_reference(cls, a_bzrdir):
1858
 
        """Get the target reference of the branch in a_bzrdir.
1859
 
 
1860
 
        format probing must have been completed before calling
1861
 
        this method - it is assumed that the format of the branch
1862
 
        in a_bzrdir is correct.
1863
 
 
1864
 
        :param a_bzrdir: The bzrdir to get the branch data from.
1865
 
        :return: None if the branch is not a reference branch.
1866
 
        """
1867
 
        return None
1868
 
 
1869
 
    @classmethod
1870
 
    def set_reference(self, a_bzrdir, to_branch):
1871
 
        """Set the target reference of the branch in a_bzrdir.
1872
 
 
1873
 
        format probing must have been completed before calling
1874
 
        this method - it is assumed that the format of the branch
1875
 
        in a_bzrdir is correct.
1876
 
 
1877
 
        :param a_bzrdir: The bzrdir to set the branch reference for.
1878
 
        :param to_branch: branch that the checkout is to reference
1879
 
        """
1880
 
        raise NotImplementedError(self.set_reference)
1881
 
 
1882
 
    @classmethod
1883
 
    def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
1884
 
            lock_class):
1885
 
        branch_transport = a_bzrdir.get_branch_transport(cls)
1886
 
        control_files = lockable_files.LockableFiles(branch_transport,
1887
 
            lock_filename, lock_class)
1888
 
        control_files.create_lock()
1889
 
        control_files.lock_write()
1890
 
        try:
1891
 
            for filename, content in utf8_files:
1892
 
                control_files.put_utf8(filename, content)
1893
 
        finally:
1894
 
            control_files.unlock()
1895
 
        
1896
 
    @classmethod
1897
 
    def initialize(cls, a_bzrdir):
1898
 
        """Create a branch of this format in a_bzrdir."""
1899
 
        utf8_files = [('format', cls.get_format_string()),
1900
 
                      ('revision-history', ''),
1901
 
                      ('branch-name', ''),
1902
 
                      ('tags', ''),
1903
 
                      ]
1904
 
        cls._initialize_control_files(a_bzrdir, utf8_files,
1905
 
            'lock', lockdir.LockDir)
1906
 
        return cls.open(a_bzrdir, _found=True)
1907
 
 
1908
 
    @classmethod
1909
 
    def open(cls, a_bzrdir, _found=False):
1910
 
        """Return the branch object for a_bzrdir
1911
 
 
1912
 
        _found is a private parameter, do not use it. It is used to indicate
1913
 
               if format probing has already be done.
1914
 
        """
1915
 
        if not _found:
1916
 
            format = BranchFormat.find_format(a_bzrdir)
1917
 
            assert format.__class__ == cls
1918
 
        transport = a_bzrdir.get_branch_transport(None)
1919
 
        control_files = lockable_files.LockableFiles(transport, 'lock',
1920
 
                                                     lockdir.LockDir)
1921
 
        return cls(_format=cls,
1922
 
            _control_files=control_files,
1923
 
            a_bzrdir=a_bzrdir,
1924
 
            _repository=a_bzrdir.find_repository())
1925
 
 
1926
 
    @classmethod
1927
 
    def is_supported(cls):
1928
 
        return True
1929
 
 
1930
 
    def _make_tags(self):
1931
 
        return BasicTags(self)
1932
 
 
1933
 
    @classmethod
1934
 
    def supports_tags(cls):
1935
 
        return True
1936
 
 
1937
 
 
1938
 
BranchFormat.register_format(BzrBranchExperimental)
1939
 
 
1940
 
 
1941
1827
class BzrBranch6(BzrBranch5):
1942
1828
 
1943
1829
    @needs_read_lock
1948
1834
        revno = int(revno)
1949
1835
        return revno, revision_id
1950
1836
 
1951
 
    def last_revision(self):
1952
 
        """Return last revision id, or None"""
1953
 
        revision_id = self.last_revision_info()[1]
1954
 
        return revision_id
1955
 
 
1956
1837
    def _write_last_revision_info(self, revno, revision_id):
1957
1838
        """Simply write out the revision id, with no checks.
1958
1839
 
2129
2010
        return self.new_revno - self.old_revno
2130
2011
 
2131
2012
    def report(self, to_file):
2132
 
        if self.old_revid == self.new_revid:
2133
 
            to_file.write('No revisions to pull.\n')
2134
 
        else:
2135
 
            to_file.write('Now on revision %d.\n' % self.new_revno)
 
2013
        if not is_quiet():
 
2014
            if self.old_revid == self.new_revid:
 
2015
                to_file.write('No revisions to pull.\n')
 
2016
            else:
 
2017
                to_file.write('Now on revision %d.\n' % self.new_revno)
2136
2018
        self._show_tag_conficts(to_file)
2137
2019
 
2138
2020