/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 __init__.py

  • Committer: Robert Collins
  • Date: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
19
 
from bzrlib import errors, registry
20
 
from bzrlib.commands import Command, Option
21
 
 
22
 
 
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
 
    def revision_id_bzr_to_foreign(self, bzr_revid):
32
 
        """Parse a bzr revision id and convert it to a foreign revid.
33
 
 
34
 
        :param bzr_revid: The bzr revision id (a string).
35
 
        :return: A foreign revision id, can be any sort of object.
36
 
        """
37
 
        raise NotImplementedError(self.revision_id_bzr_to_foreign)
38
 
 
39
 
    def revision_id_foreign_to_bzr(self, foreign_revid):
40
 
        """Parse a foreign revision id and convert it to a bzr revid.
41
 
 
42
 
        :param foreign_revid: Foreign revision id, can be any sort of object.
43
 
        :return: A bzr revision id.
44
 
        """
45
 
        raise NotImplementedError(self.revision_id_foreign_to_bzr)
46
 
 
47
 
 
48
 
class VcsMappingRegistry(registry.Registry):
49
 
    """Registry for Bazaar<->foreign VCS mappings.
50
 
    
51
 
    There should be one instance of this registry for every foreign VCS.
52
 
    """
53
 
 
54
 
    def register(self, key, factory, help):
55
 
        """Register a mapping between Bazaar and foreign VCS semantics.
56
 
 
57
 
        The factory must be a callable that takes one parameter: the key.
58
 
        It must produce an instance of VcsMapping when called.
59
 
        """
60
 
        registry.Registry.register(self, key, factory, help)
61
 
 
62
 
    def set_default(self, key):
63
 
        """Set the 'default' key to be a clone of the supplied key.
64
 
 
65
 
        This method must be called once and only once.
66
 
        """
67
 
        self._set_default_key(key)
68
 
 
69
 
    def get_default(self):
70
 
        """Convenience function for obtaining the default mapping to use."""
71
 
        return self.get(self._get_default_key())
72
 
 
73
 
 
74
 
class FakeControlFiles(object):
75
 
    """Dummy implementation of ControlFiles.
76
 
    
77
 
    This is required as some code relies on controlfiles being 
78
 
    available."""
79
 
    def get_utf8(self, name):
80
 
        raise errors.NoSuchFile(name)
81
 
 
82
 
    def get(self, name):
83
 
        raise errors.NoSuchFile(name)
84
 
 
85
 
    def break_lock(self):
86
 
        pass
87
 
 
88
 
 
89
 
class cmd_dpush(Command):
90
 
    """Push diffs into a foreign version control system without any 
91
 
    Bazaar-specific metadata.
92
 
 
93
 
    This will afterwards rebase the local Bazaar branch on the remote
94
 
    branch unless the --no-rebase option is used, in which case 
95
 
    the two branches will be out of sync. 
96
 
    """
97
 
    takes_args = ['location?']
98
 
    takes_options = ['remember', Option('directory',
99
 
            help='Branch to push from, '
100
 
                 'rather than the one containing the working directory.',
101
 
            short_name='d',
102
 
            type=unicode,
103
 
            ),
104
 
            Option('no-rebase', help="Don't rebase after push")]
105
 
 
106
 
    def run(self, location=None, remember=False, directory=None, 
107
 
            no_rebase=False):
108
 
        from bzrlib import urlutils
109
 
        from bzrlib.bzrdir import BzrDir
110
 
        from bzrlib.branch import Branch
111
 
        from bzrlib.errors import BzrCommandError, NoWorkingTree
112
 
        from bzrlib.workingtree import WorkingTree
113
 
 
114
 
        if directory is None:
115
 
            directory = "."
116
 
        try:
117
 
            source_wt = WorkingTree.open_containing(directory)[0]
118
 
            source_branch = source_wt.branch
119
 
        except NoWorkingTree:
120
 
            source_branch = Branch.open_containing(directory)[0]
121
 
            source_wt = None
122
 
        stored_loc = source_branch.get_push_location()
123
 
        if location is None:
124
 
            if stored_loc is None:
125
 
                raise BzrCommandError("No push location known or specified.")
126
 
            else:
127
 
                display_url = urlutils.unescape_for_display(stored_loc,
128
 
                        self.outf.encoding)
129
 
                self.outf.write("Using saved location: %s\n" % display_url)
130
 
                location = stored_loc
131
 
 
132
 
        bzrdir = BzrDir.open(location)
133
 
        target_branch = bzrdir.open_branch()
134
 
        target_branch.lock_write()
135
 
        revid_map = source_branch.dpush(target_branch)
136
 
        # We successfully created the target, remember it
137
 
        if source_branch.get_push_location() is None or remember:
138
 
            source_branch.set_push_location(target_branch.base)
139
 
        if not no_rebase:
140
 
            _, old_last_revid = source_branch.last_revision_info()
141
 
            new_last_revid = revid_map[old_last_revid]
142
 
            if source_wt is not None:
143
 
                source_wt.pull(target_branch, overwrite=True, 
144
 
                               stop_revision=new_last_revid)
145
 
            else:
146
 
                source_branch.pull(target_branch, overwrite=True, 
147
 
                                   stop_revision=new_last_revid)
148
 
 
149
 
 
150