/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2008-11-25 03:16:20 UTC
  • mto: (0.219.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20081125031620-h4plmbufgsdjcqiw
Remove elements pending to be included in bzrlib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
""")
32
32
 
33
33
 
34
 
class VcsMapping(object):
35
 
    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
36
 
 
37
 
    """
38
 
    # Whether this is an experimental mapping that is still open to changes.
39
 
    experimental = False
40
 
 
41
 
    # Whether this mapping supports exporting and importing all bzr semantics.
42
 
    roundtripping = False
43
 
 
44
 
    # Prefix used when importing native foreign revisions (not roundtripped) 
45
 
    # using this mapping.
46
 
    revid_prefix = None
47
 
 
48
 
    def revision_id_bzr_to_foreign(self, bzr_revid):
49
 
        """Parse a bzr revision id and convert it to a foreign revid.
50
 
 
51
 
        :param bzr_revid: The bzr revision id (a string).
52
 
        :return: A foreign revision id, can be any sort of object.
53
 
        """
54
 
        raise NotImplementedError(self.revision_id_bzr_to_foreign)
55
 
 
56
 
    def revision_id_foreign_to_bzr(self, foreign_revid):
57
 
        """Parse a foreign revision id and convert it to a bzr revid.
58
 
 
59
 
        :param foreign_revid: Foreign revision id, can be any sort of object.
60
 
        :return: A bzr revision id.
61
 
        """
62
 
        raise NotImplementedError(self.revision_id_foreign_to_bzr)
63
 
 
64
 
    def show_foreign_revid(self, foreign_revid):
65
 
        """Prepare a foreign revision id for formatting using bzr log.
66
 
        
67
 
        :param foreign_revid: Foreign revision id.
68
 
        :return: Dictionary mapping string keys to string values.
69
 
        """
70
 
        # TODO: This could be on ForeignVcs instead
71
 
        return { }
72
 
 
73
 
 
74
 
class VcsMappingRegistry(registry.Registry):
75
 
    """Registry for Bazaar<->foreign VCS mappings.
76
 
    
77
 
    There should be one instance of this registry for every foreign VCS.
78
 
    """
79
 
 
80
 
    def register(self, key, factory, help):
81
 
        """Register a mapping between Bazaar and foreign VCS semantics.
82
 
 
83
 
        The factory must be a callable that takes one parameter: the key.
84
 
        It must produce an instance of VcsMapping when called.
85
 
        """
86
 
        if ":" in key:
87
 
            raise ValueError("mapping name can not contain colon (:)")
88
 
        registry.Registry.register(self, key, factory, help)
89
 
 
90
 
    def set_default(self, key):
91
 
        """Set the 'default' key to be a clone of the supplied key.
92
 
 
93
 
        This method must be called once and only once.
94
 
        """
95
 
        self._set_default_key(key)
96
 
 
97
 
    def get_default(self):
98
 
        """Convenience function for obtaining the default mapping to use."""
99
 
        return self.get(self._get_default_key())
100
 
 
101
 
    def revision_id_bzr_to_foreign(self, revid):
102
 
        """Convert a bzr revision id to a foreign revid."""
103
 
        raise NotImplementedError(self.revision_id_bzr_to_foreign)
104
 
 
105
 
 
106
34
class ForeignBranch(Branch):
107
35
    """Branch that exists in a foreign version control system."""
108
36
 
124
52
        raise NotImplementedError(self.pull)
125
53
 
126
54
 
127
 
class ForeignRepository(repository.Repository):
 
55
class ForeignRepository(Repository):
128
56
 
129
57
    def has_foreign_revision(self, foreign_revid):
130
58
        raise NotImplementedError(self.has_foreign_revision)
270
198
    return message
271
199
 
272
200
 
273
 
class ForeignRevision(Revision):
274
 
    """A Revision from a Foreign repository. Remembers 
275
 
    information about foreign revision id and mapping.
276
 
 
277
 
    """
278
 
 
279
 
    def __init__(self, foreign_revid, mapping, *args, **kwargs):
280
 
        if not "inventory_sha1" in kwargs:
281
 
            kwargs["inventory_sha1"] = ""
282
 
        super(ForeignRevision, self).__init__(*args, **kwargs)
283
 
        self.foreign_revid = foreign_revid
284
 
        self.mapping = mapping
285
 
 
286
 
 
287
 
def show_foreign_properties(rev):
288
 
    """Custom log displayer for foreign revision identifiers.
289
 
 
290
 
    :param rev: Revision object.
291
 
    """
292
 
    # Revision comes directly from a foreign repository
293
 
    if isinstance(rev, ForeignRevision):
294
 
        return rev.mapping.show_foreign_revid(rev.foreign_revid)
295
 
 
296
 
    # Revision was once imported from a foreign repository
297
 
    try:
298
 
        foreign_revid, mapping = \
299
 
            foreign_vcs_registry.parse_revision_id(rev.revision_id)
300
 
    except errors.InvalidRevisionId:
301
 
        return {}
302
 
 
303
 
    return mapping.show_foreign_revid(foreign_revid)
304
 
 
305
 
 
306
 
class ForeignVcs(object):
307
 
    """A foreign version control system."""
308
 
 
309
 
    def __init__(self, mapping_registry):
310
 
        self.mapping_registry = mapping_registry
311
 
 
312
 
 
313
 
class ForeignVcsRegistry(registry.Registry):
314
 
    """Registry for Foreign VCSes.
315
 
 
316
 
    There should be one entry per foreign VCS. Example entries would be 
317
 
    "git", "svn", "hg", "darcs", etc.
318
 
 
319
 
    """
320
 
 
321
 
    def register(self, key, foreign_vcs, help):
322
 
        """Register a foreign VCS.
323
 
 
324
 
        :param key: Prefix of the foreign VCS in revision ids
325
 
        :param foreign_vcs: ForeignVCS instance
326
 
        :param help: Description of the foreign VCS
327
 
        """
328
 
        if ":" in key or "-" in key:
329
 
            raise ValueError("vcs name can not contain : or -")
330
 
        registry.Registry.register(self, key, foreign_vcs, help)
331
 
 
332
 
    def parse_revision_id(self, revid):
333
 
        """Parse a bzr revision and return the matching mapping and foreign 
334
 
        revid.
335
 
        
336
 
        :param revid: The bzr revision id
337
 
        :return: tuple with foreign revid and vcs mapping
338
 
        """
339
 
        if not "-" in revid:
340
 
            raise errors.InvalidRevisionId(revid, None)
341
 
        try:
342
 
            foreign_vcs = self.get(revid.split("-")[0])
343
 
        except KeyError:
344
 
            raise errors.InvalidRevisionId(revid, None)
345
 
        return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid)
346
 
 
347
 
 
348
 
if not "foreign" in log.properties_handler_registry:
349
 
    log.properties_handler_registry.register("foreign",
350
 
                                             show_foreign_properties,
351
 
                                             "Show foreign VCS properties")
352
 
 
353
 
foreign_vcs_registry = ForeignVcsRegistry()