/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

[merge] bzr.dev 2294

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
        self.added = []
57
57
        self.removed = []
58
58
        self.renamed = []
 
59
        self.kind_changed = []
59
60
        self.modified = []
60
61
        self.unchanged = []
61
62
 
66
67
               and self.removed == other.removed \
67
68
               and self.renamed == other.renamed \
68
69
               and self.modified == other.modified \
69
 
               and self.unchanged == other.unchanged
 
70
               and self.unchanged == other.unchanged \
 
71
               and self.kind_changed == other.kind_changed
70
72
 
71
73
    def __ne__(self, other):
72
74
        return not (self == other)
73
75
 
74
76
    def __repr__(self):
75
 
        return "TreeDelta(added=%r, removed=%r, renamed=%r, modified=%r," \
76
 
            " unchanged=%r)" % (self.added, self.removed, self.renamed,
77
 
            self.modified, self.unchanged)
 
77
        return "TreeDelta(added=%r, removed=%r, renamed=%r," \
 
78
            " kind_changed=%r, modified=%r, unchanged=%r)" % (self.added,
 
79
            self.removed, self.renamed, self.kind_changed, self.modified,
 
80
            self.unchanged)
78
81
 
79
82
    def has_changed(self):
80
83
        return bool(self.modified
81
84
                    or self.added
82
85
                    or self.removed
83
 
                    or self.renamed)
 
86
                    or self.renamed
 
87
                    or self.kind_changed)
84
88
 
85
89
    def touches_file_id(self, file_id):
86
90
        """Return True if file_id is modified by this delta."""
91
95
        for v in self.renamed:
92
96
            if v[2] == file_id:
93
97
                return True
 
98
        for v in self.kind_changed:
 
99
            if v[1] == file_id:
 
100
                return True
94
101
        return False
95
102
            
96
103
 
97
 
    def show(self, to_file, show_ids=False, show_unchanged=False, short_status=False):
 
104
    def show(self, to_file, show_ids=False, show_unchanged=False,
 
105
             short_status=False):
98
106
        """output this delta in status-like form to to_file."""
99
107
        def show_list(files, short_status_letter=''):
100
108
            for item in files:
109
117
                    path += '*'
110
118
 
111
119
                if show_ids:
112
 
                    print >>to_file, '%s  %-30s %s' % (short_status_letter, path, fid)
 
120
                    print >>to_file, '%s  %-30s %s' % (short_status_letter,
 
121
                        path, fid)
113
122
                else:
114
123
                    print >>to_file, '%s  %s' % (short_status_letter, path)
115
124
            
142
151
                if meta_modified:
143
152
                    newpath += '*'
144
153
                if show_ids:
145
 
                    print >>to_file, '%s  %s => %s %s' % (short_status_letter,
146
 
                                                          oldpath, newpath, fid)
147
 
                else:
148
 
                    print >>to_file, '%s  %s => %s' % (short_status_letter,
149
 
                                                       oldpath, newpath)
150
 
                    
 
154
                    print >>to_file, '%s  %s => %s %s' % (
 
155
                        short_status_letter, oldpath, newpath, fid)
 
156
                else:
 
157
                    print >>to_file, '%s  %s => %s' % (
 
158
                        short_status_letter, oldpath, newpath)
 
159
 
 
160
        if self.kind_changed:
 
161
            if short_status:
 
162
                short_status_letter = 'K'
 
163
            else:
 
164
                print >>to_file, 'kind changed:'
 
165
                short_status_letter = ''
 
166
            for (path, fid, old_kind, new_kind) in self.kind_changed:
 
167
                if show_ids:
 
168
                    suffix = ' '+fid
 
169
                else:
 
170
                    suffix = ''
 
171
                print >>to_file, '%s  %s (%s => %s)%s' % (
 
172
                    short_status_letter, path, old_kind, new_kind, suffix)
 
173
 
151
174
        if self.modified or extra_modified:
152
175
            short_status_letter = 'M'
153
176
            if not short_status:
187
210
                                               specific_file_ids):
188
211
        if not include_root and (None, None) == parent_id:
189
212
            continue
190
 
        assert kind[0] == kind[1] or None in kind
191
 
        # the only 'kind change' permitted is creation/deletion
192
213
        fully_present = tuple((versioned[x] and kind[x] is not None) for
193
214
                              x in range(2))
194
215
        if fully_present[0] != fully_present[1]:
211
232
                                  kind[1],
212
233
                                  content_change, 
213
234
                                  (executable[0] != executable[1])))
 
235
        elif kind[0] != kind[1]:
 
236
            delta.kind_changed.append((path, file_id, kind[0], kind[1]))
214
237
        elif content_change is True or executable[0] != executable[1]:
215
238
            delta.modified.append((path, file_id, kind[1],
216
239
                                   content_change, 
232
255
class ChangeReporter(object):
233
256
    """Report changes between two trees"""
234
257
 
235
 
    def __init__(self, old_inventory, output=None):
 
258
    def __init__(self, old_inventory, output=None, suppress_root_add=True,
 
259
                 output_file=None):
 
260
        """Constructor
 
261
 
 
262
        :param old_inventory: The inventory of the old tree
 
263
        :param output: a function with the signature of trace.note, i.e.
 
264
            accepts a format and parameters.
 
265
        :param supress_root_add: If true, adding the root will be ignored
 
266
            (i.e. when a tree has just been initted)
 
267
        :param output_file: If supplied, a file-like object to write to.
 
268
            Only one of output and output_file may be supplied.
 
269
        """
236
270
        self.old_inventory = old_inventory
 
271
        if output_file is not None:
 
272
            if output is not None:
 
273
                raise BzrError('Cannot specify both output and output_file')
 
274
            def output(fmt, *args):
 
275
                output_file.write((fmt % args) + '\n')
237
276
        self.output = output
238
277
        if self.output is None:
239
278
            from bzrlib import trace
240
279
            self.output = trace.note
 
280
        self.suppress_root_add = suppress_root_add
241
281
 
242
282
    def report(self, file_id, path, versioned, renamed, modified, exe_change,
243
283
               kind):
254
294
        :param kind: A pair of file kinds, as generated by Tree._iter_changes.
255
295
            None indicates no file present.
256
296
        """
 
297
        if path == '' and versioned == 'added' and self.suppress_root_add:
 
298
            return
257
299
        modified_map = {'kind changed': 'K',
258
300
                        'unchanged': ' ',
259
301
                        'created': 'N',
273
315
                old_path = path
274
316
        if modified == 'deleted':
275
317
            path += osutils.kind_marker(kind[0])
276
 
        else:
 
318
        elif kind[1] is not None:
277
319
            path += osutils.kind_marker(kind[1])
278
320
        if old_path != "":
279
 
            old_path += "%s => " % osutils.kind_marker(kind[0])
 
321
            if kind[0] is not None:
 
322
                old_path += osutils.kind_marker(kind[0])
 
323
            old_path += " => "
280
324
        if exe_change:
281
325
            exe = '*'
282
326
        else:
300
344
        exe_change = False
301
345
        # files are "renamed" if they are moved or if name changes, as long
302
346
        # as it had a value
303
 
        if None not in name and (name[0] != name[1] or
304
 
                                 parent_id[0] != parent_id[1]):
 
347
        if None not in name and None not in parent_id and\
 
348
            (name[0] != name[1] or parent_id[0] != parent_id[1]):
305
349
            renamed = True
306
350
        else:
307
351
            renamed = False