comparison mercurial/patch.py @ 4211:1253703853a8

git-send-email compatibility: stop reading changelog after ^---$
author Brendan Cully <brendan@kublai.com>
date Wed, 14 Mar 2007 11:46:07 -0700
parents bd9b84b9a84b
children 0d51eb296fb9
comparison
equal deleted inserted replaced
4210:6cb5be6bd70f 4211:1253703853a8
46 '(---|\*\*\*)[ \t])', re.MULTILINE) 46 '(---|\*\*\*)[ \t])', re.MULTILINE)
47 47
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 hgpatch = False
52
53 msg = email.Parser.Parser().parse(fileobj) 51 msg = email.Parser.Parser().parse(fileobj)
54 52
55 message = msg['Subject'] 53 message = msg['Subject']
56 user = msg['From'] 54 user = msg['From']
57 # should try to parse msg['Date'] 55 # should try to parse msg['Date']
75 if content_type not in ok_types: 73 if content_type not in ok_types:
76 continue 74 continue
77 payload = part.get_payload(decode=True) 75 payload = part.get_payload(decode=True)
78 m = diffre.search(payload) 76 m = diffre.search(payload)
79 if m: 77 if m:
78 hgpatch = False
79 ignoretext = False
80
80 ui.debug(_('found patch at byte %d\n') % m.start(0)) 81 ui.debug(_('found patch at byte %d\n') % m.start(0))
81 diffs_seen += 1 82 diffs_seen += 1
82 cfp = cStringIO.StringIO() 83 cfp = cStringIO.StringIO()
83 if message: 84 if message:
84 cfp.write(message) 85 cfp.write(message)
94 if line.startswith('# User '): 95 if line.startswith('# User '):
95 user = line[7:] 96 user = line[7:]
96 ui.debug('From: %s\n' % user) 97 ui.debug('From: %s\n' % user)
97 elif line.startswith("# Date "): 98 elif line.startswith("# Date "):
98 date = line[7:] 99 date = line[7:]
99 if not line.startswith('# '): 100 elif line == '---' and 'git-send-email' in msg['X-Mailer']:
101 ignoretext = True
102 if not line.startswith('# ') and not ignoretext:
100 cfp.write(line) 103 cfp.write(line)
101 cfp.write('\n') 104 cfp.write('\n')
102 message = cfp.getvalue() 105 message = cfp.getvalue()
103 if tmpfp: 106 if tmpfp:
104 tmpfp.write(payload) 107 tmpfp.write(payload)