~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-03-25 00:02:51 UTC
  • mfrom: (5106.1.1 version-bump)
  • Revision ID: pqm@pqm.ubuntu.com-20100325000251-bwsv5c5d3l9x3lnn
(Jelmer) Bump API version for 2.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Foreign branch utilities."""
18
19
 
19
 
from __future__ import absolute_import
20
 
 
21
20
 
22
21
from bzrlib.branch import (
23
22
    Branch,
 
23
    InterBranch,
24
24
    )
25
25
from bzrlib.commands import Command, Option
26
26
from bzrlib.repository import Repository
29
29
lazy_import(globals(), """
30
30
from bzrlib import (
31
31
    errors,
 
32
    osutils,
32
33
    registry,
33
34
    transform,
34
35
    )
35
 
from bzrlib.i18n import gettext
36
36
""")
37
37
 
38
38
class VcsMapping(object):
259
259
 
260
260
 
261
261
class cmd_dpush(Command):
262
 
    __doc__ = """Push into a different VCS without any custom bzr metadata.
 
262
    """Push into a different VCS without any custom bzr metadata.
263
263
 
264
264
    This will afterwards rebase the local branch on the remote
265
265
    branch unless the --no-rebase option is used, in which case 
266
266
    the two branches will be out of sync after the push. 
267
267
    """
 
268
    hidden = True
268
269
    takes_args = ['location?']
269
270
    takes_options = [
270
271
        'remember',
283
284
    def run(self, location=None, remember=False, directory=None,
284
285
            no_rebase=False, strict=None):
285
286
        from bzrlib import urlutils
286
 
        from bzrlib.controldir import ControlDir
 
287
        from bzrlib.bzrdir import BzrDir
287
288
        from bzrlib.errors import BzrCommandError, NoWorkingTree
288
289
        from bzrlib.workingtree import WorkingTree
289
290
 
295
296
        except NoWorkingTree:
296
297
            source_branch = Branch.open(directory)
297
298
            source_wt = None
298
 
        if source_wt is not None:
299
 
            source_wt.check_changed_or_out_of_date(
300
 
                strict, 'dpush_strict',
301
 
                more_error='Use --no-strict to force the push.',
302
 
                more_warning='Uncommitted changes will not be pushed.')
 
299
        if strict is None:
 
300
            strict = source_branch.get_config(
 
301
                ).get_user_option_as_bool('dpush_strict')
 
302
        if strict is None: strict = True # default value
 
303
        if strict and source_wt is not None:
 
304
            if (source_wt.has_changes()):
 
305
                raise errors.UncommittedChanges(
 
306
                    source_wt, more='Use --no-strict to force the push.')
 
307
            if source_wt.last_revision() != source_wt.branch.last_revision():
 
308
                # The tree has lost sync with its branch, there is little
 
309
                # chance that the user is aware of it but he can still force
 
310
                # the push with --no-strict
 
311
                raise errors.OutOfDateTree(
 
312
                    source_wt, more='Use --no-strict to force the push.')
303
313
        stored_loc = source_branch.get_push_location()
304
314
        if location is None:
305
315
            if stored_loc is None:
306
 
                raise BzrCommandError(gettext("No push location known or specified."))
 
316
                raise BzrCommandError("No push location known or specified.")
307
317
            else:
308
318
                display_url = urlutils.unescape_for_display(stored_loc,
309
319
                        self.outf.encoding)
310
 
                self.outf.write(
311
 
                       gettext("Using saved location: %s\n") % display_url)
 
320
                self.outf.write("Using saved location: %s\n" % display_url)
312
321
                location = stored_loc
313
322
 
314
 
        controldir = ControlDir.open(location)
315
 
        target_branch = controldir.open_branch()
 
323
        bzrdir = BzrDir.open(location)
 
324
        target_branch = bzrdir.open_branch()
316
325
        target_branch.lock_write()
317
326
        try:
318
327
            try:
319
 
                push_result = source_branch.push(target_branch, lossy=True)
 
328
                push_result = source_branch.lossy_push(target_branch)
320
329
            except errors.LossyPushToSameVCS:
321
 
                raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy "
322
 
                    "push not necessary. Please use regular push.").format(
323
 
                    source_branch, target_branch))
 
330
                raise BzrCommandError("%r and %r are in the same VCS, lossy "
 
331
                    "push not necessary. Please use regular push." %
 
332
                    (source_branch, target_branch))
324
333
            # We successfully created the target, remember it
325
334
            if source_branch.get_push_location() is None or remember:
326
 
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
327
335
                source_branch.set_push_location(target_branch.base)
328
336
            if not no_rebase:
329
337
                old_last_revid = source_branch.last_revision()
340
348
            push_result.report(self.outf)
341
349
        finally:
342
350
            target_branch.unlock()
 
351
 
 
352
 
 
353
class InterToForeignBranch(InterBranch):
 
354
 
 
355
    def lossy_push(self, stop_revision=None):
 
356
        """Push deltas into another branch.
 
357
 
 
358
        :note: This does not, like push, retain the revision ids from 
 
359
            the source branch and will, rather than adding bzr-specific 
 
360
            metadata, push only those semantics of the revision that can be 
 
361
            natively represented by this branch' VCS.
 
362
 
 
363
        :param target: Target branch
 
364
        :param stop_revision: Revision to push, defaults to last revision.
 
365
        :return: BranchPushResult with an extra member revidmap: 
 
366
            A dictionary mapping revision ids from the target branch 
 
367
            to new revision ids in the target branch, for each 
 
368
            revision that was pushed.
 
369
        """
 
370
        raise NotImplementedError(self.lossy_push)