/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:26:22 UTC
  • mfrom: (7167.1.4 run-flake8)
  • Revision ID: breezy.the.bot@gmail.com-20181116182622-qw3gan3hz78a2imw
Add a flake8 test.

Merged from https://code.launchpad.net/~jelmer/brz/run-flake8/+merge/358902

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