bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6404.6.1
by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. |
1 |
# Copyright (C) 2008-2012 Canonical Ltd
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3918.2.2
by Martin Pool
Add import statement |
16 |
|
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
17 |
"""Foreign branch utilities."""
|
18 |
||
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
19 |
from __future__ import absolute_import |
3918.2.2
by Martin Pool
Add import statement |
20 |
|
21 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
22 |
from .branch import ( |
4347.2.1
by Jelmer Vernooij
Move dpush onto an InterBranch object. |
23 |
Branch, |
24 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
25 |
from .repository import Repository |
26 |
from .revision import Revision |
|
27 |
from .lazy_import import lazy_import |
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
28 |
lazy_import(globals(), """ |
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
29 |
from breezy import (
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
30 |
errors,
|
31 |
registry,
|
|
32 |
)
|
|
33 |
""") |
|
34 |
||
35 |
class VcsMapping(object): |
|
4585.1.7
by Jelmer Vernooij
Use scenarios and adapters. |
36 |
"""Describes the mapping between the semantics of Bazaar and a foreign VCS. |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
37 |
|
38 |
"""
|
|
39 |
# Whether this is an experimental mapping that is still open to changes.
|
|
40 |
experimental = False |
|
41 |
||
42 |
# Whether this mapping supports exporting and importing all bzr semantics.
|
|
43 |
roundtripping = False |
|
44 |
||
4531.2.1
by Samuel Bronson
Clarify comment about bzrlib.foreign.VcsMapping's variable revid_prefix. |
45 |
# Prefix used when importing revisions native to the foreign VCS (as
|
46 |
# opposed to roundtripping bzr-native revisions) using this mapping.
|
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
47 |
revid_prefix = None |
48 |
||
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
49 |
def __init__(self, vcs): |
50 |
"""Create a new VcsMapping. |
|
51 |
||
52 |
:param vcs: VCS that this mapping maps to Bazaar
|
|
53 |
"""
|
|
54 |
self.vcs = vcs |
|
55 |
||
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
56 |
def revision_id_bzr_to_foreign(self, bzr_revid): |
57 |
"""Parse a bzr revision id and convert it to a foreign revid. |
|
58 |
||
59 |
:param bzr_revid: The bzr revision id (a string).
|
|
60 |
:return: A foreign revision id, can be any sort of object.
|
|
61 |
"""
|
|
62 |
raise NotImplementedError(self.revision_id_bzr_to_foreign) |
|
63 |
||
64 |
def revision_id_foreign_to_bzr(self, foreign_revid): |
|
65 |
"""Parse a foreign revision id and convert it to a bzr revid. |
|
66 |
||
67 |
:param foreign_revid: Foreign revision id, can be any sort of object.
|
|
68 |
:return: A bzr revision id.
|
|
69 |
"""
|
|
70 |
raise NotImplementedError(self.revision_id_foreign_to_bzr) |
|
71 |
||
72 |
||
73 |
class VcsMappingRegistry(registry.Registry): |
|
74 |
"""Registry for Bazaar<->foreign VCS mappings. |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
75 |
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
76 |
There should be one instance of this registry for every foreign VCS.
|
77 |
"""
|
|
78 |
||
79 |
def register(self, key, factory, help): |
|
80 |
"""Register a mapping between Bazaar and foreign VCS semantics. |
|
81 |
||
82 |
The factory must be a callable that takes one parameter: the key.
|
|
83 |
It must produce an instance of VcsMapping when called.
|
|
84 |
"""
|
|
7045.2.9
by Jelmer Vernooij
Fix some foreign branch tests. |
85 |
if b":" in key: |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
86 |
raise ValueError("mapping name can not contain colon (:)") |
87 |
registry.Registry.register(self, key, factory, help) |
|
88 |
||
89 |
def set_default(self, key): |
|
90 |
"""Set the 'default' key to be a clone of the supplied key. |
|
91 |
||
92 |
This method must be called once and only once.
|
|
93 |
"""
|
|
94 |
self._set_default_key(key) |
|
95 |
||
96 |
def get_default(self): |
|
97 |
"""Convenience function for obtaining the default mapping to use.""" |
|
98 |
return self.get(self._get_default_key()) |
|
99 |
||
100 |
def revision_id_bzr_to_foreign(self, revid): |
|
101 |
"""Convert a bzr revision id to a foreign revid.""" |
|
102 |
raise NotImplementedError(self.revision_id_bzr_to_foreign) |
|
103 |
||
104 |
||
105 |
class ForeignRevision(Revision): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
106 |
"""A Revision from a Foreign repository. Remembers |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
107 |
information about foreign revision id and mapping.
|
108 |
||
109 |
"""
|
|
110 |
||
111 |
def __init__(self, foreign_revid, mapping, *args, **kwargs): |
|
3830.4.4
by Jelmer Vernooij
make inventory_sha1 default to an empty string. |
112 |
if not "inventory_sha1" in kwargs: |
7045.2.9
by Jelmer Vernooij
Fix some foreign branch tests. |
113 |
kwargs["inventory_sha1"] = b"" |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
114 |
super(ForeignRevision, self).__init__(*args, **kwargs) |
115 |
self.foreign_revid = foreign_revid |
|
116 |
self.mapping = mapping |
|
117 |
||
118 |
||
119 |
class ForeignVcs(object): |
|
120 |
"""A foreign version control system.""" |
|
121 |
||
4585.1.10
by Jelmer Vernooij
Store only a single branch format per foreign VCS (for now). |
122 |
branch_format = None |
4585.1.8
by Jelmer Vernooij
Make branch formats provide a factory for particular situations. |
123 |
|
4585.1.11
by Jelmer Vernooij
Add tests for foreign repository formats. |
124 |
repository_format = None |
125 |
||
4747.2.1
by Jelmer Vernooij
Allow specifying an abbreviation for foreign vcs'es and an optional function to serialize foreign revision ids. |
126 |
def __init__(self, mapping_registry, abbreviation=None): |
127 |
"""Create a new foreign vcs instance. |
|
128 |
||
129 |
:param mapping_registry: Registry with mappings for this VCS.
|
|
130 |
:param abbreviation: Optional abbreviation ('bzr', 'svn', 'git', etc)
|
|
131 |
"""
|
|
132 |
self.abbreviation = abbreviation |
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
133 |
self.mapping_registry = mapping_registry |
134 |
||
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
135 |
def show_foreign_revid(self, foreign_revid): |
136 |
"""Prepare a foreign revision id for formatting using bzr log. |
|
4032.1.1
by John Arbash Meinel
Merge the removal of all trailing whitespace, and resolve conflicts. |
137 |
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
138 |
:param foreign_revid: Foreign revision id.
|
139 |
:return: Dictionary mapping string keys to string values.
|
|
140 |
"""
|
|
141 |
return { } |
|
142 |
||
4747.2.1
by Jelmer Vernooij
Allow specifying an abbreviation for foreign vcs'es and an optional function to serialize foreign revision ids. |
143 |
def serialize_foreign_revid(self, foreign_revid): |
144 |
"""Serialize a foreign revision id for this VCS. |
|
145 |
||
146 |
:param foreign_revid: Foreign revision id
|
|
147 |
:return: Bytestring with serialized revid, will not contain any
|
|
148 |
newlines.
|
|
149 |
"""
|
|
150 |
raise NotImplementedError(self.serialize_foreign_revid) |
|
151 |
||
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
152 |
|
153 |
class ForeignVcsRegistry(registry.Registry): |
|
154 |
"""Registry for Foreign VCSes. |
|
155 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
156 |
There should be one entry per foreign VCS. Example entries would be
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
157 |
"git", "svn", "hg", "darcs", etc.
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
158 |
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
159 |
"""
|
160 |
||
161 |
def register(self, key, foreign_vcs, help): |
|
162 |
"""Register a foreign VCS. |
|
163 |
||
164 |
:param key: Prefix of the foreign VCS in revision ids
|
|
165 |
:param foreign_vcs: ForeignVCS instance
|
|
166 |
:param help: Description of the foreign VCS
|
|
167 |
"""
|
|
7143.14.2
by Jelmer Vernooij
Fix test. |
168 |
if ":" in key or "-" in key: |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
169 |
raise ValueError("vcs name can not contain : or -") |
170 |
registry.Registry.register(self, key, foreign_vcs, help) |
|
171 |
||
172 |
def parse_revision_id(self, revid): |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
173 |
"""Parse a bzr revision and return the matching mapping and foreign |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
174 |
revid.
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
175 |
|
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
176 |
:param revid: The bzr revision id
|
177 |
:return: tuple with foreign revid and vcs mapping
|
|
178 |
"""
|
|
7045.2.9
by Jelmer Vernooij
Fix some foreign branch tests. |
179 |
if b":" not in revid or b"-" not in revid: |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
180 |
raise errors.InvalidRevisionId(revid, None) |
181 |
try: |
|
7143.14.1
by Jelmer Vernooij
Fix parsing of foreign commits. |
182 |
foreign_vcs = self.get(revid.split(b"-")[0].decode('ascii')) |
3830.4.1
by Jelmer Vernooij
Add base classes for foreign branches. |
183 |
except KeyError: |
184 |
raise errors.InvalidRevisionId(revid, None) |
|
185 |
return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid) |
|
186 |
||
187 |
||
188 |
foreign_vcs_registry = ForeignVcsRegistry() |
|
3878.5.1
by Jelmer Vernooij
Add a ForeignRepository base class. |
189 |
|
190 |
||
191 |
class ForeignRepository(Repository): |
|
192 |
"""A Repository that exists in a foreign version control system. |
|
193 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
194 |
The data in this repository can not be represented natively using
|
3878.5.1
by Jelmer Vernooij
Add a ForeignRepository base class. |
195 |
Bazaars internal datastructures, but have to converted using a VcsMapping.
|
196 |
"""
|
|
197 |
||
198 |
# This repository's native version control system
|
|
199 |
vcs = None |
|
200 |
||
201 |
def has_foreign_revision(self, foreign_revid): |
|
202 |
"""Check whether the specified foreign revision is present. |
|
203 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
204 |
:param foreign_revid: A foreign revision id, in the format used
|
3878.5.1
by Jelmer Vernooij
Add a ForeignRepository base class. |
205 |
by this Repository's VCS.
|
206 |
"""
|
|
207 |
raise NotImplementedError(self.has_foreign_revision) |
|
208 |
||
209 |
def lookup_bzr_revision_id(self, revid): |
|
210 |
"""Lookup a mapped or roundtripped revision by revision id. |
|
211 |
||
212 |
:param revid: Bazaar revision id
|
|
213 |
:return: Tuple with foreign revision id and mapping.
|
|
214 |
"""
|
|
215 |
raise NotImplementedError(self.lookup_revision_id) |
|
216 |
||
217 |
def all_revision_ids(self, mapping=None): |
|
218 |
"""See Repository.all_revision_ids().""" |
|
219 |
raise NotImplementedError(self.all_revision_ids) |
|
220 |
||
221 |
def get_default_mapping(self): |
|
222 |
"""Get the default mapping for this repository.""" |
|
223 |
raise NotImplementedError(self.get_default_mapping) |
|
224 |
||
225 |
||
3920.2.1
by Jelmer Vernooij
Add ForeignBranch class. |
226 |
class ForeignBranch(Branch): |
227 |
"""Branch that exists in a foreign version control system.""" |
|
228 |
||
229 |
def __init__(self, mapping): |
|
230 |
self.mapping = mapping |
|
231 |
super(ForeignBranch, self).__init__() |
|
232 |