21
21
def uncommit(branch, remove_files=False,
22
dry_run=False, verbose=False):
22
dry_run=False, verbose=False, revno=None):
23
23
"""Remove the last revision from the supplied branch.
25
25
:param remove_files: If True, remove files from the stores
28
28
from bzrlib.atomicfile import AtomicFile
29
29
rh = branch.revision_history()
31
rev = branch.get_revision(rev_id)
32
inv = branch.get_inventory(rev.inventory_id)
35
inv_prev.append(branch.get_revision_inventory(p.revision_id))
37
34
new_rev_history = AtomicFile(branch.controlfilename('revision-history'))
35
for r in range(revno-1, len(rh)):
38
print 'Removing revno %d: %s' % (len(rh)+1, rev_id)
39
rev = branch.get_revision(rev_id)
40
inv = branch.get_inventory(rev.inventory_id)
43
inv_prev.append(branch.get_revision_inventory(p.revision_id))
46
# Figure out what text-store entries are new
48
# In the future, when we have text_version instead of
49
# text_id, we can just check to see if the text_version
50
# equals the current revision id.
53
if not hasattr(ie, 'text_id'):
55
for other_inv in inv_prev:
56
if file_id in other_inv:
57
other_ie = other_inv[file_id]
58
if other_ie.text_id == ie.text_id:
61
# None of the previous ancestors used
63
files_to_remove.append(branch.controlfilename(['text-store',
65
rev_file = branch.controlfilename(['revision-store',
67
files_to_remove.append(rev_file)
68
inv_file = branch.controlfilename(['inventory-store',
69
rev.inventory_id + '.gz'])
70
files_to_remove.append(inv_file)
73
print 'Removing files:'
74
for f in files_to_remove:
75
print '\t%s' % branch.relpath(f)
38
77
new_rev_history.write('\n'.join(rh))
39
# Committing now, because even if we fail to remove all files
79
# Committing before we start removing files, because
40
80
# once we have removed at least one, all the rest are invalid.
42
82
new_rev_history.commit()
44
new_rev_history.abort()
47
# Figure out what text-store entries are new
51
if not hasattr(ie, 'text_id'):
53
for other_inv in inv_prev:
54
if file_id in other_inv:
55
other_ie = other_inv[file_id]
56
if other_ie.text_id == ie.text_id:
59
# None of the previous ancestors used
61
files_to_remove.append(branch.controlfilename(['text-store',
63
rev_file = branch.controlfilename(['revision-store',
65
files_to_remove.append(rev_file)
66
inv_file = branch.controlfilename(['inventory-store',
67
rev.inventory_id + '.gz'])
68
files_to_remove.append(inv_file)
71
print 'Removing files:'
72
for f in files_to_remove:
73
print '\t%s' % branch.relpath(f)
76
84
# Actually start removing files
77
85
for f in files_to_remove:
89
new_rev_history.abort()