##// END OF EJS Templates
mq: smarter handling of plain headers...
Mads Kiilerich -
r23442:a5c94ea3 default
parent child Browse files
Show More
@@ -114,6 +114,12 b' HGHEADERS = ['
114 '# Node ID ',
114 '# Node ID ',
115 '# Parent ', # can occur twice for merges - but that is not relevant for mq
115 '# Parent ', # can occur twice for merges - but that is not relevant for mq
116 ]
116 ]
117 # The order of headers in plain 'mail style' patches:
118 PLAINHEADERS = {
119 'from': 0,
120 'date': 1,
121 'subject': 2,
122 }
117
123
118 def inserthgheader(lines, header, value):
124 def inserthgheader(lines, header, value):
119 """Assuming lines contains a HG patch header, add a header line with value.
125 """Assuming lines contains a HG patch header, add a header line with value.
@@ -156,9 +162,40 b' def inserthgheader(lines, header, value)'
156 return lines
162 return lines
157
163
158 def insertplainheader(lines, header, value):
164 def insertplainheader(lines, header, value):
159 if lines and lines[0] and ':' not in lines[0]:
165 """For lines containing a plain patch header, add a header line with value.
160 lines.insert(0, '')
166 >>> insertplainheader([], 'Date', 'z')
161 lines.insert(0, '%s: %s' % (header, value))
167 ['Date: z']
168 >>> insertplainheader([''], 'Date', 'z')
169 ['Date: z', '']
170 >>> insertplainheader(['x'], 'Date', 'z')
171 ['Date: z', '', 'x']
172 >>> insertplainheader(['From: y', 'x'], 'Date', 'z')
173 ['From: y', 'Date: z', '', 'x']
174 >>> insertplainheader([' date : x', ' from : y', ''], 'From', 'z')
175 [' date : x', 'From: z', '']
176 >>> insertplainheader(['', 'Date: y'], 'Date', 'z')
177 ['Date: z', '', 'Date: y']
178 >>> insertplainheader(['foo: bar', 'DATE: z', 'x'], 'From', 'y')
179 ['From: y', 'foo: bar', 'DATE: z', '', 'x']
180 """
181 newprio = PLAINHEADERS[header.lower()]
182 bestpos = len(lines)
183 for i, line in enumerate(lines):
184 if ':' in line:
185 lheader = line.split(':', 1)[0].strip().lower()
186 lprio = PLAINHEADERS.get(lheader, newprio + 1)
187 if lprio == newprio:
188 lines[i] = '%s: %s' % (header, value)
189 return lines
190 if lprio > newprio and i < bestpos:
191 bestpos = i
192 else:
193 if line:
194 lines.insert(i, '')
195 if i < bestpos:
196 bestpos = i
197 break
198 lines.insert(bestpos, '%s: %s' % (header, value))
162 return lines
199 return lines
163
200
164 class patchheader(object):
201 class patchheader(object):
@@ -412,8 +412,8 b''
412 1: Three (again) - test
412 1: Three (again) - test
413 0: [mq]: 1.patch - test
413 0: [mq]: 1.patch - test
414 ==== qref -d
414 ==== qref -d
415 From: jane
415 Date: 12 0
416 Date: 12 0
416 From: jane
417
417
418 diff -r ... 6
418 diff -r ... 6
419 --- /dev/null
419 --- /dev/null
@@ -465,8 +465,8 b''
465 1: Three (again) - test
465 1: Three (again) - test
466 0: [mq]: 1.patch - test
466 0: [mq]: 1.patch - test
467 ==== qref -u -d
467 ==== qref -u -d
468 From: john
468 Date: 14 0
469 Date: 14 0
469 From: john
470
470
471 diff -r ... 8
471 diff -r ... 8
472 --- /dev/null
472 --- /dev/null
@@ -495,8 +495,8 b''
495 1: Three (again) - test
495 1: Three (again) - test
496 0: [mq]: 1.patch - test
496 0: [mq]: 1.patch - test
497 ==== qref -u -d
497 ==== qref -u -d
498 From: john
498 Date: 15 0
499 Date: 15 0
499 From: john
500
500
501 Nine
501 Nine
502
502
General Comments 0
You need to be logged in to leave comments. Login now