Show More
@@ -178,7 +178,7 b' class hunk(object):' | |||||
178 | return '<hunk %r@%d>' % (self.filename(), self.fromline) |
|
178 | return '<hunk %r@%d>' % (self.filename(), self.fromline) | |
179 |
|
179 | |||
180 | def parsepatch(fp): |
|
180 | def parsepatch(fp): | |
181 | """patch -> [] of hunks """ |
|
181 | """patch -> [] of headers -> [] of hunks """ | |
182 | class parser(object): |
|
182 | class parser(object): | |
183 | """patch parsing state machine""" |
|
183 | """patch parsing state machine""" | |
184 | def __init__(self): |
|
184 | def __init__(self): | |
@@ -189,7 +189,7 b' def parsepatch(fp):' | |||||
189 | self.context = [] |
|
189 | self.context = [] | |
190 | self.before = [] |
|
190 | self.before = [] | |
191 | self.hunk = [] |
|
191 | self.hunk = [] | |
192 |
self. |
|
192 | self.headers = [] | |
193 |
|
193 | |||
194 | def addrange(self, limits): |
|
194 | def addrange(self, limits): | |
195 | fromstart, fromend, tostart, toend, proc = limits |
|
195 | fromstart, fromend, tostart, toend, proc = limits | |
@@ -202,7 +202,6 b' def parsepatch(fp):' | |||||
202 | h = hunk(self.header, self.fromline, self.toline, self.proc, |
|
202 | h = hunk(self.header, self.fromline, self.toline, self.proc, | |
203 | self.before, self.hunk, context) |
|
203 | self.before, self.hunk, context) | |
204 | self.header.hunks.append(h) |
|
204 | self.header.hunks.append(h) | |
205 | self.stream.append(h) |
|
|||
206 | self.fromline += len(self.before) + h.removed |
|
205 | self.fromline += len(self.before) + h.removed | |
207 | self.toline += len(self.before) + h.added |
|
206 | self.toline += len(self.before) + h.added | |
208 | self.before = [] |
|
207 | self.before = [] | |
@@ -219,12 +218,12 b' def parsepatch(fp):' | |||||
219 | def newfile(self, hdr): |
|
218 | def newfile(self, hdr): | |
220 | self.addcontext([]) |
|
219 | self.addcontext([]) | |
221 | h = header(hdr) |
|
220 | h = header(hdr) | |
222 |
self. |
|
221 | self.headers.append(h) | |
223 | self.header = h |
|
222 | self.header = h | |
224 |
|
223 | |||
225 | def finished(self): |
|
224 | def finished(self): | |
226 | self.addcontext([]) |
|
225 | self.addcontext([]) | |
227 |
return self. |
|
226 | return self.headers | |
228 |
|
227 | |||
229 | transitions = { |
|
228 | transitions = { | |
230 | 'file': {'context': addcontext, |
|
229 | 'file': {'context': addcontext, | |
@@ -253,18 +252,8 b' def parsepatch(fp):' | |||||
253 | state = newstate |
|
252 | state = newstate | |
254 | return p.finished() |
|
253 | return p.finished() | |
255 |
|
254 | |||
256 |
def filterpatch(ui, |
|
255 | def filterpatch(ui, headers): | |
257 | """Interactively filter patch chunks into applied-only chunks""" |
|
256 | """Interactively filter patch chunks into applied-only chunks""" | |
258 | def consumefile(chunks): |
|
|||
259 | """fetch next portion from chunks until a 'header' is seen |
|
|||
260 | NB: header == new-file mark |
|
|||
261 | """ |
|
|||
262 | consumed = [] |
|
|||
263 | while chunks: |
|
|||
264 | if isinstance(chunks[-1], header): |
|
|||
265 | break |
|
|||
266 | consumed.append(chunks.pop()) |
|
|||
267 | return consumed |
|
|||
268 |
|
257 | |||
269 | def prompt(skipfile, skipall, query): |
|
258 | def prompt(skipfile, skipall, query): | |
270 | """prompt query, and process base inputs |
|
259 | """prompt query, and process base inputs | |
@@ -315,43 +304,39 b' def filterpatch(ui, chunks):' | |||||
315 | raise util.Abort(_('user quit')) |
|
304 | raise util.Abort(_('user quit')) | |
316 | return ret, skipfile, skipall |
|
305 | return ret, skipfile, skipall | |
317 |
|
306 | |||
318 | chunks = list(chunks) |
|
|||
319 | chunks.reverse() |
|
|||
320 | seen = set() |
|
307 | seen = set() | |
321 | applied = {} # 'filename' -> [] of chunks |
|
308 | applied = {} # 'filename' -> [] of chunks | |
322 | skipfile, skipall = None, None |
|
309 | skipfile, skipall = None, None | |
323 | pos, total = 0, len(chunks) - 1 |
|
310 | # XXX: operation count is weird: it counts headers and hunks | |
324 | while chunks: |
|
311 | # except for the first header. It probably comes from the previous | |
325 | pos = total - len(chunks) + 1 |
|
312 | # mixed header/hunk stream representation. | |
326 | chunk = chunks.pop() |
|
313 | pos, total = -1, sum((len(h.hunks) + 1) for h in headers) - 1 | |
327 | if isinstance(chunk, header): |
|
314 | for h in headers: | |
328 | # new-file mark |
|
315 | pos += len(h.hunks) + 1 | |
329 |
|
|
316 | skipfile = None | |
330 |
|
|
317 | fixoffset = 0 | |
331 |
|
|
318 | hdr = ''.join(h.header) | |
332 |
|
|
319 | if hdr in seen: | |
333 |
|
|
320 | continue | |
334 | continue |
|
321 | seen.add(hdr) | |
335 | seen.add(hdr) |
|
322 | if skipall is None: | |
336 | if skipall is None: |
|
323 | h.pretty(ui) | |
337 | chunk.pretty(ui) |
|
324 | msg = (_('examine changes to %s?') % | |
338 | msg = (_('examine changes to %s?') % |
|
325 | _(' and ').join(map(repr, h.files()))) | |
339 | _(' and ').join(map(repr, chunk.files()))) |
|
326 | r, skipfile, skipall = prompt(skipfile, skipall, msg) | |
340 | r, skipfile, skipall = prompt(skipfile, skipall, msg) |
|
327 | if not r: | |
341 |
|
|
328 | continue | |
342 |
|
|
329 | applied[h.filename()] = [h] | |
343 |
|
|
330 | if h.allhunks(): | |
344 |
|
|
331 | applied[h.filename()] += h.hunks | |
345 |
e |
|
332 | continue | |
346 | consumefile(chunks) |
|
333 | for i, chunk in enumerate(h.hunks): | |
347 | else: |
|
|||
348 | # new hunk |
|
|||
349 | if skipfile is None and skipall is None: |
|
334 | if skipfile is None and skipall is None: | |
350 | chunk.pretty(ui) |
|
335 | chunk.pretty(ui) | |
351 | msg = (total == 1 |
|
336 | msg = (total == 1 | |
352 | and (_('record this change to %r?') % chunk.filename()) |
|
337 | and (_('record this change to %r?') % chunk.filename()) | |
353 | or (_('record change %d/%d to %r?') % |
|
338 | or (_('record change %d/%d to %r?') % | |
354 | (pos, total, chunk.filename()))) |
|
339 | (pos - len(h.hunks) + i + 1, total, chunk.filename()))) | |
355 | r, skipfile, skipall = prompt(skipfile, skipall, msg) |
|
340 | r, skipfile, skipall = prompt(skipfile, skipall, msg) | |
356 | if r: |
|
341 | if r: | |
357 | if fixoffset: |
|
342 | if fixoffset: |
General Comments 0
You need to be logged in to leave comments.
Login now