Merge bzr-foreign fix.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 30 Aug 2008 02:32:18 +0000 (04:32 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 30 Aug 2008 02:32:18 +0000 (04:32 +0200)
1  2 
foreign/__init__.py

index 1a449d2315845c5b1074226a9561d25322a68825,0000000000000000000000000000000000000000..64324e069824d83a84fcab5a781d6a627bf33b1b
mode 100644,000000..100644
--- /dev/null
@@@ -1,149 -1,0 +1,149 @@@
-         revid_map = source_branch.dpull(target_branch)
 +# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
 +#
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
 +# the Free Software Foundation; either version 2 of the License, or
 +# (at your option) any later version.
 +#
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
 +#
 +# You should have received a copy of the GNU General Public License
 +# along with this program; if not, write to the Free Software
 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 +
 +"""Foreign branch utilities."""
 +
 +from bzrlib import errors, registry
 +from bzrlib.commands import Command, Option
 +
 +
 +class VcsMapping(object):
 +    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
 +
 +    """
 +    experimental = False
 +    roundtripping = False
 +    revid_prefix = None
 +
 +    def revision_id_bzr_to_foreign(self, bzr_revid):
 +        """Parse a bzr revision id and convert it to a foreign revid.
 +
 +        :param bzr_revid: The bzr revision id (a string).
 +        :return: A foreign revision id, can be any sort of object.
 +        """
 +        raise NotImplementedError(self.revision_id_bzr_to_foreign)
 +
 +    def revision_id_foreign_to_bzr(self, foreign_revid):
 +        """Parse a foreign revision id and convert it to a bzr revid.
 +
 +        :param foreign_revid: Foreign revision id, can be any sort of object.
 +        :return: A bzr revision id.
 +        """
 +        raise NotImplementedError(self.revision_id_foreign_to_bzr)
 +
 +
 +class VcsMappingRegistry(registry.Registry):
 +    """Registry for Bazaar<->foreign VCS mappings.
 +    
 +    There should be one instance of this registry for every foreign VCS.
 +    """
 +
 +    def register(self, key, factory, help):
 +        """Register a mapping between Bazaar and foreign VCS semantics.
 +
 +        The factory must be a callable that takes one parameter: the key.
 +        It must produce an instance of VcsMapping when called.
 +        """
 +        registry.Registry.register(self, key, factory, help)
 +
 +    def set_default(self, key):
 +        """Set the 'default' key to be a clone of the supplied key.
 +
 +        This method must be called once and only once.
 +        """
 +        self._set_default_key(key)
 +
 +    def get_default(self):
 +        """Convenience function for obtaining the default mapping to use."""
 +        return self.get(self._get_default_key())
 +
 +
 +class FakeControlFiles(object):
 +    """Dummy implementation of ControlFiles.
 +    
 +    This is required as some code relies on controlfiles being 
 +    available."""
 +    def get_utf8(self, name):
 +        raise errors.NoSuchFile(name)
 +
 +    def get(self, name):
 +        raise errors.NoSuchFile(name)
 +
 +    def break_lock(self):
 +        pass
 +
 +
 +class cmd_dpush(Command):
 +    """Push diffs into a foreign version control system without any 
 +    Bazaar-specific metadata.
 +
 +    This will afterwards rebase the local Bazaar branch on the remote
 +    branch unless the --no-rebase option is used, in which case 
 +    the two branches will be out of sync. 
 +    """
 +    takes_args = ['location?']
 +    takes_options = ['remember', Option('directory',
 +            help='Branch to push from, '
 +                 'rather than the one containing the working directory.',
 +            short_name='d',
 +            type=unicode,
 +            ),
 +            Option('no-rebase', help="Don't rebase after push")]
 +
 +    def run(self, location=None, remember=False, directory=None, 
 +            no_rebase=False):
 +        from bzrlib import urlutils
 +        from bzrlib.bzrdir import BzrDir
 +        from bzrlib.branch import Branch
 +        from bzrlib.errors import BzrCommandError, NoWorkingTree
 +        from bzrlib.workingtree import WorkingTree
 +
 +        if directory is None:
 +            directory = "."
 +        try:
 +            source_wt = WorkingTree.open_containing(directory)[0]
 +            source_branch = source_wt.branch
 +        except NoWorkingTree:
 +            source_branch = Branch.open_containing(directory)[0]
 +            source_wt = None
 +        stored_loc = source_branch.get_push_location()
 +        if location is None:
 +            if stored_loc is None:
 +                raise BzrCommandError("No push location known or specified.")
 +            else:
 +                display_url = urlutils.unescape_for_display(stored_loc,
 +                        self.outf.encoding)
 +                self.outf.write("Using saved location: %s\n" % display_url)
 +                location = stored_loc
 +
 +        bzrdir = BzrDir.open(location)
 +        target_branch = bzrdir.open_branch()
 +        target_branch.lock_write()
++        revid_map = target_branch.dpull(source_branch)
 +        # We successfully created the target, remember it
 +        if source_branch.get_push_location() is None or remember:
 +            source_branch.set_push_location(target_branch.base)
 +        if not no_rebase:
 +            _, old_last_revid = source_branch.last_revision_info()
 +            new_last_revid = revid_map[old_last_revid]
 +            if source_wt is not None:
 +                source_wt.pull(target_branch, overwrite=True, 
 +                               stop_revision=new_last_revid)
 +            else:
 +                source_branch.pull(target_branch, overwrite=True, 
 +                                   stop_revision=new_last_revid)
 +
 +