/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: Robert Collins
  • Date: 2006-08-08 23:19:29 UTC
  • mfrom: (1884 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: robertc@robertcollins.net-20060808231929-4e3e298190214b3a
current status

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib.inventory import InventoryEntry
18
18
from bzrlib.trace import mutter
 
19
from bzrlib import tree
19
20
 
20
21
 
21
22
class TreeDelta(object):
90
91
            
91
92
 
92
93
    def show(self, to_file, show_ids=False, show_unchanged=False):
 
94
        """output this delta in status-like form to to_file."""
93
95
        def show_list(files):
94
96
            for item in files:
95
97
                path, fid, kind = item[:3]
141
143
            show_list(self.unchanged)
142
144
 
143
145
 
144
 
 
145
 
def compare_trees(old_tree, new_tree, want_unchanged=False, specific_files=None):
 
146
def compare_trees(old_tree, new_tree, want_unchanged=False, 
 
147
                  specific_files=None, extra_trees=None, 
 
148
                  require_versioned=False):
146
149
    """Describe changes from one tree to another.
147
150
 
148
151
    Returns a TreeDelta with details of added, modified, renamed, and
157
160
        the next.
158
161
 
159
162
    specific_files
160
 
        If true, only check for changes to specified names or
161
 
        files within them.  Any unversioned files given have no effect
162
 
        (but this might change in the future).
 
163
        If supplied, only check for changes to specified names or
 
164
        files within them.  When mapping filenames to ids, all matches in all
 
165
        trees (including optional extra_trees) are used, and all children of
 
166
        matched directories are included.
 
167
 
 
168
    extra_trees
 
169
        If non-None, a list of more trees to use for looking up file_ids from
 
170
        paths
 
171
 
 
172
    require_versioned
 
173
        If true, an all files are required to be versioned, and
 
174
        PathsNotVersionedError will be thrown if they are not.
163
175
    """
164
176
    # NB: show_status depends on being able to pass in non-versioned files and
165
177
    # report them as unknown
167
179
    try:
168
180
        new_tree.lock_read()
169
181
        try:
 
182
            trees = (new_tree, old_tree)
 
183
            if extra_trees is not None:
 
184
                trees = trees + tuple(extra_trees)
 
185
            specific_file_ids = tree.find_ids_across_trees(specific_files, 
 
186
                trees, require_versioned=require_versioned)
 
187
            if specific_files and not specific_file_ids:
 
188
                # All files are unversioned, so just return an empty delta
 
189
                # _compare_trees would think we want a complete delta
 
190
                return TreeDelta()
170
191
            return _compare_trees(old_tree, new_tree, want_unchanged,
171
 
                                  specific_files)
 
192
                                  specific_file_ids)
172
193
        finally:
173
194
            new_tree.unlock()
174
195
    finally:
175
196
        old_tree.unlock()
176
197
 
177
198
 
178
 
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files):
 
199
def _compare_trees(old_tree, new_tree, want_unchanged, specific_file_ids):
179
200
 
180
201
    from osutils import is_inside_any
181
202
    
186
207
 
187
208
    # TODO: Rather than iterating over the whole tree and then filtering, we
188
209
    # could diff just the specified files (if any) and their subtrees.  
189
 
    # Perhaps should take a list of file-ids instead?   Need to indicate any
190
 
    # ids or names which were not found in the trees.
191
210
 
192
211
    old_files = old_tree.list_files()
193
212
    new_files = new_tree.list_files()
214
233
        if old_entry.kind == 'root_directory':
215
234
            return
216
235
 
217
 
        if specific_files:
218
 
            if (not is_inside_any(specific_files, old_path)
219
 
                and not is_inside_any(specific_files, new_path)):
 
236
        if specific_file_ids:
 
237
            if (old_entry.file_id not in specific_file_ids and 
 
238
                new_entry.file_id not in specific_file_ids):
220
239
                return
221
240
 
222
241
        # temporary hack until all entries are populated before clients 
314
333
 
315
334
    # Now we have a set of added and removed files, mark them all
316
335
    for old_path, old_entry in removed.itervalues():
317
 
        if specific_files:
318
 
            if not is_inside_any(specific_files, old_path):
 
336
        if specific_file_ids:
 
337
            if not old_entry.file_id in specific_file_ids:
319
338
                continue
320
339
        delta.removed.append((old_path, old_entry.file_id, old_entry.kind))
321
340
    for new_path, new_entry in added.itervalues():
322
 
        if specific_files:
323
 
            if not is_inside_any(specific_files, new_path):
 
341
        if specific_file_ids:
 
342
            if not new_entry.file_id in specific_file_ids:
324
343
                continue
325
344
        delta.added.append((new_path, new_entry.file_id, new_entry.kind))
326
345