patch: move 'extract' return to a dictionnary
The final goal here is to be able to parse, return and process arbitrary data
from patch. This mirror the recently added ability to add arbitrary data to
patch headers.
The first step is to return something more flexible, so we return a dict without
changing any other logic.
--- a/mercurial/cmdutil.py Tue Oct 06 01:49:04 2015 -0700
+++ b/mercurial/cmdutil.py Tue Oct 06 02:01:53 2015 -0700
@@ -850,8 +850,15 @@
"""
# avoid cycle context -> subrepo -> cmdutil
import context
- tmpname, message, user, date, branch, nodeid, p1, p2 = \
- patch.extract(ui, hunk)
+ extractdata = patch.extract(ui, hunk)
+ tmpname = extractdata.get('filename')
+ message = extractdata.get('message')
+ user = extractdata.get('user')
+ date = extractdata.get('date')
+ branch = extractdata.get('branch')
+ nodeid = extractdata.get('nodeid')
+ p1 = extractdata.get('p1')
+ p2 = extractdata.get('p2')
update = not opts.get('bypass')
strip = opts["strip"]
--- a/mercurial/patch.py Tue Oct 06 01:49:04 2015 -0700
+++ b/mercurial/patch.py Tue Oct 06 02:01:53 2015 -0700
@@ -156,8 +156,16 @@
patch can be a normal patch or contained in an email message.
- return tuple (filename, message, user, date, branch, node, p1, p2).
- Any item in the returned tuple can be None. If filename is None,
+ return a dictionnary. Standard keys are:
+ - filename,
+ - message,
+ - user,
+ - date,
+ - branch,
+ - node,
+ - p1,
+ - p2.
+ Any item can be missing from the dictionary. If filename is mising,
fileobj did not contain a patch. Caller must unlink filename when done.'''
# attempt to detect the start of a patch
@@ -167,6 +175,7 @@
r'---[ \t].*?^\+\+\+[ \t]|'
r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
+ data = {}
fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
tmpfp = os.fdopen(fd, 'w')
try:
@@ -256,7 +265,11 @@
tmpfp.close()
if not diffs_seen:
os.unlink(tmpname)
- return None, message, user, date, branch, None, None, None
+ data['message'] = message
+ data['user'] = user
+ data['date'] = date
+ data['branch'] = branch
+ return data
if parents:
p1 = parents.pop(0)
@@ -268,7 +281,15 @@
else:
p2 = None
- return tmpname, message, user, date, branch, nodeid, p1, p2
+ data['filename'] = tmpname
+ data['message'] = message
+ data['user'] = user
+ data['date'] = date
+ data['branch'] = branch
+ data['nodeid'] = nodeid
+ data['p1'] = p1
+ data['p2'] = p2
+ return data
class patchmeta(object):
"""Patched file metadata