~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008-2012 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
 
 
18
17
"""Foreign branch utilities."""
19
18
 
 
19
from __future__ import absolute_import
 
20
 
20
21
 
21
22
from bzrlib.branch import (
22
23
    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,
33
32
    registry,
34
33
    transform,
35
34
    )
 
35
from bzrlib.i18n import gettext
36
36
""")
37
37
 
38
38
class VcsMapping(object):
225
225
        """Get the default mapping for this repository."""
226
226
        raise NotImplementedError(self.get_default_mapping)
227
227
 
228
 
    def get_inventory_xml(self, revision_id):
229
 
        """See Repository.get_inventory_xml()."""
230
 
        return self.serialise_inventory(self.get_inventory(revision_id))
231
 
 
232
 
    def get_inventory_sha1(self, revision_id):
233
 
        """Get the sha1 for the XML representation of an inventory.
234
 
 
235
 
        :param revision_id: Revision id of the inventory for which to return
236
 
         the SHA1.
237
 
        :return: XML string
238
 
        """
239
 
 
240
 
        return osutils.sha_string(self.get_inventory_xml(revision_id))
241
 
 
242
 
    def get_revision_xml(self, revision_id):
243
 
        """Return the XML representation of a revision.
244
 
 
245
 
        :param revision_id: Revision for which to return the XML.
246
 
        :return: XML string
247
 
        """
248
 
        return self._serializer.write_revision_to_string(
249
 
            self.get_revision(revision_id))
250
 
 
251
228
 
252
229
class ForeignBranch(Branch):
253
230
    """Branch that exists in a foreign version control system."""
282
259
 
283
260
 
284
261
class cmd_dpush(Command):
285
 
    """Push into a different VCS without any custom bzr metadata.
 
262
    __doc__ = """Push into a different VCS without any custom bzr metadata.
286
263
 
287
264
    This will afterwards rebase the local branch on the remote
288
265
    branch unless the --no-rebase option is used, in which case 
289
266
    the two branches will be out of sync after the push. 
290
267
    """
291
 
    hidden = True
292
268
    takes_args = ['location?']
293
269
    takes_options = [
294
270
        'remember',
307
283
    def run(self, location=None, remember=False, directory=None,
308
284
            no_rebase=False, strict=None):
309
285
        from bzrlib import urlutils
310
 
        from bzrlib.bzrdir import BzrDir
 
286
        from bzrlib.controldir import ControlDir
311
287
        from bzrlib.errors import BzrCommandError, NoWorkingTree
312
288
        from bzrlib.workingtree import WorkingTree
313
289
 
319
295
        except NoWorkingTree:
320
296
            source_branch = Branch.open(directory)
321
297
            source_wt = None
322
 
        if strict is None:
323
 
            strict = source_branch.get_config(
324
 
                ).get_user_option_as_bool('dpush_strict')
325
 
        if strict is None: strict = True # default value
326
 
        if strict and source_wt is not None:
327
 
            if (source_wt.has_changes()):
328
 
                raise errors.UncommittedChanges(
329
 
                    source_wt, more='Use --no-strict to force the push.')
330
 
            if source_wt.last_revision() != source_wt.branch.last_revision():
331
 
                # The tree has lost sync with its branch, there is little
332
 
                # chance that the user is aware of it but he can still force
333
 
                # the push with --no-strict
334
 
                raise errors.OutOfDateTree(
335
 
                    source_wt, more='Use --no-strict to force the push.')
 
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.')
336
303
        stored_loc = source_branch.get_push_location()
337
304
        if location is None:
338
305
            if stored_loc is None:
339
 
                raise BzrCommandError("No push location known or specified.")
 
306
                raise BzrCommandError(gettext("No push location known or specified."))
340
307
            else:
341
308
                display_url = urlutils.unescape_for_display(stored_loc,
342
309
                        self.outf.encoding)
343
 
                self.outf.write("Using saved location: %s\n" % display_url)
 
310
                self.outf.write(
 
311
                       gettext("Using saved location: %s\n") % display_url)
344
312
                location = stored_loc
345
313
 
346
 
        bzrdir = BzrDir.open(location)
347
 
        target_branch = bzrdir.open_branch()
 
314
        controldir = ControlDir.open(location)
 
315
        target_branch = controldir.open_branch()
348
316
        target_branch.lock_write()
349
317
        try:
350
318
            try:
351
 
                push_result = source_branch.lossy_push(target_branch)
 
319
                push_result = source_branch.push(target_branch, lossy=True)
352
320
            except errors.LossyPushToSameVCS:
353
 
                raise BzrCommandError("%r and %r are in the same VCS, lossy "
354
 
                    "push not necessary. Please use regular push." %
355
 
                    (source_branch, target_branch))
 
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))
356
324
            # We successfully created the target, remember it
357
325
            if source_branch.get_push_location() is None or remember:
 
326
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
358
327
                source_branch.set_push_location(target_branch.base)
359
328
            if not no_rebase:
360
329
                old_last_revid = source_branch.last_revision()
371
340
            push_result.report(self.outf)
372
341
        finally:
373
342
            target_branch.unlock()
374
 
 
375
 
 
376
 
class InterToForeignBranch(InterBranch):
377
 
 
378
 
    def lossy_push(self, stop_revision=None):
379
 
        """Push deltas into another branch.
380
 
 
381
 
        :note: This does not, like push, retain the revision ids from 
382
 
            the source branch and will, rather than adding bzr-specific 
383
 
            metadata, push only those semantics of the revision that can be 
384
 
            natively represented by this branch' VCS.
385
 
 
386
 
        :param target: Target branch
387
 
        :param stop_revision: Revision to push, defaults to last revision.
388
 
        :return: BranchPushResult with an extra member revidmap: 
389
 
            A dictionary mapping revision ids from the target branch 
390
 
            to new revision ids in the target branch, for each 
391
 
            revision that was pushed.
392
 
        """
393
 
        raise NotImplementedError(self.lossy_push)