Mercurial > hg
comparison mercurial/crecord.py @ 27155:8d3c5797a175
commit: add a way to return more information from the chunkselector
Before this patch, the chunkselector for record or crecord was used to return
the list of hunks that were selected by the user. The goal of this series is to
reintroduce the toggle amend feature for crecord. To do so, we need to be able
to return more than just the selected hunks from the chunkselector but also
the information: is amend mode toggled. This patch adds a new return value for
chunkselectors that will be used to implement the toggle amend feature in
crecord.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Mon, 30 Nov 2015 16:35:21 -0800 |
parents | 1aee2ab0f902 |
children | 55fa7c3900ae |
comparison
equal
deleted
inserted
replaced
27154:3bc7919fb215 | 27155:8d3c5797a175 |
---|---|
452 if len(headers) == 0: | 452 if len(headers) == 0: |
453 return [] | 453 return [] |
454 uiheaders = [uiheader(h) for h in headers] | 454 uiheaders = [uiheader(h) for h in headers] |
455 # let user choose headers/hunks/lines, and mark their applied flags | 455 # let user choose headers/hunks/lines, and mark their applied flags |
456 # accordingly | 456 # accordingly |
457 chunkselector(ui, uiheaders) | 457 ret = chunkselector(ui, uiheaders) |
458 appliedhunklist = [] | 458 appliedhunklist = [] |
459 for hdr in uiheaders: | 459 for hdr in uiheaders: |
460 if (hdr.applied and | 460 if (hdr.applied and |
461 (hdr.special() or len([h for h in hdr.hunks if h.applied]) > 0)): | 461 (hdr.special() or len([h for h in hdr.hunks if h.applied]) > 0)): |
462 appliedhunklist.append(hdr) | 462 appliedhunklist.append(hdr) |
470 #hnk = copy.copy(hnk) # necessary?? | 470 #hnk = copy.copy(hnk) # necessary?? |
471 hnk.toline += fixoffset | 471 hnk.toline += fixoffset |
472 else: | 472 else: |
473 fixoffset += hnk.removed - hnk.added | 473 fixoffset += hnk.removed - hnk.added |
474 | 474 |
475 return appliedhunklist | 475 return (appliedhunklist, ret) |
476 | 476 |
477 def gethw(): | 477 def gethw(): |
478 """ | 478 """ |
479 magically get the current height and width of the window (without initscr) | 479 magically get the current height and width of the window (without initscr) |
480 | 480 |
499 curses.wrapper(chunkselector.main) | 499 curses.wrapper(chunkselector.main) |
500 if chunkselector.initerr is not None: | 500 if chunkselector.initerr is not None: |
501 raise error.Abort(chunkselector.initerr) | 501 raise error.Abort(chunkselector.initerr) |
502 # ncurses does not restore signal handler for SIGTSTP | 502 # ncurses does not restore signal handler for SIGTSTP |
503 signal.signal(signal.SIGTSTP, f) | 503 signal.signal(signal.SIGTSTP, f) |
504 return chunkselector.opts | |
504 | 505 |
505 def testdecorator(testfn, f): | 506 def testdecorator(testfn, f): |
506 def u(*args, **kwargs): | 507 def u(*args, **kwargs): |
507 return f(testfn, *args, **kwargs) | 508 return f(testfn, *args, **kwargs) |
508 return u | 509 return u |
519 testcommands = map(lambda x: x.rstrip('\n'), testf.readlines()) | 520 testcommands = map(lambda x: x.rstrip('\n'), testf.readlines()) |
520 testf.close() | 521 testf.close() |
521 while True: | 522 while True: |
522 if chunkselector.handlekeypressed(testcommands.pop(0), test=True): | 523 if chunkselector.handlekeypressed(testcommands.pop(0), test=True): |
523 break | 524 break |
525 return chunkselector.opts | |
524 | 526 |
525 class curseschunkselector(object): | 527 class curseschunkselector(object): |
526 def __init__(self, headerlist, ui): | 528 def __init__(self, headerlist, ui): |
527 # put the headers into a patch object | 529 # put the headers into a patch object |
528 self.headerlist = patch(headerlist) | 530 self.headerlist = patch(headerlist) |
529 | 531 |
530 self.ui = ui | 532 self.ui = ui |
533 self.opts = {} | |
531 | 534 |
532 self.errorstr = None | 535 self.errorstr = None |
533 # list of all chunks | 536 # list of all chunks |
534 self.chunklist = [] | 537 self.chunklist = [] |
535 for h in headerlist: | 538 for h in headerlist: |