/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: 2018-08-14 01:15:02 UTC
  • mto: This revision was merged to the branch mainline in revision 7078.
  • Revision ID: jelmer@jelmer.uk-20180814011502-5zaydaq02vc2qxo1
Fix tests.

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()
166
172
    delta.unchanged.sort()
 
173
    delta.unversioned.sort()
167
174
 
168
175
    return delta
169
176
 
172
179
    """Report changes between two trees"""
173
180
 
174
181
    def __init__(self, output=None, suppress_root_add=True,
175
 
                 output_file=None, unversioned_filter=None, view_info=None):
 
182
                 output_file=None, unversioned_filter=None, view_info=None,
 
183
                 classify=True):
176
184
        """Constructor
177
185
 
178
186
        :param output: a function with the signature of trace.note, i.e.
187
195
        :param view_info: A tuple of view_name,view_files if only
188
196
            items inside a view are to be reported on, or None for
189
197
            no view filtering.
 
198
        :param classify: Add special symbols to indicate file kind.
190
199
        """
191
200
        if output_file is not None:
192
201
            if output is not None:
195
204
                output_file.write((fmt % args) + '\n')
196
205
        self.output = output
197
206
        if self.output is None:
198
 
            from bzrlib import trace
 
207
            from . import trace
199
208
            self.output = trace.note
200
209
        self.suppress_root_add = suppress_root_add
201
210
        self.modified_map = {'kind changed': 'K',
202
211
                             'unchanged': ' ',
203
212
                             'created': 'N',
204
213
                             'modified': 'M',
205
 
                             'deleted': 'D'}
 
214
                             'deleted': 'D',
 
215
                             'missing': '!',
 
216
                             }
206
217
        self.versioned_map = {'added': '+', # versioned target
207
218
                              'unchanged': ' ', # versioned in both
208
219
                              'removed': '-', # versioned in source
209
220
                              'unversioned': '?', # versioned in neither
210
221
                              }
211
222
        self.unversioned_filter = unversioned_filter
 
223
        if classify:
 
224
            self.kind_marker = osutils.kind_marker
 
225
        else:
 
226
            self.kind_marker = lambda kind: ''
212
227
        if view_info is None:
213
228
            self.view_name = None
214
229
            self.view_files = []
263
278
            # if the file is not missing in the source, we show its kind
264
279
            # when we show two paths.
265
280
            if kind[0] is not None:
266
 
                old_path += osutils.kind_marker(kind[0])
 
281
                old_path += self.kind_marker(kind[0])
267
282
            old_path += " => "
268
283
        elif versioned == 'removed':
269
284
            # not present in target
278
293
            rename = self.versioned_map[versioned]
279
294
        # we show the old kind on the new path when the content is deleted.
280
295
        if modified == 'deleted':
281
 
            path += osutils.kind_marker(kind[0])
 
296
            path += self.kind_marker(kind[0])
282
297
        # otherwise we always show the current kind when there is one
283
298
        elif kind[1] is not None:
284
 
            path += osutils.kind_marker(kind[1])
 
299
            path += self.kind_marker(kind[1])
285
300
        if exe_change:
286
301
            exe = '*'
287
302
        else:
289
304
        self.output("%s%s%s %s%s", rename, self.modified_map[modified], exe,
290
305
                    old_path, path)
291
306
 
 
307
 
292
308
def report_changes(change_iterator, reporter):
293
309
    """Report the changes from a change iterator.
294
310
 
300
316
    :param reporter: The _ChangeReporter that will report the changes.
301
317
    """
302
318
    versioned_change_map = {
303
 
        (True, True)  : 'unchanged',
304
 
        (True, False) : 'removed',
305
 
        (False, True) : 'added',
 
319
        (True, True): 'unchanged',
 
320
        (True, False): 'removed',
 
321
        (False, True): 'added',
306
322
        (False, False): 'unversioned',
307
323
        }
 
324
    def path_key(change):
 
325
        if change[1][0] is not None:
 
326
            path = change[1][0]
 
327
        else:
 
328
            path = change[1][1]
 
329
        return osutils.splitpath(path)
308
330
    for (file_id, path, content_change, versioned, parent_id, name, kind,
309
 
         executable) in change_iterator:
 
331
         executable) in sorted(change_iterator, key=path_key):
310
332
        exe_change = False
311
333
        # files are "renamed" if they are moved or if name changes, as long
312
334
        # as it had a value
325
347
        else:
326
348
            if content_change:
327
349
                modified = "modified"
 
350
            elif kind[0] is None:
 
351
                modified = "missing"
328
352
            else:
329
353
                modified = "unchanged"
330
354
            if kind[1] == "file":
333
357
        reporter.report(file_id, path, versioned_change, renamed, modified,
334
358
                        exe_change, kind)
335
359
 
336
 
def report_delta(to_file, delta, short_status=False, show_ids=False, 
337
 
         show_unchanged=False, indent='', filter=None):
 
360
 
 
361
def report_delta(to_file, delta, short_status=False, show_ids=False,
 
362
        show_unchanged=False, indent='', predicate=None, classify=True):
338
363
    """Output this delta in status-like form to to_file.
339
364
 
340
365
    :param to_file: A file-like object where the output is displayed.
350
375
    :param indent: Added at the beginning of all output lines (for merged
351
376
        revisions).
352
377
 
353
 
    :param filter: A callable receiving a path and a file id and
 
378
    :param predicate: A callable receiving a path and a file id and
354
379
        returning True if the path should be displayed.
 
380
 
 
381
    :param classify: Add special symbols to indicate file kind.
355
382
    """
356
383
 
357
384
    def decorate_path(path, kind, meta_modified=None):
 
385
        if not classify:
 
386
            return path
358
387
        if kind == 'directory':
359
388
            path += '/'
360
389
        elif kind == 'symlink':
397
426
 
398
427
            for item in files:
399
428
                path, file_id, kind = item[:3]
400
 
                if (filter is not None and not filter(path, file_id)):
 
429
                if (predicate is not None and not predicate(path, file_id)):
401
430
                    continue
402
431
                if not header_shown and not short_status:
403
432
                    to_file.write(indent + long_status_name + ':\n')
417
446
 
418
447
    show_list(delta.removed, 'removed', 'D')
419
448
    show_list(delta.added, 'added', 'A')
 
449
    show_list(delta.missing, 'missing', '!')
420
450
    extra_modified = []
421
451
    # Reorder delta.renamed tuples so that all lists share the same
422
452
    # order for their 3 first fields and that they also begin like