~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisiontree.py

  • Committer: Vincent Ladeuil
  • Date: 2010-04-23 08:51:52 UTC
  • mfrom: (5131.2.6 support_OO_flag)
  • mto: This revision was merged to the branch mainline in revision 5179.
  • Revision ID: v.ladeuil+lp@free.fr-20100423085152-uoewc1vnkwqhw0pj
Manually assign docstrings to command objects, so that they work with python -OO

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.
86
87
                      default_revision=revision.CURRENT_REVISION):
87
88
        """See Tree.annotate_iter"""
88
89
        text_key = (file_id, self.inventory[file_id].revision)
89
 
        annotations = self._repository.texts.annotate(text_key)
 
90
        annotator = self._repository.texts.get_annotator()
 
91
        annotations = annotator.annotate_flat(text_key)
90
92
        return [(key[-1], line) for key, line in annotations]
91
93
 
92
94
    def get_file_size(self, file_id):
101
103
 
102
104
    def get_file_mtime(self, file_id, path=None):
103
105
        ie = self._inventory[file_id]
104
 
        revision = self._repository.get_revision(ie.revision)
 
106
        try:
 
107
            revision = self._repository.get_revision(ie.revision)
 
108
        except errors.NoSuchRevision:
 
109
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
105
110
        return revision.timestamp
106
111
 
107
112
    def is_executable(self, file_id, path=None):
113
118
    def has_filename(self, filename):
114
119
        return bool(self.inventory.path2id(filename))
115
120
 
116
 
    def list_files(self, include_root=False):
 
121
    def list_files(self, include_root=False, from_dir=None, recursive=True):
117
122
        # The only files returned by this are those from the version
118
 
        entries = self.inventory.iter_entries()
119
 
        # skip the root for compatability with the current apis.
120
 
        if self.inventory.root is not None and not include_root:
 
123
        inv = self.inventory
 
124
        if from_dir is None:
 
125
            from_dir_id = None
 
126
        else:
 
127
            from_dir_id = inv.path2id(from_dir)
 
128
            if from_dir_id is None:
 
129
                # Directory not versioned
 
130
                return
 
131
        entries = inv.iter_entries(from_dir=from_dir_id, recursive=recursive)
 
132
        if inv.root is not None and not include_root and from_dir is None:
121
133
            # skip the root for compatability with the current apis.
122
134
            entries.next()
123
135
        for path, entry in entries:
125
137
 
126
138
    def get_symlink_target(self, file_id):
127
139
        ie = self._inventory[file_id]
128
 
        return ie.symlink_target;
 
140
        # Inventories store symlink targets in unicode
 
141
        return ie.symlink_target
129
142
 
130
143
    def get_reference_revision(self, file_id, path=None):
131
144
        return self.inventory[file_id].reference_revision
232
245
        lookup_trees = [self.source]
233
246
        if extra_trees:
234
247
             lookup_trees.extend(extra_trees)
 
248
        # The ids of items we need to examine to insure delta consistency.
 
249
        precise_file_ids = set()
 
250
        discarded_changes = {}
235
251
        if specific_files == []:
236
252
            specific_file_ids = []
237
253
        else:
238
254
            specific_file_ids = self.target.paths2ids(specific_files,
239
255
                lookup_trees, require_versioned=require_versioned)
240
 
 
241
256
        # FIXME: It should be possible to delegate include_unchanged handling
242
257
        # to CHKInventory.iter_changes and do a better job there -- vila
243
258
        # 20090304
244
 
        if include_unchanged:
245
 
            changed_file_ids = []
 
259
        changed_file_ids = set()
246
260
        for result in self.target.inventory.iter_changes(self.source.inventory):
247
 
            if (specific_file_ids is not None
248
 
                and not result[0] in specific_file_ids):
249
 
                # CHKMap.iter_changes is clean and fast. Better filter out
250
 
                # the specific files *after* it did its job.
251
 
                continue
 
261
            if specific_file_ids is not None:
 
262
                file_id = result[0]
 
263
                if file_id not in specific_file_ids:
 
264
                    # A change from the whole tree that we don't want to show yet.
 
265
                    # We may find that we need to show it for delta consistency, so
 
266
                    # stash it.
 
267
                    discarded_changes[result[0]] = result
 
268
                    continue
 
269
                new_parent_id = result[4][1]
 
270
                precise_file_ids.add(new_parent_id)
252
271
            yield result
253
 
            if include_unchanged:
254
 
                # Keep track of yielded results (cheaper than building the
255
 
                # whole inventory).
256
 
                changed_file_ids.append(result[0])
 
272
            changed_file_ids.add(result[0])
 
273
        if specific_file_ids is not None:
 
274
            for result in self._handle_precise_ids(precise_file_ids,
 
275
                changed_file_ids, discarded_changes=discarded_changes):
 
276
                yield result
257
277
        if include_unchanged:
258
278
            # CHKMap avoid being O(tree), so we go to O(tree) only if
259
279
            # required to.
260
280
            # Now walk the whole inventory, excluding the already yielded
261
281
            # file ids
262
 
            def not_a_change(file_id, relpath, parent, kind, executable):
263
 
                return (file_id,
264
 
                        (relpath, relpath), # Not renamed
265
 
                        False, # Not modified
266
 
                        (True, True), # Still  versioned
267
 
                        (executable, executable))
268
282
            changed_file_ids = set(changed_file_ids)
269
283
            for relpath, entry in self.target.inventory.iter_entries():
270
284
                if (specific_file_ids is not None
272
286
                    continue
273
287
                if not entry.file_id in changed_file_ids:
274
288
                    yield (entry.file_id,
275
 
                           (relpath, relpath),
276
 
                           False,
277
 
                           (True, True),
 
289
                           (relpath, relpath), # Not renamed
 
290
                           False, # Not modified
 
291
                           (True, True), # Still  versioned
278
292
                           (entry.parent_id, entry.parent_id),
279
293
                           (entry.name, entry.name),
280
294
                           (entry.kind, entry.kind),