/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

Fix formatting, remove catch-all for exceptions when opening local 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 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)
 
46
        if _client is not None:
 
47
            self._client = _client
 
48
        else:
 
49
            self._client = git.client.TCPGitClient(self._host, self._port)
65
50
 
66
51
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
67
52
        if progress is None:
68
53
            def progress(text):
69
54
                info("git: %s" % text)
70
 
        self._get_client().fetch_pack(self._path, determine_wants, 
71
 
            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)
72
68
 
73
69
    def get(self, path):
74
70
        raise NoSuchFile(path)
75
71
 
76
 
    def abspath(self, relpath):
77
 
        return urlutils.join(self.base, relpath)
78
 
 
79
72
    def clone(self, offset=None):
80
73
        """See Transport.clone()."""
81
74
        if offset is None:
97
90
    def open_repository(self):
98
91
        return RemoteGitRepository(self, self._lockfiles)
99
92
 
100
 
    def open_branch(self, _unsupported=False):
 
93
    def open_branch(self):
101
94
        repo = self.open_repository()
102
95
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
103
96
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
106
99
        raise NotLocalUrl(self.transport.base)
107
100
 
108
101
 
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
 
 
123
102
class RemoteGitRepository(GitRepository):
124
103
 
125
104
    def __init__(self, gitdir, lockfiles):
130
109
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, 
131
110
            progress)
132
111
 
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
 
 
139
112
 
140
113
class RemoteGitBranch(GitBranch):
141
114
 
142
115
    def __init__(self, bzrdir, repository, name, lockfiles):
143
116
        def determine_wants(heads):
144
 
            if not name in heads:
145
 
                raise NoSuchRef(name)
146
117
            self._ref = heads[name]
147
118
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
148
119
                             lambda x: mutter("git: %s" % x))
151
122
    def last_revision(self):
152
123
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
153
124
 
154
 
    def _synchronize_history(self, destination, revision_id):
155
 
        """See Branch._synchronize_history()."""
156
 
        destination.generate_revision_history(self.last_revision())
157