mercurial/patch.py
changeset 36045 04984f2e50ae
parent 36035 95791b275b73
child 36046 a5cf79755eff
equal deleted inserted replaced
36044:3b4d14beac3d 36045:04984f2e50ae
    10 
    10 
    11 import collections
    11 import collections
    12 import copy
    12 import copy
    13 import difflib
    13 import difflib
    14 import email
    14 import email
    15 import email.parser as emailparser
       
    16 import errno
    15 import errno
    17 import hashlib
    16 import hashlib
    18 import os
    17 import os
    19 import posixpath
    18 import posixpath
    20 import re
    19 import re
   107 
   106 
   108         for line in stream:
   107         for line in stream:
   109             cur.append(line)
   108             cur.append(line)
   110         c = chunk(cur)
   109         c = chunk(cur)
   111 
   110 
   112         m = emailparser.Parser().parse(c)
   111         m = pycompat.emailparser().parse(c)
   113         if not m.is_multipart():
   112         if not m.is_multipart():
   114             yield msgfp(m)
   113             yield msgfp(m)
   115         else:
   114         else:
   116             ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   115             ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   117             for part in m.walk():
   116             for part in m.walk():
   216 
   215 
   217     data = {}
   216     data = {}
   218     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   217     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   219     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   218     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   220     try:
   219     try:
   221         msg = emailparser.Parser().parse(fileobj)
   220         msg = pycompat.emailparser().parse(fileobj)
   222 
   221 
   223         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
   222         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
   224         data['user'] = msg['From'] and mail.headdecode(msg['From'])
   223         data['user'] = msg['From'] and mail.headdecode(msg['From'])
   225         if not subject and not data['user']:
   224         if not subject and not data['user']:
   226             # Not an email, restore parsed headers if any
   225             # Not an email, restore parsed headers if any