mercurial/patch.py
changeset 3372 fd43ff3b4442
parent 3367 7f486971d263
child 3376 1106e00e6847
equal deleted inserted replaced
3371:9851f46d6ecc 3372:fd43ff3b4442
   189     return (dopatch, gitpatches)
   189     return (dopatch, gitpatches)
   190 
   190 
   191 def dogitpatch(patchname, gitpatches, cwd=None):
   191 def dogitpatch(patchname, gitpatches, cwd=None):
   192     """Preprocess git patch so that vanilla patch can handle it"""
   192     """Preprocess git patch so that vanilla patch can handle it"""
   193     def extractbin(fp):
   193     def extractbin(fp):
   194         line = fp.readline()
   194         line = fp.readline().rstrip()
   195         while line and not line.startswith('literal '):
   195         while line and not line.startswith('literal '):
   196             line = fp.readline()
   196             line = fp.readline().rstrip()
   197         if not line:
   197         if not line:
   198             return
   198             return
   199         size = int(line[8:].rstrip())
   199         size = int(line[8:])
   200         dec = []
   200         dec = []
   201         line = fp.readline()
   201         line = fp.readline().rstrip()
   202         while line:
   202         while line:
   203             line = line[1:-1]
   203             l = line[0]
   204             dec.append(base85.b85decode(line))
   204             if l <= 'Z' and l >= 'A':
   205             line = fp.readline()
   205                 l = ord(l) - ord('A') + 1
       
   206             else:
       
   207                 l = ord(l) - ord('a') + 27
       
   208             dec.append(base85.b85decode(line[1:])[:l])
       
   209             line = fp.readline().rstrip()
   206         text = zlib.decompress(''.join(dec))
   210         text = zlib.decompress(''.join(dec))
   207         if len(text) != size:
   211         if len(text) != size:
   208             raise util.Abort(_('binary patch is %d bytes, not %d') %
   212             raise util.Abort(_('binary patch is %d bytes, not %d') %
   209                              (len(text), size))
   213                              (len(text), size))
   210         return text
   214         return text