Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9.2, 1.9.3, and 2.0

fileview: use mdiff.unidiff to generate unified diffs

1 - This is Mercurial's function, it supports all [diff] options
2 - Does not require splitting input buffers, output buffer is not split
3 - Is EOL clean
4 - Removes some ugly hacks in chunks.py

Changeset 68584afb2fd3

Parent 82cbddf70525

by Steve Borho

Changes to 2 files · Browse files at 68584afb2fd3 Showing diff from parent 82cbddf70525 Diff from another changeset...

 
567
568
569
570
571
 
572
573
574
 
567
568
569
 
 
570
571
572
573
@@ -567,8 +567,7 @@
  chunks = self._ctx._files[filename]   else:   buf = cStringIO.StringIO() - buf.write('diff -r aaaaaaaaaaaa -r bbbbbbbbbbb %s\n' % filename) - buf.write('\n'.join(fd.diff)) + buf.write(fd.diff)   buf.seek(0)   chunks = record.parsepatch(buf)  
 
22
23
24
25
 
26
27
28
 
330
331
332
333
334
 
 
 
 
 
 
335
336
337
 
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
 
 
 
 
 
 
 
 
22
23
24
 
25
26
27
28
 
330
331
332
 
 
333
334
335
336
337
338
339
340
341
 
704
705
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
708
709
710
711
712
713
@@ -22,7 +22,7 @@
 import re    from mercurial import hg, error, match, patch, subrepo, commands, util -from mercurial import ui as uimod +from mercurial import ui as uimod, mdiff    from PyQt4.QtCore import *  from PyQt4.QtGui import * @@ -330,8 +330,12 @@
  if self._mode == 'diff' and fd.diff:   lexer = get_diff_lexer(self)   self.sci.setLexer(lexer) - utext = [hglib.tounicode(l) for l in fd.diff[2:]] - self.sci.setText(u'\n'.join(utext)) + # trim first three lines, for example: + # diff -r f6bfc41af6d7 -r c1b18806486d tortoisehg/hgqt/thgrepo.py + # --- a/tortoisehg/hgqt/thgrepo.py + # +++ b/tortoisehg/hgqt/thgrepo.py + noheader = fd.diff.split('\n', 3)[3] + self.sci.setText(hglib.tounicode(noheader))   elif fd.contents is None:   return   else: @@ -700,20 +704,10 @@
  return     self.olddata = olddata - olddata = olddata.splitlines() - newdata = newdata.splitlines() - gen = difflib.unified_diff(olddata, newdata, 'a/'+oldname, 'b/'+wfile, - lineterm='') - data = [] - if repo.ui.config('diff', 'showfunc'): - for chunkline in gen: - chunkhdr = chunkhdrre.match(chunkline) - if chunkhdr: - func = hglib.getchunkfunction(olddata, chunkhdr.group(1)) - if func: - chunkline += func - data.append(chunkline) - else: - for chunkline in gen: - data.append(chunkline) - self.diff = data + newdate = util.datestr(ctx.date()) + olddate = util.datestr(ctx2.date()) + revs = [str(ctx), str(ctx2)] + diffopts = patch.diffopts(repo.ui, {}) + diffopts.git = False + self.diff = mdiff.unidiff(olddata, olddate, newdata, newdate, + oldname, wfile, revs, diffopts)