Mercurial > hg
comparison hgext/record.py @ 13290:82133e91ce7d
record: turn consumefile() into a pure function
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 12:44:05 +0100 |
parents | 592998ba3466 |
children | 90e7be23167e |
comparison
equal
deleted
inserted
replaced
13289:58b26b360a57 | 13290:82133e91ce7d |
---|---|
253 state = newstate | 253 state = newstate |
254 return p.finished() | 254 return p.finished() |
255 | 255 |
256 def filterpatch(ui, chunks): | 256 def filterpatch(ui, chunks): |
257 """Interactively filter patch chunks into applied-only chunks""" | 257 """Interactively filter patch chunks into applied-only chunks""" |
258 chunks = list(chunks) | 258 def consumefile(chunks): |
259 chunks.reverse() | |
260 seen = set() | |
261 def consumefile(): | |
262 """fetch next portion from chunks until a 'header' is seen | 259 """fetch next portion from chunks until a 'header' is seen |
263 NB: header == new-file mark | 260 NB: header == new-file mark |
264 """ | 261 """ |
265 consumed = [] | 262 consumed = [] |
266 while chunks: | 263 while chunks: |
267 if isinstance(chunks[-1], header): | 264 if isinstance(chunks[-1], header): |
268 break | 265 break |
269 else: | 266 consumed.append(chunks.pop()) |
270 consumed.append(chunks.pop()) | |
271 return consumed | 267 return consumed |
272 | 268 |
269 chunks = list(chunks) | |
270 chunks.reverse() | |
271 seen = set() | |
273 resp_all = [None] # this two are changed from inside prompt, | 272 resp_all = [None] # this two are changed from inside prompt, |
274 resp_file = [None] # so can't be usual variables | 273 resp_file = [None] # so can't be usual variables |
275 applied = {} # 'filename' -> [] of chunks | 274 applied = {} # 'filename' -> [] of chunks |
276 def prompt(query): | 275 def prompt(query): |
277 """prompt query, and process base inputs | 276 """prompt query, and process base inputs |
330 # new-file mark | 329 # new-file mark |
331 resp_file = [None] | 330 resp_file = [None] |
332 fixoffset = 0 | 331 fixoffset = 0 |
333 hdr = ''.join(chunk.header) | 332 hdr = ''.join(chunk.header) |
334 if hdr in seen: | 333 if hdr in seen: |
335 consumefile() | 334 consumefile(chunks) |
336 continue | 335 continue |
337 seen.add(hdr) | 336 seen.add(hdr) |
338 if resp_all[0] is None: | 337 if resp_all[0] is None: |
339 chunk.pretty(ui) | 338 chunk.pretty(ui) |
340 r = prompt(_('examine changes to %s?') % | 339 r = prompt(_('examine changes to %s?') % |
341 _(' and ').join(map(repr, chunk.files()))) | 340 _(' and ').join(map(repr, chunk.files()))) |
342 if r: | 341 if r: |
343 applied[chunk.filename()] = [chunk] | 342 applied[chunk.filename()] = [chunk] |
344 if chunk.allhunks(): | 343 if chunk.allhunks(): |
345 applied[chunk.filename()] += consumefile() | 344 applied[chunk.filename()] += consumefile(chunks) |
346 else: | 345 else: |
347 consumefile() | 346 consumefile(chunks) |
348 else: | 347 else: |
349 # new hunk | 348 # new hunk |
350 if resp_file[0] is None and resp_all[0] is None: | 349 if resp_file[0] is None and resp_all[0] is None: |
351 chunk.pretty(ui) | 350 chunk.pretty(ui) |
352 r = (total == 1 | 351 r = (total == 1 |