~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-15 03:18:20 UTC
  • mfrom: (1910.2.6 format-bumps)
  • Revision ID: pqm@pqm.ubuntu.com-20060815031820-fde63c7ba995e484
Root entry always has a revision id

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import re
21
21
import time
22
22
from unittest import TestSuite
 
23
from warnings import warn
23
24
 
24
25
from bzrlib import bzrdir, check, delta, gpg, errors, xml5, ui, transactions, osutils
25
26
from bzrlib.decorators import needs_read_lock, needs_write_lock
26
27
from bzrlib.errors import InvalidRevisionId
27
28
from bzrlib.graph import Graph
28
29
from bzrlib.inter import InterObject
29
 
from bzrlib.inventory import Inventory
 
30
from bzrlib.inventory import Inventory, InventoryDirectory, ROOT_ID
30
31
from bzrlib.knit import KnitVersionedFile, KnitPlainFactory
31
32
from bzrlib.lockable_files import LockableFiles, TransportLock
32
33
from bzrlib.lockdir import LockDir
73
74
        assert inv.revision_id is None or inv.revision_id == revid, \
74
75
            "Mismatch between inventory revision" \
75
76
            " id and insertion revid (%r, %r)" % (inv.revision_id, revid)
 
77
        assert inv.root is not None
76
78
        inv_text = xml5.serializer_v5.write_inventory_to_string(inv)
77
79
        inv_sha1 = osutils.sha_string(inv_text)
78
80
        inv_vf = self.control_weaves.get_weave('inventory',
260
262
        :param revprops: Optional dictionary of revision properties.
261
263
        :param revision_id: Optional revision id.
262
264
        """
263
 
        return CommitBuilder(self, parents, config, timestamp, timezone,
264
 
                             committer, revprops, revision_id)
 
265
        return _CommitBuilder(self, parents, config, timestamp, timezone,
 
266
                              committer, revprops, revision_id)
265
267
 
266
268
    def unlock(self):
267
269
        self.control_files.unlock()
448
450
        :param revision_id: The expected revision id of the inventory.
449
451
        :param xml: A serialised inventory.
450
452
        """
451
 
        return xml5.serializer_v5.read_inventory_from_string(xml)
 
453
        result = xml5.serializer_v5.read_inventory_from_string(xml)
 
454
        result.root.revision = revision_id
 
455
        return result
452
456
 
453
457
    @needs_read_lock
454
458
    def get_inventory_xml(self, revision_id):
1969
1973
    This allows describing a tree to be committed without needing to 
1970
1974
    know the internals of the format of the repository.
1971
1975
    """
 
1976
    
 
1977
    record_root_entry = False
1972
1978
    def __init__(self, repository, parents, config, timestamp=None, 
1973
1979
                 timezone=None, committer=None, revprops=None, 
1974
1980
                 revision_id=None):
1991
1997
            assert isinstance(committer, basestring), type(committer)
1992
1998
            self._committer = committer
1993
1999
 
1994
 
        self.new_inventory = Inventory()
 
2000
        self.new_inventory = Inventory(None)
1995
2001
        self._new_revision_id = revision_id
1996
2002
        self.parents = parents
1997
2003
        self.repository = repository
2031
2037
 
2032
2038
    def finish_inventory(self):
2033
2039
        """Tell the builder that the inventory is finished."""
 
2040
        if self.new_inventory.root is None:
 
2041
            warn('Root entry should be supplied to record_entry_contents, as'
 
2042
                 ' of bzr 0.10.',
 
2043
                 DeprecationWarning, stacklevel=2)
 
2044
            self.new_inventory.add(InventoryDirectory(ROOT_ID, '', None))
2034
2045
        self.new_inventory.revision_id = self._new_revision_id
2035
2046
        self.inv_sha1 = self.repository.add_inventory(
2036
2047
            self._new_revision_id,
2060
2071
    def record_entry_contents(self, ie, parent_invs, path, tree):
2061
2072
        """Record the content of ie from tree into the commit if needed.
2062
2073
 
 
2074
        Side effect: sets ie.revision when unchanged
 
2075
 
2063
2076
        :param ie: An inventory entry present in the commit.
2064
2077
        :param parent_invs: The inventories of the parent revisions of the
2065
2078
            commit.
2074
2087
        # which may be the sole parent if it is untouched.
2075
2088
        if ie.revision is not None:
2076
2089
            return
 
2090
 
 
2091
        # In this revision format, root entries have no knit or weave
 
2092
        if ie is self.new_inventory.root:
 
2093
            if len(parent_invs):
 
2094
                ie.revision = parent_invs[0].root.revision
 
2095
            else:
 
2096
                ie.revision = None
 
2097
            return
2077
2098
        previous_entries = ie.find_previous_heads(
2078
2099
            parent_invs,
2079
2100
            self.repository.weave_store,
2139
2160
        versionedfile.clear_cache()
2140
2161
 
2141
2162
 
 
2163
class _CommitBuilder(CommitBuilder):
 
2164
    """Temporary class so old CommitBuilders are detected properly
 
2165
    
 
2166
    Note: CommitBuilder works whether or not root entry is recorded.
 
2167
    """
 
2168
 
 
2169
    record_root_entry = True
 
2170
 
 
2171
 
2142
2172
_unescape_map = {
2143
2173
    'apos':"'",
2144
2174
    'quot':'"',