/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):
0.205.8 by Jelmer Vernooij
Remove references to svn.
74
    """Push diffs into a foreign version control system without any 
75
    Bazaar-specific metadata.
0.205.7 by Jelmer Vernooij
Import dpush.
76
0.205.8 by Jelmer Vernooij
Remove references to svn.
77
    This will afterwards rebase the local Bazaar branch on the remote
0.205.7 by Jelmer Vernooij
Import dpush.
78
    branch unless the --no-rebase option is used, in which case 
79
    the two branches will be out of sync. 
80
    """
81
    takes_args = ['location?']
82
    takes_options = ['remember', Option('directory',
83
            help='Branch to push from, '
84
                 'rather than the one containing the working directory.',
85
            short_name='d',
86
            type=unicode,
87
            ),
88
            Option('no-rebase', help="Don't rebase after push")]
89
90
    def run(self, location=None, remember=False, directory=None, 
91
            no_rebase=False):
92
        from bzrlib import urlutils
93
        from bzrlib.bzrdir import BzrDir
94
        from bzrlib.branch import Branch
95
        from bzrlib.errors import BzrCommandError, NoWorkingTree
96
        from bzrlib.workingtree import WorkingTree
97
98
        if directory is None:
99
            directory = "."
100
        try:
101
            source_wt = WorkingTree.open_containing(directory)[0]
102
            source_branch = source_wt.branch
103
        except NoWorkingTree:
104
            source_branch = Branch.open_containing(directory)[0]
105
            source_wt = None
106
        stored_loc = source_branch.get_push_location()
107
        if location is None:
108
            if stored_loc is None:
109
                raise BzrCommandError("No push location known or specified.")
110
            else:
111
                display_url = urlutils.unescape_for_display(stored_loc,
112
                        self.outf.encoding)
113
                self.outf.write("Using saved location: %s\n" % display_url)
114
                location = stored_loc
115
116
        bzrdir = BzrDir.open(location)
117
        target_branch = bzrdir.open_branch()
118
        target_branch.lock_write()
119
        revid_map = source_branch.dpush(target_branch)
120
        # We successfully created the target, remember it
121
        if source_branch.get_push_location() is None or remember:
122
            source_branch.set_push_location(target_branch.base)
123
        if not no_rebase:
124
            _, old_last_revid = source_branch.last_revision_info()
125
            new_last_revid = revid_map[old_last_revid]
126
            if source_wt is not None:
127
                source_wt.pull(target_branch, overwrite=True, 
128
                               stop_revision=new_last_revid)
129
            else:
130
                source_branch.pull(target_branch, overwrite=True, 
131
                                   stop_revision=new_last_revid)
132
133
134