~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 18:38:58 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713183858-ebf4aa1f9ef8bb6e
[merge] bzr.dev 1863

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):
142
143
            show_list(self.unchanged)
143
144
 
144
145
 
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)
170
187
            return _compare_trees(old_tree, new_tree, want_unchanged,
171
 
                                  specific_files)
 
188
                                  specific_file_ids)
172
189
        finally:
173
190
            new_tree.unlock()
174
191
    finally:
175
192
        old_tree.unlock()
176
193
 
177
194
 
178
 
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files):
 
195
def _compare_trees(old_tree, new_tree, want_unchanged, specific_file_ids):
179
196
 
180
197
    from osutils import is_inside_any
181
198
    
186
203
 
187
204
    # TODO: Rather than iterating over the whole tree and then filtering, we
188
205
    # 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
206
 
192
207
    old_files = old_tree.list_files()
193
208
    new_files = new_tree.list_files()
214
229
        if old_entry.kind == 'root_directory':
215
230
            return
216
231
 
217
 
        if specific_files:
218
 
            if (not is_inside_any(specific_files, old_path)
219
 
                and not is_inside_any(specific_files, new_path)):
 
232
        if specific_file_ids:
 
233
            if (old_file_id not in specific_file_ids and 
 
234
                new_file_id not in specific_file_ids):
220
235
                return
221
236
 
222
237
        # temporary hack until all entries are populated before clients 
314
329
 
315
330
    # Now we have a set of added and removed files, mark them all
316
331
    for old_path, old_entry in removed.itervalues():
317
 
        if specific_files:
318
 
            if not is_inside_any(specific_files, old_path):
 
332
        if specific_file_ids:
 
333
            if not old_entry.file_id in specific_file_ids:
319
334
                continue
320
335
        delta.removed.append((old_path, old_entry.file_id, old_entry.kind))
321
336
    for new_path, new_entry in added.itervalues():
322
 
        if specific_files:
323
 
            if not is_inside_any(specific_files, new_path):
 
337
        if specific_file_ids:
 
338
            if not new_entry.file_id in specific_file_ids:
324
339
                continue
325
340
        delta.added.append((new_path, new_entry.file_id, new_entry.kind))
326
341