mercurial/mdiff.py
changeset 4103 544838cc1158
parent 3199 096f1c73cdc3
child 4108 226df1808f16
equal deleted inserted replaced
4095:6fa7a2d0fc2e 4103:544838cc1158
     5 # This software may be used and distributed according to the terms
     5 # This software may be used and distributed according to the terms
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from demandload import demandload
     8 from demandload import demandload
     9 import bdiff, mpatch
     9 import bdiff, mpatch
    10 demandload(globals(), "re struct util")
    10 demandload(globals(), "re struct util md5")
    11 
    11 
    12 def splitnewlines(text):
    12 def splitnewlines(text):
    13     '''like str.splitlines, but only split on newlines.'''
    13     '''like str.splitlines, but only split on newlines.'''
    14     lines = [l + '\n' for l in text.split('\n')]
    14     lines = [l + '\n' for l in text.split('\n')]
    15     if lines:
    15     if lines:
    57 
    57 
    58     if not a and not b: return ""
    58     if not a and not b: return ""
    59     epoch = util.datestr((0, 0))
    59     epoch = util.datestr((0, 0))
    60 
    60 
    61     if not opts.text and (util.binary(a) or util.binary(b)):
    61     if not opts.text and (util.binary(a) or util.binary(b)):
       
    62         def h(v):
       
    63             # md5 is used instead of sha1 because md5 is supposedly faster
       
    64             return md5.new(v).digest()
       
    65         if a and b and len(a) == len(b) and h(a) == h(b):
       
    66             return ""
    62         l = ['Binary file %s has changed\n' % fn]
    67         l = ['Binary file %s has changed\n' % fn]
    63     elif not a:
    68     elif not a:
    64         b = splitnewlines(b)
    69         b = splitnewlines(b)
    65         if a is None:
    70         if a is None:
    66             l1 = '--- /dev/null%s' % datetag(epoch)
    71             l1 = '--- /dev/null%s' % datetag(epoch)