~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: INADA Naoki
  • Date: 2011-05-18 06:27:34 UTC
  • mfrom: (5887 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5894.
  • Revision ID: songofacandy@gmail.com-20110518062734-1ilhll0rrqyyp8um
merge from lp:bzr and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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
20
20
 
21
21
from bzrlib.branch import (
22
22
    Branch,
23
 
    InterBranch,
24
23
    )
25
24
from bzrlib.commands import Command, Option
26
25
from bzrlib.repository import Repository
29
28
lazy_import(globals(), """
30
29
from bzrlib import (
31
30
    errors,
32
 
    osutils,
33
31
    registry,
34
32
    transform,
35
33
    )
36
34
""")
37
35
 
38
36
class VcsMapping(object):
39
 
    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
 
37
    """Describes the mapping between the semantics of Bazaar and a foreign VCS.
40
38
 
41
39
    """
42
40
    # Whether this is an experimental mapping that is still open to changes.
122
120
class ForeignVcs(object):
123
121
    """A foreign version control system."""
124
122
 
125
 
    def __init__(self, mapping_registry):
 
123
    branch_format = None
 
124
 
 
125
    repository_format = None
 
126
 
 
127
    def __init__(self, mapping_registry, abbreviation=None):
 
128
        """Create a new foreign vcs instance.
 
129
 
 
130
        :param mapping_registry: Registry with mappings for this VCS.
 
131
        :param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
 
132
        """
 
133
        self.abbreviation = abbreviation
126
134
        self.mapping_registry = mapping_registry
127
135
 
128
136
    def show_foreign_revid(self, foreign_revid):
133
141
        """
134
142
        return { }
135
143
 
 
144
    def serialize_foreign_revid(self, foreign_revid):
 
145
        """Serialize a foreign revision id for this VCS.
 
146
 
 
147
        :param foreign_revid: Foreign revision id
 
148
        :return: Bytestring with serialized revid, will not contain any 
 
149
            newlines.
 
150
        """
 
151
        raise NotImplementedError(self.serialize_foreign_revid)
 
152
 
136
153
 
137
154
class ForeignVcsRegistry(registry.Registry):
138
155
    """Registry for Foreign VCSes.
206
223
        """Get the default mapping for this repository."""
207
224
        raise NotImplementedError(self.get_default_mapping)
208
225
 
209
 
    def get_inventory_xml(self, revision_id):
210
 
        """See Repository.get_inventory_xml()."""
211
 
        return self.serialise_inventory(self.get_inventory(revision_id))
212
 
 
213
 
    def get_inventory_sha1(self, revision_id):
214
 
        """Get the sha1 for the XML representation of an inventory.
215
 
 
216
 
        :param revision_id: Revision id of the inventory for which to return
217
 
         the SHA1.
218
 
        :return: XML string
219
 
        """
220
 
 
221
 
        return osutils.sha_string(self.get_inventory_xml(revision_id))
222
 
 
223
 
    def get_revision_xml(self, revision_id):
224
 
        """Return the XML representation of a revision.
225
 
 
226
 
        :param revision_id: Revision for which to return the XML.
227
 
        :return: XML string
228
 
        """
229
 
        return self._serializer.write_revision_to_string(
230
 
            self.get_revision(revision_id))
231
 
 
232
226
 
233
227
class ForeignBranch(Branch):
234
228
    """Branch that exists in a foreign version control system."""
263
257
 
264
258
 
265
259
class cmd_dpush(Command):
266
 
    """Push into a different VCS without any custom bzr metadata.
 
260
    __doc__ = """Push into a different VCS without any custom bzr metadata.
267
261
 
268
262
    This will afterwards rebase the local branch on the remote
269
263
    branch unless the --no-rebase option is used, in which case 
271
265
    """
272
266
    hidden = True
273
267
    takes_args = ['location?']
274
 
    takes_options = ['remember', Option('directory',
275
 
            help='Branch to push from, '
276
 
                 'rather than the one containing the working directory.',
277
 
            short_name='d',
278
 
            type=unicode,
279
 
            ),
280
 
            Option('no-rebase', help="Do not rebase after push.")]
 
268
    takes_options = [
 
269
        'remember',
 
270
        Option('directory',
 
271
               help='Branch to push from, '
 
272
               'rather than the one containing the working directory.',
 
273
               short_name='d',
 
274
               type=unicode,
 
275
               ),
 
276
        Option('no-rebase', help="Do not rebase after push."),
 
277
        Option('strict',
 
278
               help='Refuse to push if there are uncommitted changes in'
 
279
               ' the working tree, --no-strict disables the check.'),
 
280
        ]
281
281
 
282
 
    def run(self, location=None, remember=False, directory=None, 
283
 
            no_rebase=False):
 
282
    def run(self, location=None, remember=False, directory=None,
 
283
            no_rebase=False, strict=None):
284
284
        from bzrlib import urlutils
285
285
        from bzrlib.bzrdir import BzrDir
286
286
        from bzrlib.errors import BzrCommandError, NoWorkingTree
287
 
        from bzrlib.trace import info
288
287
        from bzrlib.workingtree import WorkingTree
289
288
 
290
289
        if directory is None:
295
294
        except NoWorkingTree:
296
295
            source_branch = Branch.open(directory)
297
296
            source_wt = None
 
297
        if source_wt is not None:
 
298
            source_wt.check_changed_or_out_of_date(
 
299
                strict, 'dpush_strict',
 
300
                more_error='Use --no-strict to force the push.',
 
301
                more_warning='Uncommitted changes will not be pushed.')
298
302
        stored_loc = source_branch.get_push_location()
299
303
        if location is None:
300
304
            if stored_loc is None:
310
314
        target_branch.lock_write()
311
315
        try:
312
316
            try:
313
 
                push_result = source_branch.lossy_push(target_branch)
 
317
                push_result = source_branch.push(target_branch, lossy=True)
314
318
            except errors.LossyPushToSameVCS:
315
319
                raise BzrCommandError("%r and %r are in the same VCS, lossy "
316
320
                    "push not necessary. Please use regular push." %
333
337
            push_result.report(self.outf)
334
338
        finally:
335
339
            target_branch.unlock()
336
 
 
337
 
 
338
 
class InterToForeignBranch(InterBranch):
339
 
 
340
 
    def lossy_push(self, stop_revision=None):
341
 
        """Push deltas into another branch.
342
 
 
343
 
        :note: This does not, like push, retain the revision ids from 
344
 
            the source branch and will, rather than adding bzr-specific 
345
 
            metadata, push only those semantics of the revision that can be 
346
 
            natively represented by this branch' VCS.
347
 
 
348
 
        :param target: Target branch
349
 
        :param stop_revision: Revision to push, defaults to last revision.
350
 
        :return: BranchPushResult with an extra member revidmap: 
351
 
            A dictionary mapping revision ids from the target branch 
352
 
            to new revision ids in the target branch, for each 
353
 
            revision that was pushed.
354
 
        """
355
 
        raise NotImplementedError(self.lossy_push)