diff mercurial/mdiff.py @ 17946:1e13b1184292

diff: move index header generation to patch In an upcoming patch, we will add index information to all git diffs, not only binary diffs, so this code needs to be moved to a more appropriate place. Also, since this information is used for patch headers, it makes more sense to be in the patch module, along with other patch-related metadata.
author Guillermo Pérez <bisho@fb.com>
date Thu, 15 Nov 2012 15:16:41 -0800
parents 9a6e4d5d7ea8
children 1e5b38a919dd
line wrap: on
line diff
--- a/mercurial/mdiff.py	Thu Nov 15 15:06:32 2012 -0800
+++ b/mercurial/mdiff.py	Thu Nov 15 15:16:41 2012 -0800
@@ -8,7 +8,6 @@
 from i18n import _
 import bdiff, mpatch, util
 import re, struct, base85, zlib
-from node import hex, nullid
 
 def splitnewlines(text):
     '''like str.splitlines, but only split on newlines.'''
@@ -301,14 +300,6 @@
 
 def b85diff(to, tn):
     '''print base85-encoded binary diff'''
-    def gitindex(text):
-        if not text:
-            return hex(nullid)
-        l = len(text)
-        s = util.sha1('blob %d\0' % l)
-        s.update(text)
-        return s.hexdigest()
-
     def fmtline(line):
         l = len(line)
         if l <= 26:
@@ -324,17 +315,22 @@
             yield text[i:i + csize]
             i += csize
 
-    tohash = gitindex(to)
-    tnhash = gitindex(tn)
-    if tohash == tnhash:
-        return ""
+    if to is None:
+        to = ''
+    if tn is None:
+        tn = ''
+
+    if to == tn:
+        return ''
 
     # TODO: deltas
-    ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' %
-           (tohash, tnhash, len(tn))]
+    ret = []
+    ret.append('GIT binary patch\n')
+    ret.append('literal %s\n' % len(tn))
     for l in chunk(zlib.compress(tn)):
         ret.append(fmtline(l))
     ret.append('\n')
+
     return ''.join(ret)
 
 def patchtext(bin):