comparison mercurial/patch.py @ 4258:47ba52121433

Add import --exact. When this option is set, import will apply the patch (which must be generated by export) to the parents specified in the patch, and check that the node produced by the patch matches the node ID in the patch.
author Brendan Cully <brendan@kublai.com>
date Thu, 22 Mar 2007 10:44:59 -0700
parents 0d51eb296fb9
children aa26759c6fb3
comparison
equal deleted inserted replaced
4257:f51317e24114 4258:47ba52121433
31 # public functions 31 # public functions
32 32
33 def extract(ui, fileobj): 33 def extract(ui, fileobj):
34 '''extract patch from data read from fileobj. 34 '''extract patch from data read from fileobj.
35 35
36 patch can be normal patch or contained in email message. 36 patch can be a normal patch or contained in an email message.
37 37
38 return tuple (filename, message, user, date). any item in returned 38 return tuple (filename, message, user, date, node, p1, p2).
39 tuple can be None. if filename is None, fileobj did not contain 39 Any item in the returned tuple can be None. If filename is None,
40 patch. caller must unlink filename when done.''' 40 fileobj did not contain a patch. Caller must unlink filename when done.'''
41 41
42 # attempt to detect the start of a patch 42 # attempt to detect the start of a patch
43 # (this heuristic is borrowed from quilt) 43 # (this heuristic is borrowed from quilt)
44 diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' + 44 diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' +
45 'retrieving revision [0-9]+(\.[0-9]+)*$|' + 45 'retrieving revision [0-9]+(\.[0-9]+)*$|' +
52 52
53 message = msg['Subject'] 53 message = msg['Subject']
54 user = msg['From'] 54 user = msg['From']
55 # should try to parse msg['Date'] 55 # should try to parse msg['Date']
56 date = None 56 date = None
57 nodeid = None
58 parents = []
57 59
58 if message: 60 if message:
59 if message.startswith('[PATCH'): 61 if message.startswith('[PATCH'):
60 pend = message.find(']') 62 pend = message.find(']')
61 if pend >= 0: 63 if pend >= 0:
95 if line.startswith('# User '): 97 if line.startswith('# User '):
96 user = line[7:] 98 user = line[7:]
97 ui.debug('From: %s\n' % user) 99 ui.debug('From: %s\n' % user)
98 elif line.startswith("# Date "): 100 elif line.startswith("# Date "):
99 date = line[7:] 101 date = line[7:]
102 elif line.startswith("# Node ID "):
103 nodeid = line[10:]
104 elif line.startswith("# Parent "):
105 parents.append(line[10:])
100 elif line == '---' and 'git-send-email' in msg['X-Mailer']: 106 elif line == '---' and 'git-send-email' in msg['X-Mailer']:
101 ignoretext = True 107 ignoretext = True
102 if not line.startswith('# ') and not ignoretext: 108 if not line.startswith('# ') and not ignoretext:
103 cfp.write(line) 109 cfp.write(line)
104 cfp.write('\n') 110 cfp.write('\n')
115 raise 121 raise
116 122
117 tmpfp.close() 123 tmpfp.close()
118 if not diffs_seen: 124 if not diffs_seen:
119 os.unlink(tmpname) 125 os.unlink(tmpname)
120 return None, message, user, date 126 return None, message, user, date, None, None, None
121 return tmpname, message, user, date 127 p1 = parents and parents.pop(0) or None
128 p2 = parents and parents.pop(0) or None
129 return tmpname, message, user, date, nodeid, p1, p2
122 130
123 GP_PATCH = 1 << 0 # we have to run patch 131 GP_PATCH = 1 << 0 # we have to run patch
124 GP_FILTER = 1 << 1 # there's some copy/rename operation 132 GP_FILTER = 1 << 1 # there's some copy/rename operation
125 GP_BINARY = 1 << 2 # there's a binary patch 133 GP_BINARY = 1 << 2 # there's a binary patch
126 134