/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/uncommit.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

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