mercurial/patch.py
changeset 26556 2bef84fad19f
parent 26555 1e33384ff2ed
child 26557 23f3f1cbd53b
equal deleted inserted replaced
26555:1e33384ff2ed 26556:2bef84fad19f
   180     tmpfp = os.fdopen(fd, 'w')
   180     tmpfp = os.fdopen(fd, 'w')
   181     try:
   181     try:
   182         msg = email.Parser.Parser().parse(fileobj)
   182         msg = email.Parser.Parser().parse(fileobj)
   183 
   183 
   184         subject = msg['Subject']
   184         subject = msg['Subject']
   185         user = msg['From']
   185         data['user'] = msg['From']
   186         if not subject and not user:
   186         if not subject and not data['user']:
   187             # Not an email, restore parsed headers if any
   187             # Not an email, restore parsed headers if any
   188             subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
   188             subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
   189 
   189 
   190         # should try to parse msg['Date']
   190         # should try to parse msg['Date']
   191         parents = []
   191         parents = []
   195                 pend = subject.find(']')
   195                 pend = subject.find(']')
   196                 if pend >= 0:
   196                 if pend >= 0:
   197                     subject = subject[pend + 1:].lstrip()
   197                     subject = subject[pend + 1:].lstrip()
   198             subject = re.sub(r'\n[ \t]+', ' ', subject)
   198             subject = re.sub(r'\n[ \t]+', ' ', subject)
   199             ui.debug('Subject: %s\n' % subject)
   199             ui.debug('Subject: %s\n' % subject)
   200         if user:
   200         if data['user']:
   201             ui.debug('From: %s\n' % user)
   201             ui.debug('From: %s\n' % data['user'])
   202         diffs_seen = 0
   202         diffs_seen = 0
   203         ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   203         ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
   204         message = ''
   204         message = ''
   205         for part in msg.walk():
   205         for part in msg.walk():
   206             content_type = part.get_content_type()
   206             content_type = part.get_content_type()
   226                         cfp.seek(0)
   226                         cfp.seek(0)
   227                         cfp.truncate()
   227                         cfp.truncate()
   228                         subject = None
   228                         subject = None
   229                     elif hgpatchheader:
   229                     elif hgpatchheader:
   230                         if line.startswith('# User '):
   230                         if line.startswith('# User '):
   231                             user = line[7:]
   231                             data['user'] = line[7:]
   232                             ui.debug('From: %s\n' % user)
   232                             ui.debug('From: %s\n' % data['user'])
   233                         elif line.startswith("# Date "):
   233                         elif line.startswith("# Date "):
   234                             data['date'] = line[7:]
   234                             data['date'] = line[7:]
   235                         elif line.startswith("# Branch "):
   235                         elif line.startswith("# Branch "):
   236                             data['branch'] = line[9:]
   236                             data['branch'] = line[9:]
   237                         elif line.startswith("# Node ID "):
   237                         elif line.startswith("# Node ID "):
   258         raise
   258         raise
   259 
   259 
   260     if subject and not message.startswith(subject):
   260     if subject and not message.startswith(subject):
   261         message = '%s\n%s' % (subject, message)
   261         message = '%s\n%s' % (subject, message)
   262     data['message'] = message
   262     data['message'] = message
   263     data['user'] = user
       
   264     tmpfp.close()
   263     tmpfp.close()
   265     if parents:
   264     if parents:
   266         data['p1'] = parents.pop(0)
   265         data['p1'] = parents.pop(0)
   267         if parents:
   266         if parents:
   268             data['p2'] = parents.pop(0)
   267             data['p2'] = parents.pop(0)