/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

Merge bzr.dev

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
146
def compare_trees(old_tree, new_tree, want_unchanged=False, 
146
 
                  specific_files=None, include_root=False):
 
147
                  specific_files=None, extra_trees=None, 
 
148
                  require_versioned=False, include_root=False):
147
149
    """Describe changes from one tree to another.
148
150
 
149
151
    Returns a TreeDelta with details of added, modified, renamed, and
158
160
        the next.
159
161
 
160
162
    specific_files
161
 
        If true, only check for changes to specified names or
162
 
        files within them.  Any unversioned files given have no effect
163
 
        (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.
164
175
    """
165
176
    # NB: show_status depends on being able to pass in non-versioned files and
166
177
    # report them as unknown
168
179
    try:
169
180
        new_tree.lock_read()
170
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)
171
187
            return _compare_trees(old_tree, new_tree, want_unchanged,
172
 
                                  specific_files, include_root)
 
188
                                  specific_file_ids, include_root)
173
189
        finally:
174
190
            new_tree.unlock()
175
191
    finally:
176
192
        old_tree.unlock()
177
193
 
178
194
 
179
 
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files,
 
195
def _compare_trees(old_tree, new_tree, want_unchanged, specific_file_ids,
180
196
                   include_root):
181
197
 
182
198
    from osutils import is_inside_any
188
204
 
189
205
    # TODO: Rather than iterating over the whole tree and then filtering, we
190
206
    # could diff just the specified files (if any) and their subtrees.  
191
 
    # Perhaps should take a list of file-ids instead?   Need to indicate any
192
 
    # ids or names which were not found in the trees.
193
207
 
194
208
    old_files = old_tree.list_files(include_root)
195
209
    new_files = new_tree.list_files(include_root)
213
227
        """We have matched up 2 file_ids, check for changes."""
214
228
        assert old_entry.kind == new_entry.kind
215
229
 
216
 
        if specific_files:
217
 
            if (not is_inside_any(specific_files, old_path)
218
 
                and not is_inside_any(specific_files, new_path)):
 
230
        if specific_file_ids:
 
231
            if (old_file_id not in specific_file_ids and 
 
232
                new_file_id not in specific_file_ids):
219
233
                return
220
234
 
221
235
        # temporary hack until all entries are populated before clients 
312
326
 
313
327
    # Now we have a set of added and removed files, mark them all
314
328
    for old_path, old_entry in removed.itervalues():
315
 
        if specific_files:
316
 
            if not is_inside_any(specific_files, old_path):
 
329
        if specific_file_ids:
 
330
            if not old_entry.file_id in specific_file_ids:
317
331
                continue
318
332
        delta.removed.append((old_path, old_entry.file_id, old_entry.kind))
319
333
    for new_path, new_entry in added.itervalues():
320
 
        if specific_files:
321
 
            if not is_inside_any(specific_files, new_path):
 
334
        if specific_file_ids:
 
335
            if not new_entry.file_id in specific_file_ids:
322
336
                continue
323
337
        delta.added.append((new_path, new_entry.file_id, new_entry.kind))
324
338