9
if len(args) == 2 and args[1] == '--bzr-usage':
12
elif len(args) == 2 and args[1] == '--bzr-help':
13
print 'Shelve a patch, you can get it back later with unshelve.'
18
raise Exception("Don't understand args %s" % args)
23
root = run_bzr('root')[0].strip()
24
shelf = os.path.join(root, '.bzr-shelf')
26
if not os.path.exists(shelf):
27
raise Exception("No shelf found in '%s'" % shelf)
29
patch = open(shelf, 'r').read()
31
print >>sys.stderr, "Reapplying shelved patches"
32
pipe = os.popen('patch -d %s -s -p0' % root, 'w')
36
if pipe.close() is not None:
37
raise Exception("Failed running patch!")
40
print 'Diff status is now:'
41
os.system('bzr diff | diffstat')
46
diff_lines = run_bzr('diff')
47
patch_list = patches.parse_patches(diff_lines.__iter__())
48
to_shelve = prompt_user(patch_list)
50
if len(to_shelve) == 0:
51
print >>sys.stderr, 'Nothing to shelve'
54
root = run_bzr('root')[0].strip()
55
shelf = os.path.join(root, '.bzr-shelf')
56
print >>sys.stderr, "Saving shelved patches to", shelf
57
shelf = open(shelf, 'a')
59
for patch in to_shelve:
60
shelf.write(str(patch))
63
os.fsync(shelf.fileno())
66
print >>sys.stderr, "Reverting shelved patches"
67
pipe = os.popen('patch -d %s -sR -p0' % root, 'w')
68
for patch in to_shelve:
69
pipe.write(str(patch))
72
if pipe.close() is not None:
73
raise Exception("Failed running patch!")
75
print 'Diff status is now:'
76
os.system('bzr diff | diffstat')
83
pipe = os.popen('bzr %s' % string.join(args, ' '), 'r')
84
lines = pipe.readlines()
85
if pipe.close() is not None:
86
raise Exception("Failed running bzr")
89
def prompt_user(patch_list):
91
for patch in patch_list:
92
total += len(patch.hunks)
99
for patch in patch_list:
100
if patch.oldname != patch.newname:
101
name = "%s -> %s" % (patch.oldname, patch.newname)
105
hunks = patch.hunks[:]
110
out.write('Shelve this change? (%d of %d) [yn] ' % (i, total))
111
line = inp.readline().strip().lower()
112
if line == 'y' or line == 'yes':
114
elif line == 'n' or line == 'no':
115
patch.hunks.remove(hunk)
120
if len(patch.hunks) > 0:
121
to_shelve.append(patch)