3
# Copyright (C) 2005 Michael Ellerman <michael@ellerman.id.au>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
from bzrlib.commands import Command
26
if len(args) == 2 and args[1] == '--bzr-usage':
29
elif len(args) == 2 and args[1] == '--bzr-help':
30
print 'Shelve a patch, you can get it back later with unshelve.'
35
raise Exception("Don't understand args %s" % args)
40
root = run_bzr('root')[0].strip()
41
shelf = os.path.join(root, '.bzr-shelf')
43
if not os.path.exists(shelf):
44
raise Exception("No shelf found in '%s'" % shelf)
46
patch = open(shelf, 'r').read()
48
print >>sys.stderr, "Reapplying shelved patches"
49
pipe = os.popen('patch -d %s -s -p0' % root, 'w')
53
if pipe.close() is not None:
54
raise Exception("Failed running patch!")
57
print 'Diff status is now:'
58
os.system('bzr diff | diffstat')
63
diff_lines = run_bzr('diff')
64
patch_list = patches.parse_patches(diff_lines.__iter__())
65
to_shelve = prompt_user(patch_list)
67
if len(to_shelve) == 0:
68
print >>sys.stderr, 'Nothing to shelve'
71
root = run_bzr('root')[0].strip()
72
shelf = os.path.join(root, '.bzr-shelf')
73
print >>sys.stderr, "Saving shelved patches to", shelf
74
shelf = open(shelf, 'a')
76
for patch in to_shelve:
77
shelf.write(str(patch))
80
os.fsync(shelf.fileno())
83
print >>sys.stderr, "Reverting shelved patches"
84
pipe = os.popen('patch -d %s -sR -p0' % root, 'w')
85
for patch in to_shelve:
86
pipe.write(str(patch))
89
if pipe.close() is not None:
90
raise Exception("Failed running patch!")
92
print 'Diff status is now:'
93
os.system('bzr diff | diffstat')
100
pipe = os.popen('bzr %s' % string.join(args, ' '), 'r')
101
lines = pipe.readlines()
102
if pipe.close() is not None:
103
raise Exception("Failed running bzr")
106
def prompt_user(patch_list):
108
for patch in patch_list:
109
total += len(patch.hunks)
116
for patch in patch_list:
117
if patch.oldname != patch.newname:
118
name = "%s -> %s" % (patch.oldname, patch.newname)
122
hunks = patch.hunks[:]
127
out.write('Shelve this change? (%d of %d) [yn] ' % (i, total))
128
line = inp.readline().strip().lower()
129
if line == 'y' or line == 'yes':
131
elif line == 'n' or line == 'no':
132
patch.hunks.remove(hunk)
137
if len(patch.hunks) > 0:
138
to_shelve.append(patch)
142
class cmd_shelve(Command):
143
"""Temporarily remove some changes from the current tree.
144
Use 'unshelve' to restore these changes.
150
class cmd_unshelve(Command):
151
"""Restore previously-shelved changes to the current tree.