~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/uncommit.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Remove the last revision from the history of the current branch."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# TODO: make the guts of this methods on tree, branch.
20
22
 
21
23
from bzrlib import (
26
28
from bzrlib.errors import BoundBranchOutOfDate
27
29
 
28
30
 
 
31
def remove_tags(branch, graph, old_tip, parents):
 
32
    """Remove tags on revisions between old_tip and new_tip.
 
33
 
 
34
    :param branch: Branch to remove tags from
 
35
    :param graph: Graph object for branch repository
 
36
    :param old_tip: Old branch tip
 
37
    :param parents: New parents
 
38
    :return: Names of the removed tags
 
39
    """
 
40
    reverse_tags = branch.tags.get_reverse_tag_dict()
 
41
    ancestors = graph.find_unique_ancestors(old_tip, parents)
 
42
    removed_tags = []
 
43
    for revid, tags in reverse_tags.iteritems():
 
44
        if not revid in ancestors:
 
45
            continue
 
46
        for tag in tags:
 
47
            branch.tags.delete_tag(tag)
 
48
            removed_tags.append(tag)
 
49
    return removed_tags
 
50
 
 
51
 
29
52
def uncommit(branch, dry_run=False, verbose=False, revno=None, tree=None,
30
 
             local=False):
 
53
             local=False, keep_tags=False):
31
54
    """Remove the last revision from the supplied branch.
32
55
 
33
56
    :param dry_run: Don't actually change anything
36
59
    :param local: If this branch is bound, only remove the revisions from the
37
60
        local branch. If this branch is not bound, it is an error to pass
38
61
        local=True.
 
62
    :param keep_tags: Whether to keep tags pointing at the removed revisions
 
63
        around.
39
64
    """
40
65
    unlockable = []
41
66
    try:
66
91
            revno = old_revno
67
92
        new_revno = revno - 1
68
93
 
69
 
        revid_iterator = branch.repository.iter_reverse_revision_history(
70
 
                            old_tip)
71
94
        cur_revno = old_revno
72
95
        new_revision_id = old_tip
73
96
        graph = branch.repository.get_graph()
74
 
        for rev_id in revid_iterator:
 
97
        for rev_id in graph.iter_lefthand_ancestry(old_tip):
75
98
            if cur_revno == new_revno:
76
99
                new_revision_id = rev_id
77
100
                break
107
130
                    hook_new_tip = None
108
131
                hook(hook_local, hook_master, old_revno, old_tip, new_revno,
109
132
                     hook_new_tip)
 
133
            if not _mod_revision.is_null(new_revision_id):
 
134
                parents = [new_revision_id]
 
135
            else:
 
136
                parents = []
110
137
            if tree is not None:
111
 
                if not _mod_revision.is_null(new_revision_id):
112
 
                    parents = [new_revision_id]
113
 
                else:
114
 
                    parents = []
115
138
                parents.extend(reversed(pending_merges))
116
139
                tree.set_parent_ids(parents)
 
140
            if branch.supports_tags() and not keep_tags:
 
141
                remove_tags(branch, graph, old_tip, parents)
117
142
    finally:
118
143
        for item in reversed(unlockable):
119
144
            item.unlock()