~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2005-07-11 06:34:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050711063455-0f0b87a770873373
todo

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from errors import BzrError
20
20
 
21
21
 
 
22
# TODO: Rather than building a changeset object, we should probably
 
23
# invoke callbacks on an object.  That object can either accumulate a
 
24
# list, write them out directly, etc etc.
 
25
 
22
26
def internal_diff(old_label, oldlines, new_label, newlines, to_file):
23
27
    import difflib
24
28
    
59
63
        ud = list(ud)
60
64
        ud[2] = ud[2].replace('+1,0', '+0,0')
61
65
 
62
 
    to_file.writelines(ud)
 
66
    for line in ud:
 
67
        to_file.write(line)
63
68
    if nonl:
64
69
        print >>to_file, "\\ No newline at end of file"
65
70
    print >>to_file
267
272
    Files that are both modified and renamed are listed only in
268
273
    renamed, with the text_modified flag true.
269
274
 
 
275
    Files are only considered renamed if their name has changed or
 
276
    their parent directory has changed.  Renaming a directory
 
277
    does not count as renaming all its contents.
 
278
 
270
279
    The lists are normally sorted when the delta is created.
271
280
    """
272
281
    def __init__(self):
276
285
        self.modified = []
277
286
        self.unchanged = []
278
287
 
 
288
    def __eq__(self, other):
 
289
        if not isinstance(other, TreeDelta):
 
290
            return False
 
291
        return self.added == other.added \
 
292
               and self.removed == other.removed \
 
293
               and self.renamed == other.renamed \
 
294
               and self.modified == other.modified \
 
295
               and self.unchanged == other.unchanged
 
296
 
 
297
    def __ne__(self, other):
 
298
        return not (self == other)
 
299
 
279
300
    def __repr__(self):
280
301
        return "TreeDelta(added=%r, removed=%r, renamed=%r, modified=%r," \
281
302
            " unchanged=%r)" % (self.added, self.removed, self.renamed,
337
358
 
338
359
 
339
360
 
340
 
def compare_trees(old_tree, new_tree, want_unchanged, specific_files=None):
 
361
def compare_trees(old_tree, new_tree, want_unchanged=False, specific_files=None):
341
362
    """Describe changes from one tree to another.
342
363
 
343
364
    Returns a TreeDelta with details of added, modified, renamed, and
380
401
            old_path = old_inv.id2path(file_id)
381
402
            new_path = new_inv.id2path(file_id)
382
403
 
 
404
            old_ie = old_inv[file_id]
 
405
            new_ie = new_inv[file_id]
 
406
 
383
407
            if specific_files:
384
408
                if (not is_inside_any(specific_files, old_path) 
385
409
                    and not is_inside_any(specific_files, new_path)):
398
422
            # the same and the parents are unchanged all the way up.
399
423
            # May not be worthwhile.
400
424
            
401
 
            if old_path != new_path:
 
425
            if (old_ie.name != new_ie.name
 
426
                or old_ie.parent_id != new_ie.parent_id):
402
427
                delta.renamed.append((old_path, new_path, file_id, kind,
403
428
                                      text_modified))
404
429
            elif text_modified: