~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/foreign.py

  • Committer: John Arbash Meinel
  • Date: 2009-05-29 09:59:25 UTC
  • mto: This revision was merged to the branch mainline in revision 4392.
  • Revision ID: john@arbash-meinel.com-20090529095925-d1cvs7nugqh3iy48
A bit more review feedback from Andrew.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008 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
36
36
""")
37
37
 
38
38
class VcsMapping(object):
39
 
    """Describes the mapping between the semantics of Bazaar and a foreign VCS.
 
39
    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
40
40
 
41
41
    """
42
42
    # Whether this is an experimental mapping that is still open to changes.
45
45
    # Whether this mapping supports exporting and importing all bzr semantics.
46
46
    roundtripping = False
47
47
 
48
 
    # Prefix used when importing revisions native to the foreign VCS (as
49
 
    # opposed to roundtripping bzr-native revisions) using this mapping.
 
48
    # Prefix used when importing native foreign revisions (not roundtripped)
 
49
    # using this mapping.
50
50
    revid_prefix = None
51
51
 
52
52
    def __init__(self, vcs):
119
119
        self.mapping = mapping
120
120
 
121
121
 
 
122
def show_foreign_properties(rev):
 
123
    """Custom log displayer for foreign revision identifiers.
 
124
 
 
125
    :param rev: Revision object.
 
126
    """
 
127
    # Revision comes directly from a foreign repository
 
128
    if isinstance(rev, ForeignRevision):
 
129
        return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
 
130
 
 
131
    # Revision was once imported from a foreign repository
 
132
    try:
 
133
        foreign_revid, mapping = \
 
134
            foreign_vcs_registry.parse_revision_id(rev.revision_id)
 
135
    except errors.InvalidRevisionId:
 
136
        return {}
 
137
 
 
138
    return mapping.vcs.show_foreign_revid(foreign_revid)
 
139
 
 
140
 
122
141
class ForeignVcs(object):
123
142
    """A foreign version control system."""
124
143
 
125
 
    branch_format = None
126
 
 
127
 
    repository_format = None
128
 
 
129
 
    def __init__(self, mapping_registry, abbreviation=None):
130
 
        """Create a new foreign vcs instance.
131
 
 
132
 
        :param mapping_registry: Registry with mappings for this VCS.
133
 
        :param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
134
 
        """
135
 
        self.abbreviation = abbreviation
 
144
    def __init__(self, mapping_registry):
136
145
        self.mapping_registry = mapping_registry
137
146
 
138
147
    def show_foreign_revid(self, foreign_revid):
143
152
        """
144
153
        return { }
145
154
 
146
 
    def serialize_foreign_revid(self, foreign_revid):
147
 
        """Serialize a foreign revision id for this VCS.
148
 
 
149
 
        :param foreign_revid: Foreign revision id
150
 
        :return: Bytestring with serialized revid, will not contain any 
151
 
            newlines.
152
 
        """
153
 
        raise NotImplementedError(self.serialize_foreign_revid)
154
 
 
155
155
 
156
156
class ForeignVcsRegistry(registry.Registry):
157
157
    """Registry for Foreign VCSes.
179
179
        :param revid: The bzr revision id
180
180
        :return: tuple with foreign revid and vcs mapping
181
181
        """
182
 
        if not ":" in revid or not "-" in revid:
 
182
        if not "-" in revid:
183
183
            raise errors.InvalidRevisionId(revid, None)
184
184
        try:
185
185
            foreign_vcs = self.get(revid.split("-")[0])
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
 
228
251
 
229
252
class ForeignBranch(Branch):
230
253
    """Branch that exists in a foreign version control system."""
259
282
 
260
283
 
261
284
class cmd_dpush(Command):
262
 
    __doc__ = """Push into a different VCS without any custom bzr metadata.
 
285
    """Push into a different VCS without any custom bzr metadata.
263
286
 
264
287
    This will afterwards rebase the local branch on the remote
265
288
    branch unless the --no-rebase option is used, in which case 
267
290
    """
268
291
    hidden = True
269
292
    takes_args = ['location?']
270
 
    takes_options = [
271
 
        'remember',
272
 
        Option('directory',
273
 
               help='Branch to push from, '
274
 
               'rather than the one containing the working directory.',
275
 
               short_name='d',
276
 
               type=unicode,
277
 
               ),
278
 
        Option('no-rebase', help="Do not rebase after push."),
279
 
        Option('strict',
280
 
               help='Refuse to push if there are uncommitted changes in'
281
 
               ' the working tree, --no-strict disables the check.'),
282
 
        ]
 
293
    takes_options = ['remember', Option('directory',
 
294
            help='Branch to push from, '
 
295
                 'rather than the one containing the working directory.',
 
296
            short_name='d',
 
297
            type=unicode,
 
298
            ),
 
299
            Option('no-rebase', help="Do not rebase after push.")]
283
300
 
284
 
    def run(self, location=None, remember=False, directory=None,
285
 
            no_rebase=False, strict=None):
 
301
    def run(self, location=None, remember=False, directory=None, 
 
302
            no_rebase=False):
286
303
        from bzrlib import urlutils
287
304
        from bzrlib.bzrdir import BzrDir
288
305
        from bzrlib.errors import BzrCommandError, NoWorkingTree
 
306
        from bzrlib.trace import info
289
307
        from bzrlib.workingtree import WorkingTree
290
308
 
291
309
        if directory is None:
296
314
        except NoWorkingTree:
297
315
            source_branch = Branch.open(directory)
298
316
            source_wt = None
299
 
        if source_wt is not None:
300
 
            source_wt.check_changed_or_out_of_date(
301
 
                strict, 'dpush_strict',
302
 
                more_error='Use --no-strict to force the push.',
303
 
                more_warning='Uncommitted changes will not be pushed.')
304
317
        stored_loc = source_branch.get_push_location()
305
318
        if location is None:
306
319
            if stored_loc is None: