Show More
@@ -8,7 +8,6 b'' | |||
|
8 | 8 | from i18n import _ |
|
9 | 9 | import bdiff, mpatch, util |
|
10 | 10 | import re, struct, base85, zlib |
|
11 | from node import hex, nullid | |
|
12 | 11 | |
|
13 | 12 | def splitnewlines(text): |
|
14 | 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 | 301 | def b85diff(to, tn): |
|
303 | 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 | 303 | def fmtline(line): |
|
313 | 304 | l = len(line) |
|
314 | 305 | if l <= 26: |
@@ -324,17 +315,22 b' def b85diff(to, tn):' | |||
|
324 | 315 | yield text[i:i + csize] |
|
325 | 316 | i += csize |
|
326 | 317 | |
|
327 | tohash = gitindex(to) | |
|
328 | tnhash = gitindex(tn) | |
|
329 | if tohash == tnhash: | |
|
330 |
|
|
|
318 | if to is None: | |
|
319 | to = '' | |
|
320 | if tn is None: | |
|
321 | tn = '' | |
|
322 | ||
|
323 | if to == tn: | |
|
324 | return '' | |
|
331 | 325 | |
|
332 | 326 | # TODO: deltas |
|
333 | ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' % | |
|
334 | (tohash, tnhash, len(tn))] | |
|
327 | ret = [] | |
|
328 | ret.append('GIT binary patch\n') | |
|
329 | ret.append('literal %s\n' % len(tn)) | |
|
335 | 330 | for l in chunk(zlib.compress(tn)): |
|
336 | 331 | ret.append(fmtline(l)) |
|
337 | 332 | ret.append('\n') |
|
333 | ||
|
338 | 334 | return ''.join(ret) |
|
339 | 335 | |
|
340 | 336 | def patchtext(bin): |
@@ -10,7 +10,7 b' import cStringIO, email.Parser, os, errn' | |||
|
10 | 10 | import tempfile, zlib, shutil |
|
11 | 11 | |
|
12 | 12 | from i18n import _ |
|
13 | from node import hex, short | |
|
13 | from node import hex, nullid, short | |
|
14 | 14 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error |
|
15 | 15 | import context |
|
16 | 16 | |
@@ -1662,6 +1662,22 b' def trydiff(repo, revs, ctx1, ctx2, modi' | |||
|
1662 | 1662 | header.append('old mode %s\n' % omode) |
|
1663 | 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 | 1681 | def diffline(a, b, revs): |
|
1666 | 1682 | if opts.git: |
|
1667 | 1683 | line = 'diff --git a/%s b/%s\n' % (a, b) |
@@ -1763,6 +1779,8 b' def trydiff(repo, revs, ctx1, ctx2, modi' | |||
|
1763 | 1779 | header.insert(0, diffline(join(a), join(b), revs)) |
|
1764 | 1780 | if dodiff == 'binary': |
|
1765 | 1781 | text = mdiff.b85diff(to, tn) |
|
1782 | if text: | |
|
1783 | addindexmeta(header, [gitindex(to), gitindex(tn)]) | |
|
1766 | 1784 | else: |
|
1767 | 1785 | text = mdiff.unidiff(to, date1, |
|
1768 | 1786 | # ctx2 date may be dynamic |
General Comments 0
You need to be logged in to leave comments.
Login now