~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
3
from userinteractor import UserInteractor, UserOption
 
4
import copy
4
5
 
5
6
class HunkSelector:
6
7
    strings = {}
116
117
        return False
117
118
 
118
119
    def select(self):
119
 
        if self.total_hunks == 0:
120
 
            return []
121
 
 
122
 
        if not self.interactor.interact():
123
 
            # False from interact means they quit
124
 
            return []
125
 
 
 
120
        if self.total_hunks == 0 or not self.interactor.interact():
 
121
            # False from interact means they chose to quit
 
122
            return ([], [])
 
123
 
 
124
        # Go through each patch and collect all selected/unselected hunks
126
125
        for patch in self.patches:
127
 
            tmp = []
 
126
            patch.selected = []
 
127
            patch.unselected = []
128
128
            for hunk in patch.hunks:
129
129
                if hunk.selected:
130
 
                    tmp.append(hunk)
131
 
            patch.hunks = tmp
132
 
 
133
 
        tmp = []
 
130
                    patch.selected.append(hunk)
 
131
                else:
 
132
                    patch.unselected.append(hunk)
 
133
 
 
134
        # Now build two lists, one of selected patches the other unselected
 
135
        selected_patches = []
 
136
        unselected_patches = []
 
137
 
134
138
        for patch in self.patches:
135
 
            if len(patch.hunks):
136
 
                tmp.append(patch)
137
 
        self.patches = tmp
138
 
 
139
 
        return self.patches
 
139
            if len(patch.selected):
 
140
                tmp = copy.copy(patch)
 
141
                tmp.hunks = tmp.selected
 
142
                del tmp.selected
 
143
                del tmp.unselected
 
144
                selected_patches.append(tmp)
 
145
 
 
146
            if len(patch.unselected):
 
147
                tmp = copy.copy(patch)
 
148
                tmp.hunks = tmp.unselected
 
149
                del tmp.selected
 
150
                del tmp.unselected
 
151
                unselected_patches.append(tmp)
 
152
 
 
153
        return (selected_patches, unselected_patches)
140
154
 
141
155
class ShelveHunkSelector(HunkSelector):
142
156
    def __init__(self, patches):