/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 breezy/delta.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:21:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610002141-m1z5k7fs8laesa65
Fix import.

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