~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    osutils,
20
20
    )
21
21
from bzrlib.inventory import InventoryEntry
22
 
from bzrlib.trace import mutter, is_quiet
23
 
from bzrlib.symbol_versioning import deprecated_function
 
22
from bzrlib.trace import mutter
 
23
from bzrlib.symbol_versioning import deprecated_function, zero_nine
24
24
 
25
25
 
26
26
class TreeDelta(object):
107
107
            
108
108
 
109
109
    def show(self, to_file, show_ids=False, show_unchanged=False,
110
 
             short_status=False, indent=''):
 
110
             short_status=False):
111
111
        """output this delta in status-like form to to_file."""
112
112
        def show_list(files, short_status_letter=''):
113
113
            for item in files:
122
122
                    path += '*'
123
123
 
124
124
                if show_ids:
125
 
                    to_file.write(indent + '%s  %-30s %s\n' % (short_status_letter,
126
 
                        path, fid))
 
125
                    print >>to_file, '%s  %-30s %s' % (short_status_letter,
 
126
                        path, fid)
127
127
                else:
128
 
                    to_file.write(indent + '%s  %s\n' % (short_status_letter, path))
 
128
                    print >>to_file, '%s  %s' % (short_status_letter, path)
129
129
            
130
130
        if self.removed:
131
131
            if not short_status:
132
 
                to_file.write(indent + 'removed:\n')
 
132
                print >>to_file, 'removed:'
133
133
                show_list(self.removed)
134
134
            else:
135
135
                show_list(self.removed, 'D')
136
136
                
137
137
        if self.added:
138
138
            if not short_status:
139
 
                to_file.write(indent + 'added:\n')
 
139
                print >>to_file, 'added:'
140
140
                show_list(self.added)
141
141
            else:
142
142
                show_list(self.added, 'A')
146
146
        if self.renamed:
147
147
            short_status_letter = 'R'
148
148
            if not short_status:
149
 
                to_file.write(indent + 'renamed:\n')
 
149
                print >>to_file, 'renamed:'
150
150
                short_status_letter = ''
151
151
            for (oldpath, newpath, fid, kind,
152
152
                 text_modified, meta_modified) in self.renamed:
156
156
                if meta_modified:
157
157
                    newpath += '*'
158
158
                if show_ids:
159
 
                    to_file.write(indent + '%s  %s => %s %s\n' % (
160
 
                        short_status_letter, oldpath, newpath, fid))
 
159
                    print >>to_file, '%s  %s => %s %s' % (
 
160
                        short_status_letter, oldpath, newpath, fid)
161
161
                else:
162
 
                    to_file.write(indent + '%s  %s => %s\n' % (
163
 
                        short_status_letter, oldpath, newpath))
 
162
                    print >>to_file, '%s  %s => %s' % (
 
163
                        short_status_letter, oldpath, newpath)
164
164
 
165
165
        if self.kind_changed:
166
166
            if short_status:
167
167
                short_status_letter = 'K'
168
168
            else:
169
 
                to_file.write(indent + 'kind changed:\n')
 
169
                print >>to_file, 'kind changed:'
170
170
                short_status_letter = ''
171
171
            for (path, fid, old_kind, new_kind) in self.kind_changed:
172
172
                if show_ids:
173
173
                    suffix = ' '+fid
174
174
                else:
175
175
                    suffix = ''
176
 
                to_file.write(indent + '%s  %s (%s => %s)%s\n' % (
177
 
                    short_status_letter, path, old_kind, new_kind, suffix))
 
176
                print >>to_file, '%s  %s (%s => %s)%s' % (
 
177
                    short_status_letter, path, old_kind, new_kind, suffix)
178
178
 
179
179
        if self.modified or extra_modified:
180
180
            short_status_letter = 'M'
181
181
            if not short_status:
182
 
                to_file.write(indent + 'modified:\n')
 
182
                print >>to_file, 'modified:'
183
183
                short_status_letter = ''
184
184
            show_list(self.modified, short_status_letter)
185
185
            show_list(extra_modified, short_status_letter)
186
186
            
187
187
        if show_unchanged and self.unchanged:
188
188
            if not short_status:
189
 
                to_file.write(indent + 'unchanged:\n')
 
189
                print >>to_file, 'unchanged:'
190
190
                show_list(self.unchanged)
191
191
            else:
192
192
                show_list(self.unchanged, 'S')
193
193
 
194
194
        if self.unversioned:
195
 
            to_file.write(indent + 'unknown:\n')
 
195
            print >>to_file, 'unknown:'
196
196
            show_list(self.unversioned)
197
197
 
198
198
    def get_changes_as_text(self, show_ids=False, show_unchanged=False,
202
202
        self.show(output, show_ids, show_unchanged, short_status)
203
203
        return output.getvalue()
204
204
 
 
205
@deprecated_function(zero_nine)
 
206
def compare_trees(old_tree, new_tree, want_unchanged=False,
 
207
                  specific_files=None, extra_trees=None,
 
208
                  require_versioned=False):
 
209
    """compare_trees was deprecated in 0.10. Please see Tree.changes_from."""
 
210
    return new_tree.changes_from(old_tree,
 
211
        want_unchanged=want_unchanged,
 
212
        specific_files=specific_files,
 
213
        extra_trees=extra_trees,
 
214
        require_versioned=require_versioned,
 
215
        include_root=False)
 
216
 
205
217
 
206
218
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files,
207
219
                   include_root, extra_trees=None,
208
 
                   require_versioned=False, want_unversioned=False):
 
220
                   want_unversioned=False):
209
221
    """Worker function that implements Tree.changes_from."""
210
222
    delta = TreeDelta()
211
223
    # mutter('start compare_trees')
212
224
 
213
225
    for (file_id, path, content_change, versioned, parent_id, name, kind,
214
 
         executable) in new_tree.iter_changes(old_tree, want_unchanged,
 
226
         executable) in new_tree._iter_changes(old_tree, want_unchanged,
215
227
            specific_files, extra_trees=extra_trees,
216
 
            require_versioned=require_versioned,
217
228
            want_unversioned=want_unversioned):
218
229
        if versioned == (False, False):
219
230
            delta.unversioned.append((path[1], None, kind[1]))
304
315
        """Report one change to a file
305
316
 
306
317
        :param file_id: The file_id of the file
307
 
        :param path: The old and new paths as generated by Tree.iter_changes.
 
318
        :param path: The old and new paths as generated by Tree._iter_changes.
308
319
        :param versioned: may be 'added', 'removed', 'unchanged', or
309
320
            'unversioned.
310
321
        :param renamed: may be True or False
311
322
        :param modified: may be 'created', 'deleted', 'kind changed',
312
323
            'modified' or 'unchanged'.
313
324
        :param exe_change: True if the execute bit has changed
314
 
        :param kind: A pair of file kinds, as generated by Tree.iter_changes.
 
325
        :param kind: A pair of file kinds, as generated by Tree._iter_changes.
315
326
            None indicates no file present.
316
327
        """
317
 
        if is_quiet():
318
 
            return
319
328
        if paths[1] == '' and versioned == 'added' and self.suppress_root_add:
320
329
            return
321
330
        if versioned == 'unversioned':
335
344
                # on a rename, we show old and new
336
345
                old_path, path = paths
337
346
            else:
338
 
                # if it's not renamed, we're showing both for kind changes
 
347
                # if its not renamed, we're showing both for kind changes
339
348
                # so only show the new path
340
349
                old_path, path = paths[1], paths[1]
341
350
            # if the file is not missing in the source, we show its kind
375
384
    Further processing may be required to produce a human-readable output.
376
385
    Unfortunately, some tree-changing operations are very complex
377
386
    :change_iterator: an iterator or sequence of changes in the format
378
 
        generated by Tree.iter_changes
 
387
        generated by Tree._iter_changes
379
388
    :param reporter: The _ChangeReporter that will report the changes.
380
389
    """
381
390
    versioned_change_map = {