~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/versioned/__init__.py

MergeĀ inĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
1
# Copyright (C) 2005 Canonical Ltd
4
2
 
5
3
# This program is free software; you can redistribute it and/or modify
46
44
        self._precious = precious
47
45
        self._versionedfile_class = versionedfile_class
48
46
 
 
47
    def _clear_cache_id(self, file_id, transaction):
 
48
        """WARNING may lead to inconsistent object references for file_id.
 
49
 
 
50
        Remove file_id from the transaction map. 
 
51
 
 
52
        NOT in the transaction api because theres no reliable way to clear
 
53
        callers. So its here for very specialised use rather than having an
 
54
        'api' that isn't.
 
55
        """
 
56
        weave = transaction.map.find_weave(file_id)
 
57
        if weave:
 
58
            mutter("old data in transaction in %s for %s", self, file_id)
 
59
            # FIXME abstraction violation.
 
60
            transaction.map.remove_object('weave-' + file-id)
 
61
 
49
62
    def filename(self, file_id):
50
63
        """Return the path relative to the transport root."""
51
64
        if self._prefixed:
72
85
                return False
73
86
        return True
74
87
 
 
88
    def get_empty(self, file_id, transaction):
 
89
        """Get an empty weave, which implies deleting the existing one first."""
 
90
        if self.has_id(file_id):
 
91
            self.delete(file_id, transaction)
 
92
        return self.get_weave_or_empty(file_id, transaction)
 
93
 
 
94
    def delete(self, file_id, transaction):
 
95
        """Remove file_id from the store."""
 
96
        suffixes = self._versionedfile_class.get_suffixes()
 
97
        filename = self.filename(file_id)
 
98
        for suffix in suffixes:
 
99
            self._transport.delete(filename + suffix)
 
100
        self._clear_cache_id(file_id, transaction)
 
101
 
75
102
    def get_weave(self, file_id, transaction):
76
103
        weave = transaction.map.find_weave(file_id)
77
104
        if weave:
99
126
 
100
127
    def _make_new_versionedfile(self, file_id):
101
128
        try:
102
 
            weave = self._versionedfile_class(self.filename(file_id), self._transport, self._file_mode)
 
129
            weave = self._versionedfile_class(self.filename(file_id), self._transport, self._file_mode, create=True)
103
130
        except NoSuchFile:
104
131
            if not self._prefixed:
105
132
                # unexpected error - NoSuchFile is raised on a missing dir only and that
106
133
                # only occurs when we are prefixed.
107
134
                raise
108
135
            self._transport.mkdir(hash_prefix(file_id), mode=self._dir_mode)
109
 
            weave = self._versionedfile_class(self.filename(file_id), self._transport, self._file_mode)
 
136
            weave = self._versionedfile_class(self.filename(file_id), self._transport, self._file_mode, create=True)
110
137
        return weave
111
138
 
112
139
    def get_weave_or_empty(self, file_id, transaction):
153
180
        """
154
181
        vfile = self.get_weave_or_empty(file_id, transaction)
155
182
        vfile.clone_text(new_rev_id, old_rev_id, parents)
156
 
     
 
183
 
 
184
    def copy(self, source, result_id, transaction):
 
185
        """Copy the source versioned file to result_id in this store."""
 
186
        self._clear_cache_id(result_id, transaction)
 
187
        source.copy_to(self.filename(result_id), self._transport)
 
188
 
157
189
    def copy_all_ids(self, store_from, pb=None, from_transaction=None):
158
190
        """Copy all the file ids from store_from into self."""
159
191
        if from_transaction is None: