~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/delta.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
from bzrlib import (
20
18
    osutils,
21
19
    )
63
61
        self.modified = []
64
62
        self.unchanged = []
65
63
        self.unversioned = []
66
 
        self.missing = []
67
64
 
68
65
    def __eq__(self, other):
69
66
        if not isinstance(other, TreeDelta):
140
137
            else:
141
138
                delta.removed.append((path[0], file_id, kind[0]))
142
139
        elif fully_present[0] is False:
143
 
            delta.missing.append((path[1], file_id, kind[1]))
 
140
            continue
144
141
        elif name[0] != name[1] or parent_id[0] != parent_id[1]:
145
142
            # If the name changes, or the parent_id changes, we have a rename
146
143
            # (if we move a parent, that doesn't count as a rename for the
163
160
    delta.removed.sort()
164
161
    delta.added.sort()
165
162
    delta.renamed.sort()
166
 
    delta.missing.sort()
167
163
    # TODO: jam 20060529 These lists shouldn't need to be sorted
168
164
    #       since we added them in alphabetical order.
169
165
    delta.modified.sort()
176
172
    """Report changes between two trees"""
177
173
 
178
174
    def __init__(self, output=None, suppress_root_add=True,
179
 
                 output_file=None, unversioned_filter=None, view_info=None,
180
 
                 classify=True):
 
175
                 output_file=None, unversioned_filter=None, view_info=None):
181
176
        """Constructor
182
177
 
183
178
        :param output: a function with the signature of trace.note, i.e.
192
187
        :param view_info: A tuple of view_name,view_files if only
193
188
            items inside a view are to be reported on, or None for
194
189
            no view filtering.
195
 
        :param classify: Add special symbols to indicate file kind.
196
190
        """
197
191
        if output_file is not None:
198
192
            if output is not None:
208
202
                             'unchanged': ' ',
209
203
                             'created': 'N',
210
204
                             'modified': 'M',
211
 
                             'deleted': 'D',
212
 
                             'missing': '!',
213
 
                             }
 
205
                             'deleted': 'D'}
214
206
        self.versioned_map = {'added': '+', # versioned target
215
207
                              'unchanged': ' ', # versioned in both
216
208
                              'removed': '-', # versioned in source
217
209
                              'unversioned': '?', # versioned in neither
218
210
                              }
219
211
        self.unversioned_filter = unversioned_filter
220
 
        if classify:
221
 
            self.kind_marker = osutils.kind_marker
222
 
        else:
223
 
            self.kind_marker = lambda kind: ''
224
212
        if view_info is None:
225
213
            self.view_name = None
226
214
            self.view_files = []
275
263
            # if the file is not missing in the source, we show its kind
276
264
            # when we show two paths.
277
265
            if kind[0] is not None:
278
 
                old_path += self.kind_marker(kind[0])
 
266
                old_path += osutils.kind_marker(kind[0])
279
267
            old_path += " => "
280
268
        elif versioned == 'removed':
281
269
            # not present in target
290
278
            rename = self.versioned_map[versioned]
291
279
        # we show the old kind on the new path when the content is deleted.
292
280
        if modified == 'deleted':
293
 
            path += self.kind_marker(kind[0])
 
281
            path += osutils.kind_marker(kind[0])
294
282
        # otherwise we always show the current kind when there is one
295
283
        elif kind[1] is not None:
296
 
            path += self.kind_marker(kind[1])
 
284
            path += osutils.kind_marker(kind[1])
297
285
        if exe_change:
298
286
            exe = '*'
299
287
        else:
337
325
        else:
338
326
            if content_change:
339
327
                modified = "modified"
340
 
            elif kind[0] is None:
341
 
                modified = "missing"
342
328
            else:
343
329
                modified = "unchanged"
344
330
            if kind[1] == "file":
348
334
                        exe_change, kind)
349
335
 
350
336
def report_delta(to_file, delta, short_status=False, show_ids=False, 
351
 
         show_unchanged=False, indent='', filter=None, classify=True):
 
337
         show_unchanged=False, indent='', filter=None):
352
338
    """Output this delta in status-like form to to_file.
353
339
 
354
340
    :param to_file: A file-like object where the output is displayed.
366
352
 
367
353
    :param filter: A callable receiving a path and a file id and
368
354
        returning True if the path should be displayed.
369
 
 
370
 
    :param classify: Add special symbols to indicate file kind.
371
355
    """
372
356
 
373
357
    def decorate_path(path, kind, meta_modified=None):
374
 
        if not classify:
375
 
            return path
376
358
        if kind == 'directory':
377
359
            path += '/'
378
360
        elif kind == 'symlink':
435
417
 
436
418
    show_list(delta.removed, 'removed', 'D')
437
419
    show_list(delta.added, 'added', 'A')
438
 
    show_list(delta.missing, 'missing', '!')
439
420
    extra_modified = []
440
421
    # Reorder delta.renamed tuples so that all lists share the same
441
422
    # order for their 3 first fields and that they also begin like