14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Remove the last revision from the history of the current branch.
17
"""Remove the last revision from the history of the current branch."""
19
# TODO: make the guts of this methods on tree, branch.
23
from bzrlib.branch import Branch
22
24
from bzrlib.errors import BoundBranchOutOfDate
24
def test_remove(filename):
25
if os.path.exists(filename):
28
print '* file does not exist: %r' % filename
31
27
def uncommit(branch, dry_run=False, verbose=False, revno=None, tree=None):
32
28
"""Remove the last revision from the supplied branch.
54
53
raise BoundBranchOutOfDate(branch, master)
56
old_revno, old_tip = branch.last_revision_info()
58
59
files_to_remove = []
59
60
for r in range(revno-1, len(rh)):
62
# NB: performance would be better using the revision graph rather
63
# than the whole revision.
64
rev = branch.repository.get_revision(rev_id)
65
# When we finish popping off the pending merges, we want
66
# them to stay in the order that they used to be.
67
# but we pop from the end, so reverse the order, and
68
# then get the order right at the end
69
pending_merges.extend(reversed(rev.parent_ids[1:]))
62
71
print 'Removing revno %d: %s' % (len(rh)+1, rev_id)
65
73
# Committing before we start removing files, because
66
74
# once we have removed at least one, all the rest are invalid.
68
76
if master is not None:
69
77
master.set_revision_history(rh)
70
78
branch.set_revision_history(rh)
79
new_tip = branch.last_revision()
86
for hook in Branch.hooks['post_uncommit']:
87
hook(hook_local, hook_master, old_revno, old_tip, new_revno,
71
89
if tree is not None:
72
tree.set_last_revision(branch.last_revision())
90
if new_tip is not None:
94
parents.extend(reversed(pending_merges))
95
tree.set_parent_ids(parents)
74
97
for item in reversed(unlockable):