~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.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:
65
65
        patches = parse_patches(open(shelf, 'r').readlines())
66
66
        if pick_hunks:
67
67
            try:
68
 
                patches = UnshelveHunkSelector(patches).select()
 
68
                to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
69
69
            except QuitException:
70
70
                return False
 
71
        else:
 
72
            to_unshelve = patches
 
73
            to_remain = []
71
74
 
72
 
        if len(patches) == 0:
 
75
        if len(to_unshelve) == 0:
73
76
            print >>sys.stderr, 'Nothing to unshelve'
74
77
            return True
75
78
 
79
82
            print >>sys.stderr, ' "%s"' % message
80
83
        else:
81
84
            print >>sys.stderr, ""
 
85
 
82
86
        pipe = os.popen('patch -d %s -s -p0' % self.branch.base, 'w')
83
 
        for patch in patches:
 
87
        for patch in to_unshelve:
84
88
            pipe.write(str(patch))
85
89
        pipe.flush()
86
90
 
87
91
        if pipe.close() is not None:
88
92
            raise Exception("Failed running patch!")
89
93
 
90
 
        os.remove(shelf)
 
94
        if len(to_remain) == 0:
 
95
            os.remove(shelf)
 
96
        else:
 
97
            f = open(shelf, 'w')
 
98
            for patch in to_remain:
 
99
                f.write(str(patch))
 
100
            f.close()
91
101
 
92
102
        diff_stat = DiffStat(self.get_patches(None, None))
93
103
        print 'Diff status is now:\n', diff_stat
108
118
 
109
119
        if pick_hunks:
110
120
            try:
111
 
                patches = ShelveHunkSelector(patches).select()
 
121
                to_shelve = ShelveHunkSelector(patches).select()[0]
112
122
            except QuitException:
113
123
                return False
 
124
        else:
 
125
            to_shelve = patches
114
126
 
115
 
        if len(patches) == 0:
 
127
        if len(to_shelve) == 0:
116
128
            print >>sys.stderr, 'Nothing to shelve'
117
129
            return True
118
130
 
122
134
        if message is not None:
123
135
            assert '\n' not in message
124
136
            shelf.write("# shelf: %s\n" % message)
125
 
        for patch in patches:
 
137
        for patch in to_shelve:
126
138
            shelf.write(str(patch))
127
139
 
128
140
        shelf.flush()
131
143
 
132
144
        print >>sys.stderr, "Reverting shelved patches"
133
145
        pipe = os.popen('patch -d %s -sR -p0' % self.branch.base, 'w')
134
 
        for patch in patches:
 
146
        for patch in to_shelve:
135
147
            pipe.write(str(patch))
136
148
        pipe.flush()
137
149