~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Robert Collins
  • Date: 2006-03-13 11:03:44 UTC
  • mto: (1615.1.2 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: robertc@robertcollins.net-20060313110344-f82a10b55cba1f99
Switch to delta based content copying in the generic versioned file copier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
277
277
        current_hunk = [0, 0, 0, []] #start, finish, repl_length, repl_tuples
278
278
        inclusions = set(self.get_ancestry(version_id))
279
279
        parent_linenum = 0
 
280
        noeol = False
 
281
        parent_noeol = False
 
282
        last_parent_line = ''
280
283
        for lineno, inserted, deletes, line in self._walk_internal(inclusions):
281
284
            parent_active = inserted in parent_inclusions and not (deletes & parent_inclusions)
282
285
            version_active = inserted in inclusions and not (deletes & inclusions)
289
292
                    diff_hunks.append(tuple(current_hunk))
290
293
                parent_linenum += 1
291
294
                current_hunk = [parent_linenum, parent_linenum, 0, []]
 
295
                if len(line) and line[-1] != '\n':
 
296
                    noeol = True
292
297
            elif parent_active and not version_active:
293
298
                # deleted line
294
299
                current_hunk[1] += 1
295
300
                parent_linenum += 1
 
301
                last_parent_line = line
296
302
            elif not parent_active and version_active:
297
303
                # replacement line
298
 
                current_hunk[2] += 1
299
 
                current_hunk[3].append((inserted, line))
 
304
                # noeol only occurs at the end of a file because we 
 
305
                # diff linewise. We want to show noeol changes as a
 
306
                # empty diff unless the actual eol-less content changed.
 
307
                if len(last_parent_line) and last_parent_line[-1] != '\n':
 
308
                    parent_noeol = True
 
309
                if len(line) and line[-1] != '\n':
 
310
                    noeol = True
 
311
                changed = False
 
312
                if parent_noeol == noeol:
 
313
                    # no noeol toggle, so trust the weave
 
314
                    changed = True
 
315
                elif parent_noeol:
 
316
                    # parent is shorter:
 
317
                    if last_parent_line != line[:-1]:
 
318
                        # but changed anyway
 
319
                        changed = True
 
320
                elif noeol:
 
321
                    # append a eol so that it looks like
 
322
                    # a normalised delta
 
323
                    line = line + '\n'
 
324
                    # we are shorter:
 
325
                    if last_parent_line != line:
 
326
                        # but changed anyway
 
327
                        changed = True
 
328
                if changed:
 
329
                    current_hunk[2] += 1
 
330
                    current_hunk[3].append((inserted, line))
 
331
                else:
 
332
                    # last hunk last parent line is not eaten
 
333
                    current_hunk[1] -= 1
300
334
        # flush last hunk
301
335
        if current_hunk != [0, 0, 0, []]:
302
336
            diff_hunks.append(tuple(current_hunk))
303
 
        return parent, sha1, diff_hunks
 
337
        return parent, sha1, noeol, diff_hunks
304
338
    
305
339
    def get_parents(self, version_id):
306
340
        """See VersionedFile.get_parent."""