Show More
@@ -8,7 +8,6 b'' | |||||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import bdiff, mpatch, util |
|
9 | import bdiff, mpatch, util | |
10 | import re, struct, base85, zlib |
|
10 | import re, struct, base85, zlib | |
11 | from node import hex, nullid |
|
|||
12 |
|
11 | |||
13 | def splitnewlines(text): |
|
12 | def splitnewlines(text): | |
14 | '''like str.splitlines, but only split on newlines.''' |
|
13 | '''like str.splitlines, but only split on newlines.''' | |
@@ -301,14 +300,6 b' def _unidiff(t1, t2, l1, l2, opts=defaul' | |||||
301 |
|
300 | |||
302 | def b85diff(to, tn): |
|
301 | def b85diff(to, tn): | |
303 | '''print base85-encoded binary diff''' |
|
302 | '''print base85-encoded binary diff''' | |
304 | def gitindex(text): |
|
|||
305 | if not text: |
|
|||
306 | return hex(nullid) |
|
|||
307 | l = len(text) |
|
|||
308 | s = util.sha1('blob %d\0' % l) |
|
|||
309 | s.update(text) |
|
|||
310 | return s.hexdigest() |
|
|||
311 |
|
||||
312 | def fmtline(line): |
|
303 | def fmtline(line): | |
313 | l = len(line) |
|
304 | l = len(line) | |
314 | if l <= 26: |
|
305 | if l <= 26: | |
@@ -324,17 +315,22 b' def b85diff(to, tn):' | |||||
324 | yield text[i:i + csize] |
|
315 | yield text[i:i + csize] | |
325 | i += csize |
|
316 | i += csize | |
326 |
|
317 | |||
327 | tohash = gitindex(to) |
|
318 | if to is None: | |
328 | tnhash = gitindex(tn) |
|
319 | to = '' | |
329 | if tohash == tnhash: |
|
320 | if tn is None: | |
330 |
|
|
321 | tn = '' | |
|
322 | ||||
|
323 | if to == tn: | |||
|
324 | return '' | |||
331 |
|
325 | |||
332 | # TODO: deltas |
|
326 | # TODO: deltas | |
333 | ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' % |
|
327 | ret = [] | |
334 | (tohash, tnhash, len(tn))] |
|
328 | ret.append('GIT binary patch\n') | |
|
329 | ret.append('literal %s\n' % len(tn)) | |||
335 | for l in chunk(zlib.compress(tn)): |
|
330 | for l in chunk(zlib.compress(tn)): | |
336 | ret.append(fmtline(l)) |
|
331 | ret.append(fmtline(l)) | |
337 | ret.append('\n') |
|
332 | ret.append('\n') | |
|
333 | ||||
338 | return ''.join(ret) |
|
334 | return ''.join(ret) | |
339 |
|
335 | |||
340 | def patchtext(bin): |
|
336 | def patchtext(bin): |
@@ -10,7 +10,7 b' import cStringIO, email.Parser, os, errn' | |||||
10 | import tempfile, zlib, shutil |
|
10 | import tempfile, zlib, shutil | |
11 |
|
11 | |||
12 | from i18n import _ |
|
12 | from i18n import _ | |
13 | from node import hex, short |
|
13 | from node import hex, nullid, short | |
14 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error |
|
14 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error | |
15 | import context |
|
15 | import context | |
16 |
|
16 | |||
@@ -1662,6 +1662,22 b' def trydiff(repo, revs, ctx1, ctx2, modi' | |||||
1662 | header.append('old mode %s\n' % omode) |
|
1662 | header.append('old mode %s\n' % omode) | |
1663 | header.append('new mode %s\n' % nmode) |
|
1663 | header.append('new mode %s\n' % nmode) | |
1664 |
|
1664 | |||
|
1665 | def addindexmeta(meta, revs): | |||
|
1666 | if opts.git: | |||
|
1667 | i = len(revs) | |||
|
1668 | if i==2: | |||
|
1669 | meta.append('index %s..%s\n' % tuple(revs)) | |||
|
1670 | elif i==3: | |||
|
1671 | meta.append('index %s,%s..%s\n' % tuple(revs)) | |||
|
1672 | ||||
|
1673 | def gitindex(text): | |||
|
1674 | if not text: | |||
|
1675 | return hex(nullid) | |||
|
1676 | l = len(text) | |||
|
1677 | s = util.sha1('blob %d\0' % l) | |||
|
1678 | s.update(text) | |||
|
1679 | return s.hexdigest() | |||
|
1680 | ||||
1665 | def diffline(a, b, revs): |
|
1681 | def diffline(a, b, revs): | |
1666 | if opts.git: |
|
1682 | if opts.git: | |
1667 | line = 'diff --git a/%s b/%s\n' % (a, b) |
|
1683 | line = 'diff --git a/%s b/%s\n' % (a, b) | |
@@ -1763,6 +1779,8 b' def trydiff(repo, revs, ctx1, ctx2, modi' | |||||
1763 | header.insert(0, diffline(join(a), join(b), revs)) |
|
1779 | header.insert(0, diffline(join(a), join(b), revs)) | |
1764 | if dodiff == 'binary': |
|
1780 | if dodiff == 'binary': | |
1765 | text = mdiff.b85diff(to, tn) |
|
1781 | text = mdiff.b85diff(to, tn) | |
|
1782 | if text: | |||
|
1783 | addindexmeta(header, [gitindex(to), gitindex(tn)]) | |||
1766 | else: |
|
1784 | else: | |
1767 | text = mdiff.unidiff(to, date1, |
|
1785 | text = mdiff.unidiff(to, date1, | |
1768 | # ctx2 date may be dynamic |
|
1786 | # ctx2 date may be dynamic |
General Comments 0
You need to be logged in to leave comments.
Login now