/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.205.1 by Jelmer Vernooij
Import utility functions for foreign branches.
1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Foreign branch utilities."""
18
0.205.6 by Jelmer Vernooij
Import FakeControlFiles.
19
from bzrlib import errors, registry
0.205.7 by Jelmer Vernooij
Import dpush.
20
from bzrlib.commands import Command, Option
0.205.3 by Jelmer Vernooij
Fix import.
21
22
0.205.1 by Jelmer Vernooij
Import utility functions for foreign branches.
23
class VcsMapping(object):
24
    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
25
26
    """
27
    experimental = False
28
    roundtripping = False
29
    revid_prefix = None
30
31
32
class VcsMappingRegistry(registry.Registry):
33
    """Registry for Bazaar<->foreign VCS mappings.
34
    
35
    There should be one instance of this registry for every foreign VCS.
36
    """
37
38
    def register(self, key, factory, help):
39
        """Register a mapping between Bazaar and foreign VCS semantics.
40
41
        The factory must be a callable that takes one parameter: the key.
42
        It must produce an instance of VcsMapping when called.
43
        """
44
        registry.Registry.register(self, key, factory, help)
45
46
    def set_default(self, key):
47
        """Set the 'default' key to be a clone of the supplied key.
48
49
        This method must be called once and only once.
50
        """
51
        self._set_default_key(key)
52
53
    def get_default(self):
54
        """Convenience function for obtaining the default mapping to use."""
55
        return self.get(self._get_default_key())
56
0.205.6 by Jelmer Vernooij
Import FakeControlFiles.
57
58
class FakeControlFiles(object):
59
    """Dummy implementation of ControlFiles.
60
    
61
    This is required as some code relies on controlfiles being 
62
    available."""
63
    def get_utf8(self, name):
64
        raise errors.NoSuchFile(name)
65
66
    def get(self, name):
67
        raise errors.NoSuchFile(name)
68
69
    def break_lock(self):
70
        pass
71
0.205.7 by Jelmer Vernooij
Import dpush.
72
73
class cmd_dpush(Command):
74
    """Push diffs into Subversion without any Bazaar-specific properties set.
75
76
    This will afterwards rebase the local Bazaar branch on the Subversion 
77
    branch unless the --no-rebase option is used, in which case 
78
    the two branches will be out of sync. 
79
    """
80
    takes_args = ['location?']
81
    takes_options = ['remember', Option('directory',
82
            help='Branch to push from, '
83
                 'rather than the one containing the working directory.',
84
            short_name='d',
85
            type=unicode,
86
            ),
87
            Option('no-rebase', help="Don't rebase after push")]
88
89
    def run(self, location=None, remember=False, directory=None, 
90
            no_rebase=False):
91
        from bzrlib import urlutils
92
        from bzrlib.bzrdir import BzrDir
93
        from bzrlib.branch import Branch
94
        from bzrlib.errors import BzrCommandError, NoWorkingTree
95
        from bzrlib.workingtree import WorkingTree
96
97
        if directory is None:
98
            directory = "."
99
        try:
100
            source_wt = WorkingTree.open_containing(directory)[0]
101
            source_branch = source_wt.branch
102
        except NoWorkingTree:
103
            source_branch = Branch.open_containing(directory)[0]
104
            source_wt = None
105
        stored_loc = source_branch.get_push_location()
106
        if location is None:
107
            if stored_loc is None:
108
                raise BzrCommandError("No push location known or specified.")
109
            else:
110
                display_url = urlutils.unescape_for_display(stored_loc,
111
                        self.outf.encoding)
112
                self.outf.write("Using saved location: %s\n" % display_url)
113
                location = stored_loc
114
115
        bzrdir = BzrDir.open(location)
116
        target_branch = bzrdir.open_branch()
117
        target_branch.lock_write()
118
        revid_map = source_branch.dpush(target_branch)
119
        # We successfully created the target, remember it
120
        if source_branch.get_push_location() is None or remember:
121
            source_branch.set_push_location(target_branch.base)
122
        if not no_rebase:
123
            _, old_last_revid = source_branch.last_revision_info()
124
            new_last_revid = revid_map[old_last_revid]
125
            if source_wt is not None:
126
                source_wt.pull(target_branch, overwrite=True, 
127
                               stop_revision=new_last_revid)
128
            else:
129
                source_branch.pull(target_branch, overwrite=True, 
130
                                   stop_revision=new_last_revid)
131
132
133