/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 remote.py

Implement GitRepository.revision_graph_can_have_wrong_parents().

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from bzrlib import (
19
19
    branch,
20
20
    tag,
 
21
    ui,
21
22
    urlutils,
22
23
    )
23
 
from bzrlib.bzrdir import (
24
 
    BzrDir,
25
 
    BzrDirFormat,
26
 
    )
27
24
from bzrlib.errors import (
28
25
    BzrError,
 
26
    InvalidRevisionId,
29
27
    NoSuchFile,
 
28
    NoSuchRevision,
30
29
    NotLocalUrl,
31
30
    )
32
 
from bzrlib.lockable_files import (
33
 
    TransportLock,
34
 
    )
35
 
from bzrlib.repository import (
36
 
    Repository,
37
 
    )
38
31
from bzrlib.trace import (
39
32
    info,
40
33
    )
49
42
 
50
43
from bzrlib.plugins.git.branch import (
51
44
    GitBranch,
 
45
    extract_tags,
52
46
    )
53
47
from bzrlib.plugins.git.errors import (
54
48
    GitSmartRemoteNotSupported,
57
51
from bzrlib.plugins.git.dir import (
58
52
    GitDir,
59
53
    )
60
 
from bzrlib.plugins.git.foreign import (
61
 
    ForeignBranch,
 
54
from bzrlib.plugins.git.mapping import (
 
55
    mapping_registry,
62
56
    )
63
57
from bzrlib.plugins.git.repository import (
64
58
    GitRepositoryFormat,
96
90
        Transport.__init__(self, url)
97
91
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
98
92
        hostport, self._path = urllib.splithost(loc)
99
 
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
 
93
        (self._username, hostport) = urllib.splituser(hostport)
 
94
        (self._host, self._port) = urllib.splitnport(hostport, None)
100
95
        self._client = _client
101
96
 
 
97
    def external_url(self):
 
98
        return self.base
 
99
 
102
100
    def has(self, relpath):
103
101
        return False
104
102
 
105
103
    def _get_client(self):
106
104
        raise NotImplementedError(self._get_client)
107
105
 
 
106
    def _get_path(self):
 
107
        return self._path
 
108
 
108
109
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
109
110
        if progress is None:
110
111
            def progress(text):
111
112
                info("git: %s" % text)
112
113
        client = self._get_client()
113
114
        try:
114
 
            client.fetch_pack(self._path, determine_wants, 
 
115
            return client.fetch_pack(self._get_path(), determine_wants, 
115
116
                graph_walker, pack_data, progress)
116
117
        except GitProtocolError, e:
117
118
            raise BzrError(e)
118
119
 
 
120
    def send_pack(self, get_changed_refs, generate_pack_contents):
 
121
        client = self._get_client()
 
122
        try:
 
123
            return client.send_pack(self._get_path(), get_changed_refs, 
 
124
                generate_pack_contents)
 
125
        except GitProtocolError, e:
 
126
            raise BzrError(e)
 
127
 
119
128
    def get(self, path):
120
129
        raise NoSuchFile(path)
121
130
 
134
143
 
135
144
class TCPGitSmartTransport(GitSmartTransport):
136
145
 
 
146
    _scheme = 'git'
 
147
 
137
148
    def _get_client(self):
138
149
        if self._client is not None:
139
150
            ret = self._client
140
151
            self._client = None
141
152
            return ret
142
 
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
 
153
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
 
154
            report_activity=self._report_activity)
143
155
 
144
156
 
145
157
class SSHGitSmartTransport(GitSmartTransport):
146
158
 
 
159
    _scheme = 'git+ssh'
 
160
 
 
161
    def _get_path(self):
 
162
        if self._path.startswith("/~/"):
 
163
            return self._path[3:]
 
164
        return self._path
 
165
 
147
166
    def _get_client(self):
148
167
        if self._client is not None:
149
168
            ret = self._client
150
169
            self._client = None
151
170
            return ret
152
 
        return git.client.SSHGitClient(self._host, self._port, thin_packs=False)
 
171
        return git.client.SSHGitClient(self._host, self._port, self._username,
 
172
            thin_packs=False, report_activity=self._report_activity)
153
173
 
154
174
 
155
175
class RemoteGitDir(GitDir):
159
179
        self.root_transport = transport
160
180
        self.transport = transport
161
181
        self._lockfiles = lockfiles
 
182
        self._mode_check_done = None
162
183
 
163
184
    def open_repository(self):
164
185
        return RemoteGitRepository(self, self._lockfiles)
185
206
        self.resolve_ext_ref = resolve_ext_ref
186
207
 
187
208
    @property
188
 
    def idx(self):
 
209
    def index(self):
189
210
        if self._idx is None:
190
 
            if self._data is None:
191
 
                self._data = PackData(self._data_path)
192
 
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
 
211
            pb = ui.ui_factory.nested_progress_bar()
 
212
            try:
 
213
                def report_progress(cur, total):
 
214
                    pb.update("generating index", cur, total)
 
215
                self.data.create_index(self._idx_path, self.resolve_ext_ref,
 
216
                    progress=report_progress)
 
217
            finally:
 
218
                pb.finished()
193
219
            self._idx = load_pack_index(self._idx_path)
194
220
        return self._idx
195
221
 
219
245
    def get_refs(self):
220
246
        if self._refs is not None:
221
247
            return self._refs
222
 
        def determine_wants(heads):
223
 
            self._refs = heads
224
 
            return []
225
 
        self.bzrdir.root_transport.fetch_pack(determine_wants, None, 
 
248
        self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None, 
226
249
            lambda x: None, lambda x: mutter("git: %s" % x))
227
250
        return self._refs
228
251
 
229
252
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
230
253
                   progress=None):
231
 
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
232
 
            progress)
 
254
        return self._transport.fetch_pack(determine_wants, graph_walker,
 
255
                                          pack_data, progress)
 
256
 
 
257
    def send_pack(self, get_changed_refs, generate_pack_contents):
 
258
        return self._transport.send_pack(get_changed_refs, generate_pack_contents)
233
259
 
234
260
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
235
261
        fd, path = tempfile.mkstemp(suffix=".pack")
239
265
            return EmptyObjectStoreIterator()
240
266
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
241
267
 
 
268
    def lookup_git_revid(self, bzr_revid):
 
269
        # This won't work for any round-tripped bzr revisions, but it's a start..
 
270
        try:
 
271
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
 
272
        except InvalidRevisionId:
 
273
            raise NoSuchRevision(self, bzr_revid)
 
274
 
242
275
 
243
276
class RemoteGitTagDict(tag.BasicTags):
244
277
 
247
280
        self.repository = branch.repository
248
281
 
249
282
    def get_tag_dict(self):
250
 
        ret = {}
251
 
        refs = self.repository.get_refs()
252
 
        for k,v in refs.iteritems():
253
 
            if k.startswith("refs/tags/") and not k.endswith("^{}"):
254
 
                v = refs.get(k+"^{}", v)
255
 
                ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
256
 
        return ret
 
283
        return extract_tags(self.repository.get_refs(), self.branch.mapping)
257
284
 
258
285
    def set_tag(self, name, revid):
259
286
        # FIXME: Not supported yet, should do a push of a new ref
263
290
class RemoteGitBranch(GitBranch):
264
291
 
265
292
    def __init__(self, bzrdir, repository, name, lockfiles):
266
 
        heads = repository.get_refs()
267
 
        if not name in heads:
 
293
        self._ref = None
 
294
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, 
 
295
                lockfiles)
 
296
 
 
297
    def revision_history(self):
 
298
        raise GitSmartRemoteNotSupported()
 
299
 
 
300
    def last_revision(self):
 
301
        return self.mapping.revision_id_foreign_to_bzr(self.head)
 
302
 
 
303
    @property
 
304
    def head(self):
 
305
        if self._ref is not None:
 
306
            return self._ref
 
307
        heads = self.repository.get_refs()
 
308
        if not self.name in heads:
268
309
            raise NoSuchRef(name)
269
 
        self._ref = heads[name]
270
 
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
271
 
 
272
 
    def last_revision(self):
273
 
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
 
310
        self._ref = heads[self.name]
 
311
        return self._ref
274
312
 
275
313
    def _synchronize_history(self, destination, revision_id):
276
314
        """See Branch._synchronize_history()."""
277
315
        destination.generate_revision_history(self.last_revision())
278
316
 
 
317
    def get_push_location(self):
 
318
        return None
 
319
 
 
320
    def set_push_location(self, url):
 
321
        pass