/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

Try to import nothing other than __init__ when not opening git repositories.

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
 
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)
109
116
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
110
117
            progress)
111
118
 
 
119
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
 
120
        fd, path = tempfile.mkstemp(suffix=".pack")
 
121
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
 
122
        os.close(fd)
 
123
        basename = path[:-len(".pack")]
 
124
        p = PackData(path)
 
125
        p.create_index_v2(basename+".idx")
 
126
        pack = Pack(basename)
 
127
        os.remove(path)
 
128
        return (len(p), pack.iterobjects())
 
129
 
112
130
 
113
131
class RemoteGitBranch(GitBranch):
114
132
 
115
133
    def __init__(self, bzrdir, repository, name, lockfiles):
116
134
        def determine_wants(heads):
 
135
            if not name in heads:
 
136
                raise NoSuchRef(name)
117
137
            self._ref = heads[name]
118
138
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
119
139
                             lambda x: mutter("git: %s" % x))
122
142
    def last_revision(self):
123
143
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
124
144
 
 
145
    def _synchronize_history(self, destination, revision_id):
 
146
        """See Branch._synchronize_history()."""
 
147
        destination.generate_revision_history(self.last_revision())
 
148