mercurial/patch.py
changeset 34066 871a58b5f428
parent 34042 c0170d88ed2b
child 34067 8b8b70cb4288
equal deleted inserted replaced
34065:c6c8a52e28c9 34066:871a58b5f428
   203     Any item can be missing from the dictionary. If filename is missing,
   203     Any item can be missing from the dictionary. If filename is missing,
   204     fileobj did not contain a patch. Caller must unlink filename when done.'''
   204     fileobj did not contain a patch. Caller must unlink filename when done.'''
   205 
   205 
   206     # attempt to detect the start of a patch
   206     # attempt to detect the start of a patch
   207     # (this heuristic is borrowed from quilt)
   207     # (this heuristic is borrowed from quilt)
   208     diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |'
   208     diffre = re.compile(br'^(?:Index:[ \t]|diff[ \t]|RCS file: |'
   209                         r'retrieving revision [0-9]+(\.[0-9]+)*$|'
   209                         br'retrieving revision [0-9]+(\.[0-9]+)*$|'
   210                         r'---[ \t].*?^\+\+\+[ \t]|'
   210                         br'---[ \t].*?^\+\+\+[ \t]|'
   211                         r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
   211                         br'\*\*\*[ \t].*?^---[ \t])',
       
   212                         re.MULTILINE | re.DOTALL)
   212 
   213 
   213     data = {}
   214     data = {}
   214     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   215     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   215     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   216     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   216     try:
   217     try:
   228         if subject:
   229         if subject:
   229             if subject.startswith('[PATCH'):
   230             if subject.startswith('[PATCH'):
   230                 pend = subject.find(']')
   231                 pend = subject.find(']')
   231                 if pend >= 0:
   232                 if pend >= 0:
   232                     subject = subject[pend + 1:].lstrip()
   233                     subject = subject[pend + 1:].lstrip()
   233             subject = re.sub(r'\n[ \t]+', ' ', subject)
   234             subject = re.sub(br'\n[ \t]+', ' ', subject)
   234             ui.debug('Subject: %s\n' % subject)
   235             ui.debug('Subject: %s\n' % subject)
   235         if data['user']:
   236         if data['user']:
   236             ui.debug('From: %s\n' % data['user'])
   237             ui.debug('From: %s\n' % data['user'])
   237         diffs_seen = 0
   238         diffs_seen = 0
   238         ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   239         ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
  1758     - ('file',    [header_lines + fromfile + tofile])
  1759     - ('file',    [header_lines + fromfile + tofile])
  1759     - ('context', [context_lines])
  1760     - ('context', [context_lines])
  1760     - ('hunk',    [hunk_lines])
  1761     - ('hunk',    [hunk_lines])
  1761     - ('range',   (-start,len, +start,len, proc))
  1762     - ('range',   (-start,len, +start,len, proc))
  1762     """
  1763     """
  1763     lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)')
  1764     lines_re = re.compile(br'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)')
  1764     lr = linereader(fp)
  1765     lr = linereader(fp)
  1765 
  1766 
  1766     def scanwhile(first, p):
  1767     def scanwhile(first, p):
  1767         """scan lr while predicate holds"""
  1768         """scan lr while predicate holds"""
  1768         lines = [first]
  1769         lines = [first]