/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: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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
 
from breezy import (
 
17
from bzrlib import (
20
18
    osutils,
21
19
    )
22
 
from .sixish import (
23
 
    StringIO,
24
 
    )
25
 
from .trace import is_quiet
 
20
from bzrlib.trace import is_quiet
26
21
 
27
22
 
28
23
class TreeDelta(object):
66
61
        self.modified = []
67
62
        self.unchanged = []
68
63
        self.unversioned = []
69
 
        self.missing = []
70
64
 
71
65
    def __eq__(self, other):
72
66
        if not isinstance(other, TreeDelta):
112
106
 
113
107
    def get_changes_as_text(self, show_ids=False, show_unchanged=False,
114
108
                            short_status=False):
115
 
        output = StringIO()
 
109
        import StringIO
 
110
        output = StringIO.StringIO()
116
111
        report_delta(output, self, short_status, show_ids, show_unchanged)
117
112
        return output.getvalue()
118
113
 
142
137
            else:
143
138
                delta.removed.append((path[0], file_id, kind[0]))
144
139
        elif fully_present[0] is False:
145
 
            delta.missing.append((path[1], file_id, kind[1]))
 
140
            continue
146
141
        elif name[0] != name[1] or parent_id[0] != parent_id[1]:
147
142
            # If the name changes, or the parent_id changes, we have a rename
148
143
            # (if we move a parent, that doesn't count as a rename for the
165
160
    delta.removed.sort()
166
161
    delta.added.sort()
167
162
    delta.renamed.sort()
168
 
    delta.missing.sort()
169
163
    # TODO: jam 20060529 These lists shouldn't need to be sorted
170
164
    #       since we added them in alphabetical order.
171
165
    delta.modified.sort()
178
172
    """Report changes between two trees"""
179
173
 
180
174
    def __init__(self, output=None, suppress_root_add=True,
181
 
                 output_file=None, unversioned_filter=None, view_info=None,
182
 
                 classify=True):
 
175
                 output_file=None, unversioned_filter=None, view_info=None):
183
176
        """Constructor
184
177
 
185
178
        :param output: a function with the signature of trace.note, i.e.
194
187
        :param view_info: A tuple of view_name,view_files if only
195
188
            items inside a view are to be reported on, or None for
196
189
            no view filtering.
197
 
        :param classify: Add special symbols to indicate file kind.
198
190
        """
199
191
        if output_file is not None:
200
192
            if output is not None:
203
195
                output_file.write((fmt % args) + '\n')
204
196
        self.output = output
205
197
        if self.output is None:
206
 
            from . import trace
 
198
            from bzrlib import trace
207
199
            self.output = trace.note
208
200
        self.suppress_root_add = suppress_root_add
209
201
        self.modified_map = {'kind changed': 'K',
210
202
                             'unchanged': ' ',
211
203
                             'created': 'N',
212
204
                             'modified': 'M',
213
 
                             'deleted': 'D',
214
 
                             'missing': '!',
215
 
                             }
 
205
                             'deleted': 'D'}
216
206
        self.versioned_map = {'added': '+', # versioned target
217
207
                              'unchanged': ' ', # versioned in both
218
208
                              'removed': '-', # versioned in source
219
209
                              'unversioned': '?', # versioned in neither
220
210
                              }
221
211
        self.unversioned_filter = unversioned_filter
222
 
        if classify:
223
 
            self.kind_marker = osutils.kind_marker
224
 
        else:
225
 
            self.kind_marker = lambda kind: ''
226
212
        if view_info is None:
227
213
            self.view_name = None
228
214
            self.view_files = []
277
263
            # if the file is not missing in the source, we show its kind
278
264
            # when we show two paths.
279
265
            if kind[0] is not None:
280
 
                old_path += self.kind_marker(kind[0])
 
266
                old_path += osutils.kind_marker(kind[0])
281
267
            old_path += " => "
282
268
        elif versioned == 'removed':
283
269
            # not present in target
292
278
            rename = self.versioned_map[versioned]
293
279
        # we show the old kind on the new path when the content is deleted.
294
280
        if modified == 'deleted':
295
 
            path += self.kind_marker(kind[0])
 
281
            path += osutils.kind_marker(kind[0])
296
282
        # otherwise we always show the current kind when there is one
297
283
        elif kind[1] is not None:
298
 
            path += self.kind_marker(kind[1])
 
284
            path += osutils.kind_marker(kind[1])
299
285
        if exe_change:
300
286
            exe = '*'
301
287
        else:
314
300
    :param reporter: The _ChangeReporter that will report the changes.
315
301
    """
316
302
    versioned_change_map = {
317
 
        (True, True): 'unchanged',
318
 
        (True, False): 'removed',
319
 
        (False, True): 'added',
 
303
        (True, True)  : 'unchanged',
 
304
        (True, False) : 'removed',
 
305
        (False, True) : 'added',
320
306
        (False, False): 'unversioned',
321
307
        }
322
308
    for (file_id, path, content_change, versioned, parent_id, name, kind,
339
325
        else:
340
326
            if content_change:
341
327
                modified = "modified"
342
 
            elif kind[0] is None:
343
 
                modified = "missing"
344
328
            else:
345
329
                modified = "unchanged"
346
330
            if kind[1] == "file":
349
333
        reporter.report(file_id, path, versioned_change, renamed, modified,
350
334
                        exe_change, kind)
351
335
 
352
 
 
353
 
def report_delta(to_file, delta, short_status=False, show_ids=False,
354
 
        show_unchanged=False, indent='', predicate=None, classify=True):
 
336
def report_delta(to_file, delta, short_status=False, show_ids=False, 
 
337
         show_unchanged=False, indent='', filter=None):
355
338
    """Output this delta in status-like form to to_file.
356
339
 
357
340
    :param to_file: A file-like object where the output is displayed.
367
350
    :param indent: Added at the beginning of all output lines (for merged
368
351
        revisions).
369
352
 
370
 
    :param predicate: A callable receiving a path and a file id and
 
353
    :param filter: A callable receiving a path and a file id and
371
354
        returning True if the path should be displayed.
372
 
 
373
 
    :param classify: Add special symbols to indicate file kind.
374
355
    """
375
356
 
376
357
    def decorate_path(path, kind, meta_modified=None):
377
 
        if not classify:
378
 
            return path
379
358
        if kind == 'directory':
380
359
            path += '/'
381
360
        elif kind == 'symlink':
418
397
 
419
398
            for item in files:
420
399
                path, file_id, kind = item[:3]
421
 
                if (predicate is not None and not predicate(path, file_id)):
 
400
                if (filter is not None and not filter(path, file_id)):
422
401
                    continue
423
402
                if not header_shown and not short_status:
424
403
                    to_file.write(indent + long_status_name + ':\n')
438
417
 
439
418
    show_list(delta.removed, 'removed', 'D')
440
419
    show_list(delta.added, 'added', 'A')
441
 
    show_list(delta.missing, 'missing', '!')
442
420
    extra_modified = []
443
421
    # Reorder delta.renamed tuples so that all lists share the same
444
422
    # order for their 3 first fields and that they also begin like