~lifeless/ubuntu/lucid/bzr/2.1.2-sru

« back to all changes in this revision

Viewing changes to bzrlib/revisiontree.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-06-27 15:23:34 UTC
  • mfrom: (1.3.1 upstream) (3.1.78 karmic)
  • Revision ID: james.westby@ubuntu.com-20090627152334-u3smexjpaolh96qd
* New upstream release.
* Bump standards version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""RevisionTree - a Tree implementation backed by repository data for a revision."""
18
18
 
23
23
    osutils,
24
24
    revision,
25
25
    symbol_versioning,
 
26
    tree,
26
27
    )
27
 
from bzrlib.tree import Tree
28
 
 
29
 
 
30
 
class RevisionTree(Tree):
 
28
 
 
29
 
 
30
class RevisionTree(tree.Tree):
31
31
    """Tree viewing a previous revision.
32
32
 
33
33
    File text can be retrieved from the text store.
45
45
        self._rules_searcher = None
46
46
 
47
47
    def supports_tree_reference(self):
48
 
        return True
 
48
        return getattr(self._repository._format, "supports_tree_reference",
 
49
            False)
49
50
 
50
51
    def get_parent_ids(self):
51
52
        """See Tree.get_parent_ids.
64
65
        return self._revision_id
65
66
 
66
67
    def get_file_text(self, file_id, path=None):
67
 
        return list(self.iter_files_bytes([(file_id, None)]))[0][1]
 
68
        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
 
69
        return ''.join(content)
68
70
 
69
71
    def get_file(self, file_id, path=None):
70
72
        return StringIO(self.get_file_text(file_id))
124
126
 
125
127
    def get_symlink_target(self, file_id):
126
128
        ie = self._inventory[file_id]
127
 
        return ie.symlink_target;
 
129
        # Inventories store symlink targets in unicode
 
130
        return ie.symlink_target
128
131
 
129
132
    def get_reference_revision(self, file_id, path=None):
130
133
        return self.inventory[file_id].reference_revision
207
210
            self._rules_searcher = super(RevisionTree,
208
211
                self)._get_rules_searcher(default_searcher)
209
212
        return self._rules_searcher
 
213
 
 
214
 
 
215
class InterCHKRevisionTree(tree.InterTree):
 
216
    """Fast path optimiser for RevisionTrees with CHK inventories."""
 
217
 
 
218
    @staticmethod
 
219
    def is_compatible(source, target):
 
220
        if (isinstance(source, RevisionTree)
 
221
            and isinstance(target, RevisionTree)):
 
222
            try:
 
223
                # Only CHK inventories have id_to_entry attribute
 
224
                source.inventory.id_to_entry
 
225
                target.inventory.id_to_entry
 
226
                return True
 
227
            except AttributeError:
 
228
                pass
 
229
        return False
 
230
 
 
231
    def iter_changes(self, include_unchanged=False,
 
232
                     specific_files=None, pb=None, extra_trees=[],
 
233
                     require_versioned=True, want_unversioned=False):
 
234
        lookup_trees = [self.source]
 
235
        if extra_trees:
 
236
             lookup_trees.extend(extra_trees)
 
237
        if specific_files == []:
 
238
            specific_file_ids = []
 
239
        else:
 
240
            specific_file_ids = self.target.paths2ids(specific_files,
 
241
                lookup_trees, require_versioned=require_versioned)
 
242
 
 
243
        # FIXME: It should be possible to delegate include_unchanged handling
 
244
        # to CHKInventory.iter_changes and do a better job there -- vila
 
245
        # 20090304
 
246
        if include_unchanged:
 
247
            changed_file_ids = []
 
248
        for result in self.target.inventory.iter_changes(self.source.inventory):
 
249
            if (specific_file_ids is not None
 
250
                and not result[0] in specific_file_ids):
 
251
                # CHKMap.iter_changes is clean and fast. Better filter out
 
252
                # the specific files *after* it did its job.
 
253
                continue
 
254
            yield result
 
255
            if include_unchanged:
 
256
                # Keep track of yielded results (cheaper than building the
 
257
                # whole inventory).
 
258
                changed_file_ids.append(result[0])
 
259
        if include_unchanged:
 
260
            # CHKMap avoid being O(tree), so we go to O(tree) only if
 
261
            # required to.
 
262
            # Now walk the whole inventory, excluding the already yielded
 
263
            # file ids
 
264
            changed_file_ids = set(changed_file_ids)
 
265
            for relpath, entry in self.target.inventory.iter_entries():
 
266
                if (specific_file_ids is not None
 
267
                    and not entry.file_id in specific_file_ids):
 
268
                    continue
 
269
                if not entry.file_id in changed_file_ids:
 
270
                    yield (entry.file_id,
 
271
                           (relpath, relpath), # Not renamed
 
272
                           False, # Not modified
 
273
                           (True, True), # Still  versioned
 
274
                           (entry.parent_id, entry.parent_id),
 
275
                           (entry.name, entry.name),
 
276
                           (entry.kind, entry.kind),
 
277
                           (entry.executable, entry.executable))
 
278
 
 
279
 
 
280
tree.InterTree.register_optimiser(InterCHKRevisionTree)