/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

Cope with new member variables in RepositoryFormat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2008 Canonical Ltd
 
1
# Copyright (C) 2007-2009 Jelmer Vernooij <jelmer@samba.org>
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
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import bzrlib
18
 
from bzrlib import urlutils
19
 
from bzrlib.bzrdir import BzrDir, BzrDirFormat
20
 
from bzrlib.errors import NoSuchFile, NotLocalUrl
 
18
from bzrlib import (
 
19
    branch,
 
20
    tag,
 
21
    urlutils,
 
22
    )
 
23
from bzrlib.bzrdir import (
 
24
    BzrDir,
 
25
    BzrDirFormat,
 
26
    )
 
27
from bzrlib.errors import (
 
28
    BzrError,
 
29
    NoSuchFile,
 
30
    NotLocalUrl,
 
31
    )
21
32
from bzrlib.lockable_files import TransportLock
22
33
from bzrlib.repository import Repository
23
34
from bzrlib.trace import info
24
35
from bzrlib.transport import Transport
25
36
 
26
 
from bzrlib.plugins.git import git
 
37
from bzrlib.plugins.git import lazy_check_versions
 
38
lazy_check_versions()
 
39
 
27
40
from bzrlib.plugins.git.branch import GitBranch
28
41
from bzrlib.plugins.git.errors import NoSuchRef
29
42
from bzrlib.plugins.git.dir import GitDir
30
43
from bzrlib.plugins.git.foreign import ForeignBranch
31
 
from bzrlib.plugins.git.repository import GitFormat, GitRepository
 
44
from bzrlib.plugins.git.repository import (
 
45
    GitRepositoryFormat,
 
46
    GitRepository,
 
47
    )
32
48
 
 
49
import dulwich as git
 
50
from dulwich.errors import GitProtocolError
 
51
from dulwich.pack import (
 
52
    Pack,
 
53
    PackData,
 
54
    PackIndex,
 
55
    )
33
56
import os
34
57
import tempfile
35
58
import urllib
36
59
import urlparse
37
60
 
38
 
from dulwich.pack import PackData, Pack
 
61
 
 
62
# Don't run any tests on GitSmartTransport as it is not intended to be 
 
63
# a full implementation of Transport
 
64
def get_test_permutations():
 
65
    return []
39
66
 
40
67
 
41
68
class GitSmartTransport(Transport):
48
75
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
49
76
        self._client = _client
50
77
 
 
78
    def has(self, relpath):
 
79
        return False
 
80
 
51
81
    def _get_client(self):
52
82
        if self._client is not None:
53
83
            ret = self._client
54
84
            self._client = None
55
85
            return ret
56
 
        return git.client.TCPGitClient(self._host, self._port)
 
86
        return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
57
87
 
58
88
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
59
89
        if progress is None:
60
90
            def progress(text):
61
91
                info("git: %s" % text)
62
 
        self._get_client().fetch_pack(self._path, determine_wants, 
63
 
            graph_walker, pack_data, progress)
 
92
        client = self._get_client()
 
93
        try:
 
94
            client.fetch_pack(self._path, determine_wants, 
 
95
                graph_walker, pack_data, progress)
 
96
        except GitProtocolError, e:
 
97
            raise BzrError(e)
64
98
 
65
99
    def get(self, path):
66
100
        raise NoSuchFile(path)
89
123
    def open_repository(self):
90
124
        return RemoteGitRepository(self, self._lockfiles)
91
125
 
92
 
    def open_branch(self):
 
126
    def open_branch(self, _unsupported=False):
93
127
        repo = self.open_repository()
94
128
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
95
129
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
98
132
        raise NotLocalUrl(self.transport.base)
99
133
 
100
134
 
 
135
class EmptyObjectStoreIterator(dict):
 
136
 
 
137
    def iterobjects(self):
 
138
        return []
 
139
 
 
140
 
 
141
class TemporaryPackIterator(Pack):
 
142
 
 
143
    def __init__(self, path, resolve_ext_ref):
 
144
        self.resolve_ext_ref = resolve_ext_ref
 
145
        super(TemporaryPackIterator, self).__init__(path)
 
146
 
 
147
    @property
 
148
    def idx(self):
 
149
        if self._idx is None:
 
150
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
 
151
            self._idx = PackIndex(self._idx_path)
 
152
        return self._idx
 
153
 
 
154
    def __del__(self):
 
155
        os.remove(self._data_path)
 
156
        os.remove(self._idx_path)
 
157
 
 
158
 
101
159
class RemoteGitRepository(GitRepository):
102
160
 
103
161
    def __init__(self, gitdir, lockfiles):
104
162
        GitRepository.__init__(self, gitdir, lockfiles)
 
163
        self._refs = None
 
164
 
 
165
    def get_refs(self):
 
166
        if self._refs is not None:
 
167
            return self._refs
 
168
        def determine_wants(heads):
 
169
            self._refs = heads
 
170
            return []
 
171
        self.bzrdir.root_transport.fetch_pack(determine_wants, None, 
 
172
            lambda x: None, lambda x: mutter("git: %s" % x))
 
173
        return self._refs
105
174
 
106
175
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
107
176
                   progress=None):
108
177
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
109
178
            progress)
110
179
 
111
 
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
180
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
112
181
        fd, path = tempfile.mkstemp(suffix=".pack")
113
182
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
114
183
        os.close(fd)
115
 
        try:
116
 
            basename = path[:-len(".pack")]
117
 
            p = PackData(path)
118
 
            p.create_index_v2(basename+".idx")
119
 
            for o in Pack(basename).iterobjects():
120
 
                yield o
121
 
        finally:
122
 
            os.remove(path)
 
184
        if os.path.getsize(path) == 0:
 
185
            return EmptyObjectStoreIterator()
 
186
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
 
187
 
 
188
 
 
189
class RemoteGitTagDict(tag.BasicTags):
 
190
 
 
191
    def __init__(self, branch):
 
192
        self.branch = branch
 
193
        self.repository = branch.repository
 
194
 
 
195
    def get_tag_dict(self):
 
196
        ret = {}
 
197
        refs = self.repository.get_refs()
 
198
        for k,v in refs.iteritems():
 
199
            if k.startswith("refs/tags/") and not k.endswith("^{}"):
 
200
                v = refs.get(k+"^{}", v)
 
201
                ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
 
202
        return ret
 
203
 
 
204
    def set_tag(self, name, revid):
 
205
        # FIXME: Not supported yet, should do a push of a new ref
 
206
        raise NotImplementedError(self.set_tag)
123
207
 
124
208
 
125
209
class RemoteGitBranch(GitBranch):
126
210
 
127
211
    def __init__(self, bzrdir, repository, name, lockfiles):
128
 
        def determine_wants(heads):
129
 
            if not name in heads:
130
 
                raise NoSuchRef(name)
131
 
            self._ref = heads[name]
132
 
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
133
 
                             lambda x: mutter("git: %s" % x))
 
212
        heads = repository.get_refs()
 
213
        if not name in heads:
 
214
            raise NoSuchRef(name)
 
215
        self._ref = heads[name]
134
216
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
135
217
 
136
218
    def last_revision(self):