/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

Add FOSDEM roundtripping notes.

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 git
 
26
from bzrlib.plugins.git import lazy_check_versions
 
27
lazy_check_versions()
 
28
 
27
29
from bzrlib.plugins.git.branch import GitBranch
 
30
from bzrlib.plugins.git.errors import NoSuchRef
28
31
from bzrlib.plugins.git.dir import GitDir
29
32
from bzrlib.plugins.git.foreign import ForeignBranch
30
33
from bzrlib.plugins.git.repository import GitFormat, GitRepository
31
34
 
 
35
import os
 
36
import tempfile
32
37
import urllib
33
38
import urlparse
34
39
 
35
 
from dulwich.pack import PackData
 
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 []
36
47
 
37
48
 
38
49
class GitSmartTransport(Transport):
43
54
        assert scheme == "git"
44
55
        hostport, self._path = urllib.splithost(loc)
45
56
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
46
 
        if _client is not None:
47
 
            self._client = _client
48
 
        else:
49
 
            self._client = git.client.TCPGitClient(self._host, self._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)
50
65
 
51
66
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
52
67
        if progress is None:
53
68
            def progress(text):
54
69
                info("git: %s" % text)
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)
 
70
        self._get_client().fetch_pack(self._path, determine_wants, 
 
71
            graph_walker, pack_data, progress)
68
72
 
69
73
    def get(self, path):
70
74
        raise NoSuchFile(path)
71
75
 
 
76
    def abspath(self, relpath):
 
77
        return urlutils.join(self.base, relpath)
 
78
 
72
79
    def clone(self, offset=None):
73
80
        """See Transport.clone()."""
74
81
        if offset is None:
90
97
    def open_repository(self):
91
98
        return RemoteGitRepository(self, self._lockfiles)
92
99
 
93
 
    def open_branch(self):
 
100
    def open_branch(self, _unsupported=False):
94
101
        repo = self.open_repository()
95
102
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
96
103
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
99
106
        raise NotLocalUrl(self.transport.base)
100
107
 
101
108
 
 
109
class TemporaryPackIterator(Pack):
 
110
 
 
111
    @property
 
112
    def idx(self):
 
113
        if self._idx is None:
 
114
            self._data.create_index_v2(self._idx_path)
 
115
            self._idx = PackIndex(self._idx_path)
 
116
        return self._idx
 
117
 
 
118
    def __del__(self):
 
119
        os.remove(self._data_path)
 
120
        os.remove(self._idx_path)
 
121
 
 
122
 
102
123
class RemoteGitRepository(GitRepository):
103
124
 
104
125
    def __init__(self, gitdir, lockfiles):
109
130
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
110
131
            progress)
111
132
 
 
133
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
134
        fd, path = tempfile.mkstemp(suffix=".pack")
 
135
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
 
136
        os.close(fd)
 
137
        return TemporaryPackIterator(path[:-len(".pack")])
 
138
 
112
139
 
113
140
class RemoteGitBranch(GitBranch):
114
141
 
115
142
    def __init__(self, bzrdir, repository, name, lockfiles):
116
143
        def determine_wants(heads):
 
144
            if not name in heads:
 
145
                raise NoSuchRef(name)
117
146
            self._ref = heads[name]
118
147
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
119
148
                             lambda x: mutter("git: %s" % x))
122
151
    def last_revision(self):
123
152
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
124
153
 
 
154
    def _synchronize_history(self, destination, revision_id):
 
155
        """See Branch._synchronize_history()."""
 
156
        destination.generate_revision_history(self.last_revision())
 
157