48 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
48 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
49 tmpfp = os.fdopen(fd, 'w') |
49 tmpfp = os.fdopen(fd, 'w') |
50 try: |
50 try: |
51 msg = email.Parser.Parser().parse(fileobj) |
51 msg = email.Parser.Parser().parse(fileobj) |
52 |
52 |
53 message = msg['Subject'] |
53 subject = msg['Subject'] |
54 user = msg['From'] |
54 user = msg['From'] |
55 # should try to parse msg['Date'] |
55 # should try to parse msg['Date'] |
56 date = None |
56 date = None |
57 nodeid = None |
57 nodeid = None |
58 branch = None |
58 branch = None |
59 parents = [] |
59 parents = [] |
60 |
60 |
61 if message: |
61 if subject: |
62 if message.startswith('[PATCH'): |
62 if subject.startswith('[PATCH'): |
63 pend = message.find(']') |
63 pend = subject.find(']') |
64 if pend >= 0: |
64 if pend >= 0: |
65 message = message[pend+1:].lstrip() |
65 subject = subject[pend+1:].lstrip() |
66 message = message.replace('\n\t', ' ') |
66 subject = subject.replace('\n\t', ' ') |
67 ui.debug('Subject: %s\n' % message) |
67 ui.debug('Subject: %s\n' % subject) |
68 if user: |
68 if user: |
69 ui.debug('From: %s\n' % user) |
69 ui.debug('From: %s\n' % user) |
70 diffs_seen = 0 |
70 diffs_seen = 0 |
71 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
71 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
72 |
72 |
82 ignoretext = False |
82 ignoretext = False |
83 |
83 |
84 ui.debug(_('found patch at byte %d\n') % m.start(0)) |
84 ui.debug(_('found patch at byte %d\n') % m.start(0)) |
85 diffs_seen += 1 |
85 diffs_seen += 1 |
86 cfp = cStringIO.StringIO() |
86 cfp = cStringIO.StringIO() |
87 if message: |
|
88 cfp.write(message) |
|
89 cfp.write('\n') |
|
90 for line in payload[:m.start(0)].splitlines(): |
87 for line in payload[:m.start(0)].splitlines(): |
91 if line.startswith('# HG changeset patch'): |
88 if line.startswith('# HG changeset patch'): |
92 ui.debug(_('patch generated by hg export\n')) |
89 ui.debug(_('patch generated by hg export\n')) |
93 hgpatch = True |
90 hgpatch = True |
94 # drop earlier commit message content |
91 # drop earlier commit message content |
121 except: |
118 except: |
122 tmpfp.close() |
119 tmpfp.close() |
123 os.unlink(tmpname) |
120 os.unlink(tmpname) |
124 raise |
121 raise |
125 |
122 |
|
123 if subject and not message.startswith(subject): |
|
124 message = '%s\n%s' % (subject, message) |
126 tmpfp.close() |
125 tmpfp.close() |
127 if not diffs_seen: |
126 if not diffs_seen: |
128 os.unlink(tmpname) |
127 os.unlink(tmpname) |
129 return None, message, user, date, branch, None, None, None |
128 return None, message, user, date, branch, None, None, None |
130 p1 = parents and parents.pop(0) or None |
129 p1 = parents and parents.pop(0) or None |