mercurial/patch.py
changeset 35633 a981ab2a1b4c
parent 35589 3328d53254d9
child 35850 079b27b5a869
equal deleted inserted replaced
35632:fa9747e7fc86 35633:a981ab2a1b4c
    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
    15 import errno
    16 import errno
    16 import hashlib
    17 import hashlib
    17 import os
    18 import os
    18 import posixpath
    19 import posixpath
    19 import re
    20 import re
   106 
   107 
   107         for line in stream:
   108         for line in stream:
   108             cur.append(line)
   109             cur.append(line)
   109         c = chunk(cur)
   110         c = chunk(cur)
   110 
   111 
   111         m = email.Parser.Parser().parse(c)
   112         m = emailparser.Parser().parse(c)
   112         if not m.is_multipart():
   113         if not m.is_multipart():
   113             yield msgfp(m)
   114             yield msgfp(m)
   114         else:
   115         else:
   115             ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   116             ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   116             for part in m.walk():
   117             for part in m.walk():
   215 
   216 
   216     data = {}
   217     data = {}
   217     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   218     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
   218     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   219     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
   219     try:
   220     try:
   220         msg = email.Parser.Parser().parse(fileobj)
   221         msg = emailparser.Parser().parse(fileobj)
   221 
   222 
   222         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
   223         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
   223         data['user'] = msg['From'] and mail.headdecode(msg['From'])
   224         data['user'] = msg['From'] and mail.headdecode(msg['From'])
   224         if not subject and not data['user']:
   225         if not subject and not data['user']:
   225             # Not an email, restore parsed headers if any
   226             # Not an email, restore parsed headers if any