/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

Merge new dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.trace import info
24
24
from bzrlib.transport import Transport
25
25
 
26
 
from bzrlib.plugins.git import lazy_check_versions
27
 
lazy_check_versions()
28
 
 
 
26
from bzrlib.plugins.git import git
29
27
from bzrlib.plugins.git.branch import GitBranch
30
 
from bzrlib.plugins.git.errors import NoSuchRef
31
28
from bzrlib.plugins.git.dir import GitDir
32
29
from bzrlib.plugins.git.foreign import ForeignBranch
33
30
from bzrlib.plugins.git.repository import GitFormat, GitRepository
34
31
 
35
 
import os
36
 
import tempfile
37
32
import urllib
38
33
import urlparse
39
34
 
40
 
import dulwich as git
41
 
from dulwich.pack import PackData, Pack, PackIndex
42
 
 
43
 
# Don't run any tests on GitSmartTransport as it is not intended to be 
44
 
# a full implementation of Transport
45
 
def get_test_permutations():
46
 
    return []
 
35
from dulwich.pack import PackData
47
36
 
48
37
 
49
38
class GitSmartTransport(Transport):
54
43
        assert scheme == "git"
55
44
        hostport, self._path = urllib.splithost(loc)
56
45
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
57
 
        self._client = _client
58
 
 
59
 
    def _get_client(self):
60
 
        if self._client is not None:
61
 
            ret = self._client
62
 
            self._client = None
63
 
            return ret
64
 
        return git.client.TCPGitClient(self._host, self._port, 
65
 
            capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
 
46
        if _client is not None:
 
47
            self._client = _client
 
48
        else:
 
49
            self._client = git.client.TCPGitClient(self._host, self._port)
66
50
 
67
51
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
68
52
        if progress is None:
69
53
            def progress(text):
70
54
                info("git: %s" % text)
71
 
        self._get_client().fetch_pack(self._path, determine_wants, 
72
 
            graph_walker, pack_data, progress)
 
55
        self._client.fetch_pack(self._path, determine_wants, graph_walker, 
 
56
                pack_data, progress)
 
57
 
 
58
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
59
        fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack")
 
60
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
 
61
        os.close(fd)
 
62
        try:
 
63
            p = PackData(path)
 
64
            for o in p.iterobjects():
 
65
                yield o
 
66
        finally:
 
67
            os.remove(path)
73
68
 
74
69
    def get(self, path):
75
70
        raise NoSuchFile(path)
76
71
 
77
 
    def abspath(self, relpath):
78
 
        return urlutils.join(self.base, relpath)
79
 
 
80
72
    def clone(self, offset=None):
81
73
        """See Transport.clone()."""
82
74
        if offset is None:
98
90
    def open_repository(self):
99
91
        return RemoteGitRepository(self, self._lockfiles)
100
92
 
101
 
    def open_branch(self, _unsupported=False):
 
93
    def open_branch(self):
102
94
        repo = self.open_repository()
103
95
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
104
96
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
106
98
    def open_workingtree(self):
107
99
        raise NotLocalUrl(self.transport.base)
108
100
 
109
 
 
110
 
class EmptyObjectStoreIterator(dict):
111
 
 
112
 
    def iterobjects(self):
113
 
        return []
114
 
 
115
 
 
116
 
class TemporaryPackIterator(Pack):
117
 
 
118
 
    def __init__(self, path, resolve_ext_ref):
119
 
        self.resolve_ext_ref = resolve_ext_ref
120
 
        super(TemporaryPackIterator, self).__init__(path)
121
 
 
122
 
    @property
123
 
    def idx(self):
124
 
        if self._idx is None:
125
 
            self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
126
 
            self._idx = PackIndex(self._idx_path)
127
 
        return self._idx
128
 
 
129
 
    def __del__(self):
130
 
        os.remove(self._data_path)
131
 
        os.remove(self._idx_path)
 
101
    def cloning_metadir(self, stacked=False):
 
102
        """Produce a metadir suitable for cloning with."""
 
103
        if stacked:
 
104
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6.1-rich-root")
 
105
        else:
 
106
            return bzrlib.bzrdir.format_registry.make_bzrdir("rich-root-pack")
132
107
 
133
108
 
134
109
class RemoteGitRepository(GitRepository):
136
111
    def __init__(self, gitdir, lockfiles):
137
112
        GitRepository.__init__(self, gitdir, lockfiles)
138
113
 
139
 
    def fetch_pack(self, determine_wants, graph_walker, pack_data, 
140
 
                   progress=None):
141
 
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
142
 
            progress)
143
 
 
144
 
    def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
145
 
        fd, path = tempfile.mkstemp(suffix=".pack")
146
 
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
147
 
        os.close(fd)
148
 
        if os.path.getsize(path) == 0:
149
 
            return EmptyObjectStoreIterator()
150
 
        return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
 
114
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
 
115
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, progress)
151
116
 
152
117
 
153
118
class RemoteGitBranch(GitBranch):
154
119
 
155
120
    def __init__(self, bzrdir, repository, name, lockfiles):
156
121
        def determine_wants(heads):
157
 
            if not name in heads:
158
 
                raise NoSuchRef(name)
159
122
            self._ref = heads[name]
160
123
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
161
124
                             lambda x: mutter("git: %s" % x))
164
127
    def last_revision(self):
165
128
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
166
129
 
167
 
    def _synchronize_history(self, destination, revision_id):
168
 
        """See Branch._synchronize_history()."""
169
 
        destination.generate_revision_history(self.last_revision())
170
 
 
 
130
 
 
131