##// END OF EJS Templates
Get patchbomb script to not use MIME attachments....
Bryan O'Sullivan -
r876:14cfaaec default
parent child Browse files
Show More
@@ -74,15 +74,14 b' def diffstat(patch):'
74
74
75 def patchbomb(ui, repo, *revs, **opts):
75 def patchbomb(ui, repo, *revs, **opts):
76 def prompt(prompt, default = None, rest = ': ', empty_ok = False):
76 def prompt(prompt, default = None, rest = ': ', empty_ok = False):
77 try:
78 if default: prompt += ' [%s]' % default
77 if default: prompt += ' [%s]' % default
79 prompt += rest
78 prompt += rest
79 while True:
80 r = raw_input(prompt)
80 r = raw_input(prompt)
81 if not r and not empty_ok: raise EOFError
81 if r: return r
82 return r
82 if default is not None: return default
83 except EOFError:
83 if empty_ok: return r
84 if default is None: raise
84 print >> sys.stderr, 'Please enter a valid value.'
85 return default
86
85
87 def confirm(s):
86 def confirm(s):
88 if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
87 if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
@@ -97,7 +96,7 b' def patchbomb(ui, repo, *revs, **opts):'
97 confirm('Does the diffstat above look okay')
96 confirm('Does the diffstat above look okay')
98 return s
97 return s
99
98
100 def make_patch(patch, idx, total):
99 def makepatch(patch, idx, total):
101 desc = []
100 desc = []
102 node = None
101 node = None
103 for line in patch:
102 for line in patch:
@@ -107,30 +106,20 b' def patchbomb(ui, repo, *revs, **opts):'
107 if line.startswith('diff -r'): break
106 if line.startswith('diff -r'): break
108 desc.append(line)
107 desc.append(line)
109 if not node: raise ValueError
108 if not node: raise ValueError
110 msg = MIMEMultipart()
109 body = ('\n'.join(desc[1:]).strip() or
111 msg['X-Mercurial-Node'] = node
110 'Patch subject is complete summary.')
111 body += '\n\n\n' + cdiffstat('\n'.join(desc), patch) + '\n\n'
112 body += '\n'.join(patch)
113 msg = MIMEText(body)
112 subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip())
114 subj = '[PATCH %d of %d] %s' % (idx, total, desc[0].strip())
113 if subj.endswith('.'): subj = subj[:-1]
115 if subj.endswith('.'): subj = subj[:-1]
114 msg['Subject'] = subj
116 msg['Subject'] = subj
115 body = '\n'.join(desc[1:]).strip() + '\n'
117 msg['X-Mercurial-Node'] = node
116 summary = subj
117 if body != '\n':
118 msg.attach(MIMEText(body))
119 summary += '\n\n' + body
120 else:
121 summary += '\n'
122 d = cdiffstat(summary, patch)
123 if d: msg.attach(MIMEText(d))
124 p = MIMEText('\n'.join(patch), 'x-patch')
125 p['Content-Disposition'] = commands.make_filename(repo, None,
126 'inline; filename=%b-%n.patch',
127 seqno = idx)
128 msg.attach(p)
129 return msg
118 return msg
130
119
131 start_time = int(time.time())
120 start_time = int(time.time())
132
121
133 def make_msgid(id):
122 def genmsgid(id):
134 return '<%s.%s@%s>' % (id[:20], start_time, socket.getfqdn())
123 return '<%s.%s@%s>' % (id[:20], start_time, socket.getfqdn())
135
124
136 patches = []
125 patches = []
@@ -139,6 +128,7 b' def patchbomb(ui, repo, *revs, **opts):'
139 def __init__(self, container):
128 def __init__(self, container):
140 self.lines = []
129 self.lines = []
141 self.container = container
130 self.container = container
131 self.name = 'email'
142
132
143 def write(self, data):
133 def write(self, data):
144 self.lines.append(data)
134 self.lines.append(data)
@@ -156,7 +146,7 b' def patchbomb(ui, repo, *revs, **opts):'
156
146
157 for p, i in zip(patches, range(len(patches))):
147 for p, i in zip(patches, range(len(patches))):
158 jumbo.extend(p)
148 jumbo.extend(p)
159 msgs.append(make_patch(p, i + 1, len(patches)))
149 msgs.append(makepatch(p, i + 1, len(patches)))
160
150
161 ui.write('\nWrite the introductory message for the patch series.\n\n')
151 ui.write('\nWrite the introductory message for the patch series.\n\n')
162
152
@@ -188,24 +178,22 b' def patchbomb(ui, repo, *revs, **opts):'
188
178
189 msgs.insert(0, msg)
179 msgs.insert(0, msg)
190
180
181 if not opts['test']:
191 s = smtplib.SMTP()
182 s = smtplib.SMTP()
192 s.connect(host = ui.config('smtp', 'host', 'mail'),
183 s.connect(host = ui.config('smtp', 'host', 'mail'),
193 port = int(ui.config('smtp', 'port', 25)))
184 port = int(ui.config('smtp', 'port', 25)))
194
185
195 refs = []
196 parent = None
186 parent = None
197 tz = time.strftime('%z')
187 tz = time.strftime('%z')
198 for m in msgs:
188 for m in msgs:
199 try:
189 try:
200 m['Message-Id'] = make_msgid(m['X-Mercurial-Node'])
190 m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
201 except TypeError:
191 except TypeError:
202 m['Message-Id'] = make_msgid('patchbomb')
192 m['Message-Id'] = genmsgid('patchbomb')
203 if parent:
193 if parent:
204 m['In-Reply-To'] = parent
194 m['In-Reply-To'] = parent
195 else:
205 parent = m['Message-Id']
196 parent = m['Message-Id']
206 if len(refs) > 1:
207 m['References'] = ' '.join(refs[:-1])
208 refs.append(parent)
209 m['Date'] = time.strftime('%a, %m %b %Y %T ', time.localtime(start_time)) + tz
197 m['Date'] = time.strftime('%a, %m %b %Y %T ', time.localtime(start_time)) + tz
210 start_time += 1
198 start_time += 1
211 m['From'] = sender
199 m['From'] = sender
@@ -219,6 +207,7 b' def patchbomb(ui, repo, *revs, **opts):'
219 fp.close()
207 fp.close()
220 else:
208 else:
221 s.sendmail(sender, to + cc, m.as_string(0))
209 s.sendmail(sender, to + cc, m.as_string(0))
210 if not opts['test']:
222 s.close()
211 s.close()
223
212
224 if __name__ == '__main__':
213 if __name__ == '__main__':
General Comments 0
You need to be logged in to leave comments. Login now