~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:12:26 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129071226-a04b3f827880025d
Unshelve --pick was broken, because we deleted the whole patch, even when only
part of it was unshelved. So now if we unshelve part of a patch, the patch is
replaced with a new patch that has just the unshelved parts. That's a long way
of saying it does what you'd expect.

Implementing this required changing HunkSelector to return both the selected,
and unselected hunks (ie. patches to shelve, and patches to keep).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
import sys
4
 
 
5
3
from userinteractor import UserInteractor, UserOption
6
4
import copy
7
5
 
9
7
    strings = {}
10
8
 
11
9
    def __init__(self, patches):
12
 
        try:
13
 
            from colordiff import DiffWriter
14
 
            from terminal import has_ansi_colors
15
 
            if has_ansi_colors():
16
 
                self.diff_stream = DiffWriter(sys.stdout)
17
 
            else:
18
 
                self.diff_stream = sys.stdout
19
 
        except ImportError:
20
 
            self.diff_stream = sys.stdout
21
10
        self.standard_options = [
22
11
            UserOption('y', self._selected, self.strings['select_desc'],
23
12
                default=True),
76
65
    # Called once for each hunk
77
66
    def _hunk_callback(self, hunk, count):
78
67
        if self.last_printed != count:
79
 
            self.diff_stream.write(str(hunk.patch.get_header()))
80
 
            self.diff_stream.write(str(hunk))
 
68
            print hunk.patch.get_header(), hunk
81
69
            self.last_printed = count
82
70
 
83
71
        if hunk.selected: