# HG changeset patch # User Brendan Cully # Date 1183399156 25200 # Node ID 5ee5cbfceff36d613fe99aae7336444c8e34955a # Parent 03844af5ebcdb3ada913ee9739cb969b1d88578f patch.extract: do not prepend subject if the description already starts with it diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -50,7 +50,7 @@ def extract(ui, fileobj): try: msg = email.Parser.Parser().parse(fileobj) - message = msg['Subject'] + subject = msg['Subject'] user = msg['From'] # should try to parse msg['Date'] date = None @@ -58,13 +58,13 @@ def extract(ui, fileobj): branch = None parents = [] - if message: - if message.startswith('[PATCH'): - pend = message.find(']') + if subject: + if subject.startswith('[PATCH'): + pend = subject.find(']') if pend >= 0: - message = message[pend+1:].lstrip() - message = message.replace('\n\t', ' ') - ui.debug('Subject: %s\n' % message) + subject = subject[pend+1:].lstrip() + subject = subject.replace('\n\t', ' ') + ui.debug('Subject: %s\n' % subject) if user: ui.debug('From: %s\n' % user) diffs_seen = 0 @@ -84,9 +84,6 @@ def extract(ui, fileobj): ui.debug(_('found patch at byte %d\n') % m.start(0)) diffs_seen += 1 cfp = cStringIO.StringIO() - if message: - cfp.write(message) - cfp.write('\n') for line in payload[:m.start(0)].splitlines(): if line.startswith('# HG changeset patch'): ui.debug(_('patch generated by hg export\n')) @@ -123,6 +120,8 @@ def extract(ui, fileobj): os.unlink(tmpname) raise + if subject and not message.startswith(subject): + message = '%s\n%s' % (subject, message) tmpfp.close() if not diffs_seen: os.unlink(tmpname)