/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: 2005-12-24 02:20:45 UTC
  • mto: (1185.50.57 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: robertc@robertcollins.net-20051224022045-14efc8dfa0e1a4e9
Start tests for api usage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
2
 
#
 
1
# -*- coding: UTF-8 -*-
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from io import StringIO
18
 
 
19
 
from breezy import (
20
 
    osutils,
21
 
    trace,
22
 
    )
23
 
from .tree import TreeChange
24
 
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib.inventory import InventoryEntry
 
18
from bzrlib.trace import mutter
25
19
 
26
20
class TreeDelta(object):
27
21
    """Describes changes from one tree to another.
28
22
 
29
 
    Contains seven lists with TreeChange objects.
 
23
    Contains four lists:
30
24
 
31
25
    added
 
26
        (path, id, kind)
32
27
    removed
 
28
        (path, id, kind)
33
29
    renamed
34
 
    copied
35
 
    kind_changed
 
30
        (oldpath, newpath, id, kind, text_modified, meta_modified)
36
31
    modified
 
32
        (path, id, kind, text_modified, meta_modified)
37
33
    unchanged
38
 
    unversioned
 
34
        (path, id, kind)
39
35
 
40
36
    Each id is listed only once.
41
37
 
42
 
    Files that are both modified and renamed or copied are listed only in
43
 
    renamed or copied, with the text_modified flag true. The text_modified
44
 
    applies either to the content of the file or the target of the
 
38
    Files that are both modified and renamed are listed only in
 
39
    renamed, with the text_modified flag true. The text_modified
 
40
    applies either to the the content of the file or the target of the
45
41
    symbolic link, depending of the kind of file.
46
42
 
47
43
    Files are only considered renamed if their name has changed or
50
46
 
51
47
    The lists are normally sorted when the delta is created.
52
48
    """
53
 
 
54
49
    def __init__(self):
55
50
        self.added = []
56
51
        self.removed = []
57
52
        self.renamed = []
58
 
        self.copied = []
59
 
        self.kind_changed = []
60
53
        self.modified = []
61
54
        self.unchanged = []
62
 
        self.unversioned = []
63
 
        self.missing = []
64
55
 
65
56
    def __eq__(self, other):
66
57
        if not isinstance(other, TreeDelta):
67
58
            return False
68
59
        return self.added == other.added \
69
 
            and self.removed == other.removed \
70
 
            and self.renamed == other.renamed \
71
 
            and self.copied == other.copied \
72
 
            and self.modified == other.modified \
73
 
            and self.unchanged == other.unchanged \
74
 
            and self.kind_changed == other.kind_changed \
75
 
            and self.unversioned == other.unversioned
 
60
               and self.removed == other.removed \
 
61
               and self.renamed == other.renamed \
 
62
               and self.modified == other.modified \
 
63
               and self.unchanged == other.unchanged
76
64
 
77
65
    def __ne__(self, other):
78
66
        return not (self == other)
79
67
 
80
68
    def __repr__(self):
81
 
        return "TreeDelta(added=%r, removed=%r, renamed=%r," \
82
 
            " copied=%r, kind_changed=%r, modified=%r, unchanged=%r," \
83
 
            " unversioned=%r)" % (
84
 
                self.added, self.removed, self.renamed, self.copied,
85
 
                self.kind_changed, self.modified, self.unchanged,
86
 
                self.unversioned)
 
69
        return "TreeDelta(added=%r, removed=%r, renamed=%r, modified=%r," \
 
70
            " unchanged=%r)" % (self.added, self.removed, self.renamed,
 
71
            self.modified, self.unchanged)
87
72
 
88
73
    def has_changed(self):
89
74
        return bool(self.modified
90
75
                    or self.added
91
76
                    or self.removed
92
 
                    or self.renamed
93
 
                    or self.copied
94
 
                    or self.kind_changed)
95
 
 
96
 
    def get_changes_as_text(self, show_ids=False, show_unchanged=False,
97
 
                            short_status=False):
98
 
        output = StringIO()
99
 
        report_delta(output, self, short_status, show_ids, show_unchanged)
100
 
        return output.getvalue()
101
 
 
102
 
 
103
 
def _compare_trees(old_tree, new_tree, want_unchanged, specific_files,
104
 
                   include_root, extra_trees=None,
105
 
                   require_versioned=False, want_unversioned=False):
106
 
    """Worker function that implements Tree.changes_from."""
 
77
                    or self.renamed)
 
78
 
 
79
    def touches_file_id(self, file_id):
 
80
        """Return True if file_id is modified by this delta."""
 
81
        for l in self.added, self.removed, self.modified:
 
82
            for v in l:
 
83
                if v[1] == file_id:
 
84
                    return True
 
85
        for v in self.renamed:
 
86
            if v[2] == file_id:
 
87
                return True
 
88
        return False
 
89
            
 
90
 
 
91
    def show(self, to_file, show_ids=False, show_unchanged=False):
 
92
        def show_list(files):
 
93
            for item in files:
 
94
                path, fid, kind = item[:3]
 
95
 
 
96
                if kind == 'directory':
 
97
                    path += '/'
 
98
                elif kind == 'symlink':
 
99
                    path += '@'
 
100
 
 
101
                if len(item) == 5 and item[4]:
 
102
                    path += '*'
 
103
 
 
104
                if show_ids:
 
105
                    print >>to_file, '  %-30s %s' % (path, fid)
 
106
                else:
 
107
                    print >>to_file, ' ', path
 
108
            
 
109
        if self.removed:
 
110
            print >>to_file, 'removed:'
 
111
            show_list(self.removed)
 
112
                
 
113
        if self.added:
 
114
            print >>to_file, 'added:'
 
115
            show_list(self.added)
 
116
 
 
117
        extra_modified = []
 
118
 
 
119
        if self.renamed:
 
120
            print >>to_file, 'renamed:'
 
121
            for (oldpath, newpath, fid, kind,
 
122
                 text_modified, meta_modified) in self.renamed:
 
123
                if text_modified or meta_modified:
 
124
                    extra_modified.append((newpath, fid, kind,
 
125
                                           text_modified, meta_modified))
 
126
                if meta_modified:
 
127
                    newpath += '*'
 
128
                if show_ids:
 
129
                    print >>to_file, '  %s => %s %s' % (oldpath, newpath, fid)
 
130
                else:
 
131
                    print >>to_file, '  %s => %s' % (oldpath, newpath)
 
132
                    
 
133
        if self.modified or extra_modified:
 
134
            print >>to_file, 'modified:'
 
135
            show_list(self.modified)
 
136
            show_list(extra_modified)
 
137
            
 
138
        if show_unchanged and self.unchanged:
 
139
            print >>to_file, 'unchanged:'
 
140
            show_list(self.unchanged)
 
141
 
 
142
 
 
143
 
 
144
def compare_trees(old_tree, new_tree, want_unchanged=False, specific_files=None):
 
145
    """Describe changes from one tree to another.
 
146
 
 
147
    Returns a TreeDelta with details of added, modified, renamed, and
 
148
    deleted entries.
 
149
 
 
150
    The root entry is specifically exempt.
 
151
 
 
152
    This only considers versioned files.
 
153
 
 
154
    want_unchanged
 
155
        If true, also list files unchanged from one version to
 
156
        the next.
 
157
 
 
158
    specific_files
 
159
        If true, only check for changes to specified names or
 
160
        files within them.
 
161
    """
 
162
 
 
163
    from osutils import is_inside_any
 
164
    
 
165
    old_inv = old_tree.inventory
 
166
    new_inv = new_tree.inventory
107
167
    delta = TreeDelta()
108
 
    # mutter('start compare_trees')
109
 
 
110
 
    for change in new_tree.iter_changes(
111
 
            old_tree, want_unchanged, specific_files, extra_trees=extra_trees,
112
 
            require_versioned=require_versioned,
113
 
            want_unversioned=want_unversioned):
114
 
        if change.versioned == (False, False):
115
 
            delta.unversioned.append(change)
116
 
            continue
117
 
        if not include_root and (None, None) == change.parent_id:
118
 
            continue
119
 
        fully_present = tuple(
120
 
            (change.versioned[x] and change.kind[x] is not None)
121
 
            for x in range(2))
122
 
        if fully_present[0] != fully_present[1]:
123
 
            if fully_present[1] is True:
124
 
                delta.added.append(change)
125
 
            else:
126
 
                if change.kind[0] == 'symlink' and not new_tree.supports_symlinks():
127
 
                    trace.warning(
128
 
                        'Ignoring "%s" as symlinks '
129
 
                        'are not supported on this filesystem.' % (change.path[0],))
130
 
                else:
131
 
                    delta.removed.append(change)
132
 
        elif fully_present[0] is False:
133
 
            delta.missing.append(change)
134
 
        elif change.name[0] != change.name[1] or change.parent_id[0] != change.parent_id[1]:
135
 
            # If the name changes, or the parent_id changes, we have a rename or copy
136
 
            # (if we move a parent, that doesn't count as a rename for the
137
 
            # file)
138
 
            if change.copied:
139
 
                delta.copied.append(change)
140
 
            else:
141
 
                delta.renamed.append(change)
142
 
        elif change.kind[0] != change.kind[1]:
143
 
            delta.kind_changed.append(change)
144
 
        elif change.changed_content or change.executable[0] != change.executable[1]:
145
 
            delta.modified.append(change)
146
 
        else:
147
 
            delta.unchanged.append(change)
148
 
 
149
 
    def change_key(change):
150
 
        if change.path[0] is None:
151
 
            path = change.path[1]
152
 
        else:
153
 
            path = change.path[0]
154
 
        return (path, change.file_id)
155
 
 
156
 
    delta.removed.sort(key=change_key)
157
 
    delta.added.sort(key=change_key)
158
 
    delta.renamed.sort(key=change_key)
159
 
    delta.copied.sort(key=change_key)
160
 
    delta.missing.sort(key=change_key)
161
 
    # TODO: jam 20060529 These lists shouldn't need to be sorted
162
 
    #       since we added them in alphabetical order.
163
 
    delta.modified.sort(key=change_key)
164
 
    delta.unchanged.sort(key=change_key)
165
 
    delta.unversioned.sort(key=change_key)
 
168
    mutter('start compare_trees')
 
169
 
 
170
    # TODO: match for specific files can be rather smarter by finding
 
171
    # the IDs of those files up front and then considering only that.
 
172
 
 
173
    for file_id in old_tree:
 
174
        if file_id in new_tree:
 
175
            old_ie = old_inv[file_id]
 
176
            new_ie = new_inv[file_id]
 
177
 
 
178
            kind = old_ie.kind
 
179
            assert kind == new_ie.kind
 
180
            
 
181
            assert kind in InventoryEntry.known_kinds, \
 
182
                   'invalid file kind %r' % kind
 
183
 
 
184
            if kind == 'root_directory':
 
185
                continue
 
186
            
 
187
            if specific_files:
 
188
                if (not is_inside_any(specific_files, old_inv.id2path(file_id)) 
 
189
                    and not is_inside_any(specific_files, new_inv.id2path(file_id))):
 
190
                    continue
 
191
 
 
192
            # temporary hack until all entries are populated before clients 
 
193
            # get them
 
194
            old_path = old_inv.id2path(file_id)
 
195
            new_path = new_inv.id2path(file_id)
 
196
            old_ie._read_tree_state(old_path, old_tree)
 
197
            new_ie._read_tree_state(new_path, new_tree)
 
198
            text_modified, meta_modified = new_ie.detect_changes(old_ie)
 
199
 
 
200
            # TODO: Can possibly avoid calculating path strings if the
 
201
            # two files are unchanged and their names and parents are
 
202
            # the same and the parents are unchanged all the way up.
 
203
            # May not be worthwhile.
 
204
            
 
205
            if (old_ie.name != new_ie.name
 
206
                or old_ie.parent_id != new_ie.parent_id):
 
207
                delta.renamed.append((old_path,
 
208
                                      new_path,
 
209
                                      file_id, kind,
 
210
                                      text_modified, meta_modified))
 
211
            elif text_modified or meta_modified:
 
212
                delta.modified.append((new_path, file_id, kind,
 
213
                                       text_modified, meta_modified))
 
214
            elif want_unchanged:
 
215
                delta.unchanged.append((new_path, file_id, kind))
 
216
        else:
 
217
            kind = old_inv.get_file_kind(file_id)
 
218
            if kind == 'root_directory':
 
219
                continue
 
220
            old_path = old_inv.id2path(file_id)
 
221
            if specific_files:
 
222
                if not is_inside_any(specific_files, old_path):
 
223
                    continue
 
224
            delta.removed.append((old_path, file_id, kind))
 
225
 
 
226
    mutter('start looking for new files')
 
227
    for file_id in new_inv:
 
228
        if file_id in old_inv or file_id not in new_tree:
 
229
            continue
 
230
        kind = new_inv.get_file_kind(file_id)
 
231
        if kind == 'root_directory':
 
232
            continue
 
233
        new_path = new_inv.id2path(file_id)
 
234
        if specific_files:
 
235
            if not is_inside_any(specific_files, new_path):
 
236
                continue
 
237
        delta.added.append((new_path, file_id, kind))
 
238
            
 
239
    delta.removed.sort()
 
240
    delta.added.sort()
 
241
    delta.renamed.sort()
 
242
    delta.modified.sort()
 
243
    delta.unchanged.sort()
166
244
 
167
245
    return delta
168
 
 
169
 
 
170
 
class _ChangeReporter(object):
171
 
    """Report changes between two trees"""
172
 
 
173
 
    def __init__(self, output=None, suppress_root_add=True,
174
 
                 output_file=None, unversioned_filter=None, view_info=None,
175
 
                 classify=True):
176
 
        """Constructor
177
 
 
178
 
        :param output: a function with the signature of trace.note, i.e.
179
 
            accepts a format and parameters.
180
 
        :param supress_root_add: If true, adding the root will be ignored
181
 
            (i.e. when a tree has just been initted)
182
 
        :param output_file: If supplied, a file-like object to write to.
183
 
            Only one of output and output_file may be supplied.
184
 
        :param unversioned_filter: A filter function to be called on
185
 
            unversioned files. This should return True to ignore a path.
186
 
            By default, no filtering takes place.
187
 
        :param view_info: A tuple of view_name,view_files if only
188
 
            items inside a view are to be reported on, or None for
189
 
            no view filtering.
190
 
        :param classify: Add special symbols to indicate file kind.
191
 
        """
192
 
        if output_file is not None:
193
 
            if output is not None:
194
 
                raise BzrError('Cannot specify both output and output_file')
195
 
 
196
 
            def output(fmt, *args):
197
 
                output_file.write((fmt % args) + '\n')
198
 
        self.output = output
199
 
        if self.output is None:
200
 
            from . import trace
201
 
            self.output = trace.note
202
 
        self.suppress_root_add = suppress_root_add
203
 
        self.modified_map = {'kind changed': 'K',
204
 
                             'unchanged': ' ',
205
 
                             'created': 'N',
206
 
                             'modified': 'M',
207
 
                             'deleted': 'D',
208
 
                             'missing': '!',
209
 
                             }
210
 
        self.versioned_map = {'added': '+',  # versioned target
211
 
                              'unchanged': ' ',  # versioned in both
212
 
                              'removed': '-',  # versioned in source
213
 
                              'unversioned': '?',  # versioned in neither
214
 
                              }
215
 
        self.unversioned_filter = unversioned_filter
216
 
        if classify:
217
 
            self.kind_marker = osutils.kind_marker
218
 
        else:
219
 
            self.kind_marker = lambda kind: ''
220
 
        if view_info is None:
221
 
            self.view_name = None
222
 
            self.view_files = []
223
 
        else:
224
 
            self.view_name = view_info[0]
225
 
            self.view_files = view_info[1]
226
 
            self.output("Operating on whole tree but only reporting on "
227
 
                        "'%s' view." % (self.view_name,))
228
 
 
229
 
    def report(self, paths, versioned, renamed, copied, modified, exe_change,
230
 
               kind):
231
 
        """Report one change to a file
232
 
 
233
 
        :param path: The old and new paths as generated by Tree.iter_changes.
234
 
        :param versioned: may be 'added', 'removed', 'unchanged', or
235
 
            'unversioned.
236
 
        :param renamed: may be True or False
237
 
        :param copied: may be True or False
238
 
        :param modified: may be 'created', 'deleted', 'kind changed',
239
 
            'modified' or 'unchanged'.
240
 
        :param exe_change: True if the execute bit has changed
241
 
        :param kind: A pair of file kinds, as generated by Tree.iter_changes.
242
 
            None indicates no file present.
243
 
        """
244
 
        if trace.is_quiet():
245
 
            return
246
 
        if paths[1] == '' and versioned == 'added' and self.suppress_root_add:
247
 
            return
248
 
        if self.view_files and not osutils.is_inside_any(self.view_files,
249
 
                                                         paths[1]):
250
 
            return
251
 
        if versioned == 'unversioned':
252
 
            # skip ignored unversioned files if needed.
253
 
            if self.unversioned_filter is not None:
254
 
                if self.unversioned_filter(paths[1]):
255
 
                    return
256
 
            # dont show a content change in the output.
257
 
            modified = 'unchanged'
258
 
        # we show both paths in the following situations:
259
 
        # the file versioning is unchanged AND
260
 
        # ( the path is different OR
261
 
        #   the kind is different)
262
 
        if (versioned == 'unchanged' and
263
 
                (renamed or copied or modified == 'kind changed')):
264
 
            if renamed or copied:
265
 
                # on a rename or copy, we show old and new
266
 
                old_path, path = paths
267
 
            else:
268
 
                # if it's not renamed or copied, we're showing both for kind
269
 
                # changes so only show the new path
270
 
                old_path, path = paths[1], paths[1]
271
 
            # if the file is not missing in the source, we show its kind
272
 
            # when we show two paths.
273
 
            if kind[0] is not None:
274
 
                old_path += self.kind_marker(kind[0])
275
 
            old_path += " => "
276
 
        elif versioned == 'removed':
277
 
            # not present in target
278
 
            old_path = ""
279
 
            path = paths[0]
280
 
        else:
281
 
            old_path = ""
282
 
            path = paths[1]
283
 
        if renamed:
284
 
            rename = "R"
285
 
        elif copied:
286
 
            rename = "C"
287
 
        else:
288
 
            rename = self.versioned_map[versioned]
289
 
        # we show the old kind on the new path when the content is deleted.
290
 
        if modified == 'deleted':
291
 
            path += self.kind_marker(kind[0])
292
 
        # otherwise we always show the current kind when there is one
293
 
        elif kind[1] is not None:
294
 
            path += self.kind_marker(kind[1])
295
 
        if exe_change:
296
 
            exe = '*'
297
 
        else:
298
 
            exe = ' '
299
 
        self.output("%s%s%s %s%s", rename, self.modified_map[modified], exe,
300
 
                    old_path, path)
301
 
 
302
 
 
303
 
def report_changes(change_iterator, reporter):
304
 
    """Report the changes from a change iterator.
305
 
 
306
 
    This is essentially a translation from low-level to medium-level changes.
307
 
    Further processing may be required to produce a human-readable output.
308
 
    Unfortunately, some tree-changing operations are very complex
309
 
    :change_iterator: an iterator or sequence of changes in the format
310
 
        generated by Tree.iter_changes
311
 
    :param reporter: The _ChangeReporter that will report the changes.
312
 
    """
313
 
    versioned_change_map = {
314
 
        (True, True): 'unchanged',
315
 
        (True, False): 'removed',
316
 
        (False, True): 'added',
317
 
        (False, False): 'unversioned',
318
 
        }
319
 
 
320
 
    def path_key(change):
321
 
        if change.path[0] is not None:
322
 
            path = change.path[0]
323
 
        else:
324
 
            path = change.path[1]
325
 
        return osutils.splitpath(path)
326
 
    for change in sorted(change_iterator, key=path_key):
327
 
        exe_change = False
328
 
        # files are "renamed" if they are moved or if name changes, as long
329
 
        # as it had a value
330
 
        if None not in change.name and None not in change.parent_id and\
331
 
                (change.name[0] != change.name[1] or change.parent_id[0] != change.parent_id[1]):
332
 
            if change.copied:
333
 
                copied = True
334
 
                renamed = False
335
 
            else:
336
 
                renamed = True
337
 
                copied = False
338
 
        else:
339
 
            copied = False
340
 
            renamed = False
341
 
        if change.kind[0] != change.kind[1]:
342
 
            if change.kind[0] is None:
343
 
                modified = "created"
344
 
            elif change.kind[1] is None:
345
 
                modified = "deleted"
346
 
            else:
347
 
                modified = "kind changed"
348
 
        else:
349
 
            if change.changed_content:
350
 
                modified = "modified"
351
 
            elif change.kind[0] is None:
352
 
                modified = "missing"
353
 
            else:
354
 
                modified = "unchanged"
355
 
            if change.kind[1] == "file":
356
 
                exe_change = (change.executable[0] != change.executable[1])
357
 
        versioned_change = versioned_change_map[change.versioned]
358
 
        reporter.report(change.path, versioned_change, renamed, copied, modified,
359
 
                        exe_change, change.kind)
360
 
 
361
 
 
362
 
def report_delta(to_file, delta, short_status=False, show_ids=False,
363
 
                 show_unchanged=False, indent='', predicate=None, classify=True):
364
 
    """Output this delta in status-like form to to_file.
365
 
 
366
 
    :param to_file: A file-like object where the output is displayed.
367
 
 
368
 
    :param delta: A TreeDelta containing the changes to be displayed
369
 
 
370
 
    :param short_status: Single-line status if True.
371
 
 
372
 
    :param show_ids: Output the file ids if True.
373
 
 
374
 
    :param show_unchanged: Output the unchanged files if True.
375
 
 
376
 
    :param indent: Added at the beginning of all output lines (for merged
377
 
        revisions).
378
 
 
379
 
    :param predicate: A callable receiving a path returning True if the path
380
 
        should be displayed.
381
 
 
382
 
    :param classify: Add special symbols to indicate file kind.
383
 
    """
384
 
 
385
 
    def decorate_path(path, kind, meta_modified=None):
386
 
        if not classify:
387
 
            return path
388
 
        if kind == 'directory':
389
 
            path += '/'
390
 
        elif kind == 'symlink':
391
 
            path += '@'
392
 
        if meta_modified:
393
 
            path += '*'
394
 
        return path
395
 
 
396
 
    def show_more_renamed(item):
397
 
        dec_new_path = decorate_path(item.path[1], item.kind[1], item.meta_modified())
398
 
        to_file.write(' => %s' % dec_new_path)
399
 
        if item.changed_content or item.meta_modified():
400
 
            extra_modified.append(TreeChange(
401
 
                item.file_id, (item.path[1], item.path[1]),
402
 
                item.changed_content,
403
 
                item.versioned,
404
 
                (item.parent_id[1], item.parent_id[1]),
405
 
                (item.name[1], item.name[1]),
406
 
                (item.kind[1], item.kind[1]),
407
 
                item.executable))
408
 
 
409
 
    def show_more_kind_changed(item):
410
 
        to_file.write(' (%s => %s)' % (item.kind[0], item.kind[1]))
411
 
 
412
 
    def show_path(path, kind, meta_modified,
413
 
                  default_format, with_file_id_format):
414
 
        dec_path = decorate_path(path, kind, meta_modified)
415
 
        if show_ids:
416
 
            to_file.write(with_file_id_format % dec_path)
417
 
        else:
418
 
            to_file.write(default_format % dec_path)
419
 
 
420
 
    def show_list(files, long_status_name, short_status_letter,
421
 
                  default_format='%s', with_file_id_format='%-30s',
422
 
                  show_more=None):
423
 
        if files:
424
 
            header_shown = False
425
 
            if short_status:
426
 
                prefix = short_status_letter
427
 
            else:
428
 
                prefix = ''
429
 
            prefix = indent + prefix + '  '
430
 
 
431
 
            for item in files:
432
 
                if item.path[0] is None:
433
 
                    path = item.path[1]
434
 
                    kind = item.kind[1]
435
 
                else:
436
 
                    path = item.path[0]
437
 
                    kind = item.kind[0]
438
 
                if predicate is not None and not predicate(path):
439
 
                    continue
440
 
                if not header_shown and not short_status:
441
 
                    to_file.write(indent + long_status_name + ':\n')
442
 
                    header_shown = True
443
 
                to_file.write(prefix)
444
 
                show_path(path, kind, item.meta_modified(),
445
 
                          default_format, with_file_id_format)
446
 
                if show_more is not None:
447
 
                    show_more(item)
448
 
                if show_ids and getattr(item, 'file_id', None):
449
 
                    to_file.write(' %s' % item.file_id.decode('utf-8'))
450
 
                to_file.write('\n')
451
 
 
452
 
    show_list(delta.removed, 'removed', 'D')
453
 
    show_list(delta.added, 'added', 'A')
454
 
    show_list(delta.missing, 'missing', '!')
455
 
    extra_modified = []
456
 
    show_list(delta.renamed, 'renamed', 'R', with_file_id_format='%s',
457
 
              show_more=show_more_renamed)
458
 
    show_list(delta.copied, 'copied', 'C', with_file_id_format='%s',
459
 
              show_more=show_more_renamed)
460
 
    show_list(delta.kind_changed, 'kind changed', 'K',
461
 
              with_file_id_format='%s',
462
 
              show_more=show_more_kind_changed)
463
 
    show_list(delta.modified + extra_modified, 'modified', 'M')
464
 
    if show_unchanged:
465
 
        show_list(delta.unchanged, 'unchanged', 'S')
466
 
 
467
 
    show_list(delta.unversioned, 'unknown', ' ')