~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/uncommit.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

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:
105
130
                    hook_new_tip = None
106
131
                hook(hook_local, hook_master, old_revno, old_tip, new_revno,
107
132
                     hook_new_tip)
 
133
            if not _mod_revision.is_null(new_revision_id):
 
134
                parents = [new_revision_id]
 
135
            else:
 
136
                parents = []
108
137
            if tree is not None:
109
 
                if not _mod_revision.is_null(new_revision_id):
110
 
                    parents = [new_revision_id]
111
 
                else:
112
 
                    parents = []
113
138
                parents.extend(reversed(pending_merges))
114
139
                tree.set_parent_ids(parents)
 
140
            if branch.supports_tags() and not keep_tags:
 
141
                remove_tags(branch, graph, old_tip, parents)
115
142
    finally:
116
143
        for item in reversed(unlockable):
117
144
            item.unlock()