# HG changeset patch # User Alexis S. L. Carvalho # Date 1171713300 7200 # Node ID 797dbdd4d7e107b2ad62fe9f29d7507c6c967d56 # Parent ed46895aa38c95c0ce3d785b65242f0006f6c318 git binary patches: don't print the header for identical files diff -r ed46895aa38c -r 797dbdd4d7e1 mercurial/patch.py --- a/mercurial/patch.py Sat Feb 17 09:54:59 2007 -0200 +++ b/mercurial/patch.py Sat Feb 17 09:55:00 2007 -0200 @@ -415,14 +415,15 @@ tohash = gitindex(to) tnhash = gitindex(tn) if tohash == tnhash: - return + return "" + # TODO: deltas - fp.write('index %s..%s\nGIT binary patch\nliteral %s\n' % - (tohash, tnhash, len(tn))) - - tn = ''.join([fmtline(l) for l in chunk(zlib.compress(tn))]) - fp.write(tn) - fp.write('\n') + ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' % + (tohash, tnhash, len(tn))] + for l in chunk(zlib.compress(tn)): + ret.append(fmtline(l)) + ret.append('\n') + return ''.join(ret) def diff(repo, node1=None, node2=None, files=None, match=util.always, fp=None, changes=None, opts=None): @@ -615,11 +616,11 @@ dodiff = 'binary' r = None header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) - if dodiff == 'binary': - fp.write(''.join(header)) - b85diff(fp, to, tn) - elif dodiff: - text = mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts) + if dodiff: + if dodiff == 'binary': + text = b85diff(fp, to, tn) + else: + text = mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts) if text or len(header) > 1: fp.write(''.join(header)) fp.write(text) diff -r ed46895aa38c -r 797dbdd4d7e1 tests/test-diff-binary-file.out --- a/tests/test-diff-binary-file.out Sat Feb 17 09:54:59 2007 -0200 +++ b/tests/test-diff-binary-file.out Sat Feb 17 09:55:00 2007 -0200 @@ -21,4 +21,3 @@ gQItJW-{SoTm)8|5##k|m00000NkvXXu0mjf3JwksH2?qr % diff --git -r 0 -r 2 -diff --git a/binfile.bin b/binfile.bin