##// END OF EJS Templates
diff: move b85diff to mdiff module...
Guillermo Pérez <bisho at fb.com> -
r17939:d5879256 default
parent child Browse files
Show More
@@ -7,7 +7,8 b''
7
7
8 from i18n import _
8 from i18n import _
9 import bdiff, mpatch, util
9 import bdiff, mpatch, util
10 import re, struct
10 import re, struct, base85, zlib
11 from node import hex, nullid
11
12
12 def splitnewlines(text):
13 def splitnewlines(text):
13 '''like str.splitlines, but only split on newlines.'''
14 '''like str.splitlines, but only split on newlines.'''
@@ -314,6 +315,44 b' def _unidiff(t1, t2, l1, l2, opts=defaul'
314 for x in yieldhunk(hunk):
315 for x in yieldhunk(hunk):
315 yield x
316 yield x
316
317
318 def b85diff(to, tn):
319 '''print base85-encoded binary diff'''
320 def gitindex(text):
321 if not text:
322 return hex(nullid)
323 l = len(text)
324 s = util.sha1('blob %d\0' % l)
325 s.update(text)
326 return s.hexdigest()
327
328 def fmtline(line):
329 l = len(line)
330 if l <= 26:
331 l = chr(ord('A') + l - 1)
332 else:
333 l = chr(l - 26 + ord('a') - 1)
334 return '%c%s\n' % (l, base85.b85encode(line, True))
335
336 def chunk(text, csize=52):
337 l = len(text)
338 i = 0
339 while i < l:
340 yield text[i:i + csize]
341 i += csize
342
343 tohash = gitindex(to)
344 tnhash = gitindex(tn)
345 if tohash == tnhash:
346 return ""
347
348 # TODO: deltas
349 ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' %
350 (tohash, tnhash, len(tn))]
351 for l in chunk(zlib.compress(tn)):
352 ret.append(fmtline(l))
353 ret.append('\n')
354 return ''.join(ret)
355
317 def patchtext(bin):
356 def patchtext(bin):
318 pos = 0
357 pos = 0
319 t = []
358 t = []
@@ -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, nullid, short
13 from node import hex, 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
@@ -1514,44 +1514,6 b' def changedfiles(ui, repo, patchpath, st'
1514 finally:
1514 finally:
1515 fp.close()
1515 fp.close()
1516
1516
1517 def b85diff(to, tn):
1518 '''print base85-encoded binary diff'''
1519 def gitindex(text):
1520 if not text:
1521 return hex(nullid)
1522 l = len(text)
1523 s = util.sha1('blob %d\0' % l)
1524 s.update(text)
1525 return s.hexdigest()
1526
1527 def fmtline(line):
1528 l = len(line)
1529 if l <= 26:
1530 l = chr(ord('A') + l - 1)
1531 else:
1532 l = chr(l - 26 + ord('a') - 1)
1533 return '%c%s\n' % (l, base85.b85encode(line, True))
1534
1535 def chunk(text, csize=52):
1536 l = len(text)
1537 i = 0
1538 while i < l:
1539 yield text[i:i + csize]
1540 i += csize
1541
1542 tohash = gitindex(to)
1543 tnhash = gitindex(tn)
1544 if tohash == tnhash:
1545 return ""
1546
1547 # TODO: deltas
1548 ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' %
1549 (tohash, tnhash, len(tn))]
1550 for l in chunk(zlib.compress(tn)):
1551 ret.append(fmtline(l))
1552 ret.append('\n')
1553 return ''.join(ret)
1554
1555 class GitDiffRequired(Exception):
1517 class GitDiffRequired(Exception):
1556 pass
1518 pass
1557
1519
@@ -1789,7 +1751,7 b' def trydiff(repo, revs, ctx1, ctx2, modi'
1789
1751
1790 if dodiff:
1752 if dodiff:
1791 if dodiff == 'binary':
1753 if dodiff == 'binary':
1792 text = b85diff(to, tn)
1754 text = mdiff.b85diff(to, tn)
1793 else:
1755 else:
1794 text = mdiff.unidiff(to, date1,
1756 text = mdiff.unidiff(to, date1,
1795 # ctx2 date may be dynamic
1757 # ctx2 date may be dynamic
General Comments 0
You need to be logged in to leave comments. Login now