equal
deleted
inserted
replaced
215 - p2. |
215 - p2. |
216 Any item can be missing from the dictionary. If filename is missing, |
216 Any item can be missing from the dictionary. If filename is missing, |
217 fileobj did not contain a patch. Caller must unlink filename when done.''' |
217 fileobj did not contain a patch. Caller must unlink filename when done.''' |
218 |
218 |
219 fd, tmpname = pycompat.mkstemp(prefix=b'hg-patch-') |
219 fd, tmpname = pycompat.mkstemp(prefix=b'hg-patch-') |
220 tmpfp = os.fdopen(fd, r'wb') |
220 tmpfp = os.fdopen(fd, 'wb') |
221 try: |
221 try: |
222 yield _extract(ui, fileobj, tmpname, tmpfp) |
222 yield _extract(ui, fileobj, tmpname, tmpfp) |
223 finally: |
223 finally: |
224 tmpfp.close() |
224 tmpfp.close() |
225 os.unlink(tmpname) |
225 os.unlink(tmpname) |
239 |
239 |
240 data = {} |
240 data = {} |
241 |
241 |
242 msg = mail.parse(fileobj) |
242 msg = mail.parse(fileobj) |
243 |
243 |
244 subject = msg[r'Subject'] and mail.headdecode(msg[r'Subject']) |
244 subject = msg['Subject'] and mail.headdecode(msg['Subject']) |
245 data[b'user'] = msg[r'From'] and mail.headdecode(msg[r'From']) |
245 data[b'user'] = msg['From'] and mail.headdecode(msg['From']) |
246 if not subject and not data[b'user']: |
246 if not subject and not data[b'user']: |
247 # Not an email, restore parsed headers if any |
247 # Not an email, restore parsed headers if any |
248 subject = ( |
248 subject = ( |
249 b'\n'.join( |
249 b'\n'.join( |
250 b': '.join(map(encoding.strtolocal, h)) for h in msg.items() |
250 b': '.join(map(encoding.strtolocal, h)) for h in msg.items() |
253 ) |
253 ) |
254 |
254 |
255 # should try to parse msg['Date'] |
255 # should try to parse msg['Date'] |
256 parents = [] |
256 parents = [] |
257 |
257 |
258 nodeid = msg[r'X-Mercurial-Node'] |
258 nodeid = msg['X-Mercurial-Node'] |
259 if nodeid: |
259 if nodeid: |
260 data[b'nodeid'] = nodeid = mail.headdecode(nodeid) |
260 data[b'nodeid'] = nodeid = mail.headdecode(nodeid) |
261 ui.debug(b'Node ID: %s\n' % nodeid) |
261 ui.debug(b'Node ID: %s\n' % nodeid) |
262 |
262 |
263 if subject: |
263 if subject: |
1223 prefix=b"hg-editor-", suffix=b".diff" |
1223 prefix=b"hg-editor-", suffix=b".diff" |
1224 ) |
1224 ) |
1225 ncpatchfp = None |
1225 ncpatchfp = None |
1226 try: |
1226 try: |
1227 # Write the initial patch |
1227 # Write the initial patch |
1228 f = util.nativeeolwriter(os.fdopen(patchfd, r'wb')) |
1228 f = util.nativeeolwriter(os.fdopen(patchfd, 'wb')) |
1229 chunk.header.write(f) |
1229 chunk.header.write(f) |
1230 chunk.write(f) |
1230 chunk.write(f) |
1231 f.write( |
1231 f.write( |
1232 b''.join( |
1232 b''.join( |
1233 [b'# ' + i + b'\n' for i in phelp.splitlines()] |
1233 [b'# ' + i + b'\n' for i in phelp.splitlines()] |
1243 ) |
1243 ) |
1244 if ret != 0: |
1244 if ret != 0: |
1245 ui.warn(_(b"editor exited with exit code %d\n") % ret) |
1245 ui.warn(_(b"editor exited with exit code %d\n") % ret) |
1246 continue |
1246 continue |
1247 # Remove comment lines |
1247 # Remove comment lines |
1248 patchfp = open(patchfn, r'rb') |
1248 patchfp = open(patchfn, 'rb') |
1249 ncpatchfp = stringio() |
1249 ncpatchfp = stringio() |
1250 for line in util.iterfile(patchfp): |
1250 for line in util.iterfile(patchfp): |
1251 line = util.fromnativeeol(line) |
1251 line = util.fromnativeeol(line) |
1252 if not line.startswith(b'#'): |
1252 if not line.startswith(b'#'): |
1253 ncpatchfp.write(line) |
1253 ncpatchfp.write(line) |
2786 nextisnewline = True |
2786 nextisnewline = True |
2787 |
2787 |
2788 |
2788 |
2789 def difflabel(func, *args, **kw): |
2789 def difflabel(func, *args, **kw): |
2790 '''yields 2-tuples of (output, label) based on the output of func()''' |
2790 '''yields 2-tuples of (output, label) based on the output of func()''' |
2791 if kw.get(r'opts') and kw[r'opts'].worddiff: |
2791 if kw.get('opts') and kw['opts'].worddiff: |
2792 dodiffhunk = diffsinglehunkinline |
2792 dodiffhunk = diffsinglehunkinline |
2793 else: |
2793 else: |
2794 dodiffhunk = diffsinglehunk |
2794 dodiffhunk = diffsinglehunk |
2795 headprefixes = [ |
2795 headprefixes = [ |
2796 (b'diff', b'diff.diffline'), |
2796 (b'diff', b'diff.diffline'), |