/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
1
# Copyright (C) 2007-2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
17
import bzrlib
18
from bzrlib import urlutils
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
19
from bzrlib.bzrdir import BzrDir, BzrDirFormat
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
20
from bzrlib.errors import NoSuchFile, NotLocalUrl
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
21
from bzrlib.lockable_files import TransportLock
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
22
from bzrlib.repository import Repository
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
23
from bzrlib.trace import info
24
from bzrlib.transport import Transport
25
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
26
from bzrlib.plugins.git import git
27
from bzrlib.plugins.git.branch import GitBranch
28
from bzrlib.plugins.git.foreign import ForeignBranch
29
from bzrlib.plugins.git.repository import GitFormat, GitRepository
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
30
31
import urllib
32
import urlparse
33
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
34
from dulwich.pack import PackData
35
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
36
37
class GitSmartTransport(Transport):
38
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
39
    def __init__(self, url, _client=None):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
40
        Transport.__init__(self, url)
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
41
        (scheme, _, loc, _, _) = urlparse.urlsplit(url)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
42
        assert scheme == "git"
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
43
        hostport, self._path = urllib.splithost(loc)
44
        (self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
45
        if _client is not None:
46
            self._client = _client
47
        else:
48
            self._client = git.client.TCPGitClient(self._host, self._port)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
49
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
50
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
51
        if progress is None:
52
            def progress(text):
53
                info("git: %s" % text)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
54
        self._client.fetch_pack(self._path, determine_wants, graph_walker, 
55
                pack_data, progress)
56
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
57
    def fetch_objects(self, determine_wants, graph_walker, progress=None):
58
        fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack")
59
        self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
60
        os.close(fd)
61
        try:
62
            p = PackData(path)
63
            for o in p.iterobjects():
64
                yield o
65
        finally:
66
            os.remove(path)
67
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
68
    def get(self, path):
69
        raise NoSuchFile(path)
70
71
    def clone(self, offset=None):
72
        """See Transport.clone()."""
73
        if offset is None:
74
            newurl = self.base
75
        else:
76
            newurl = urlutils.join(self.base, offset)
77
78
        return GitSmartTransport(newurl, self._client)
79
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
80
81
class RemoteGitDir(BzrDir):
82
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
83
    def __init__(self, transport, lockfiles, format):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
84
        self._format = format
85
        self.root_transport = transport
86
        self.transport = transport
87
        self._lockfiles = lockfiles
88
89
    def is_supported(self):
90
        return True
91
92
    def open_repository(self):
93
        return RemoteGitRepository(self, self._lockfiles)
94
95
    def open_branch(self):
96
        repo = self.open_repository()
97
        # TODO: Support for multiple branches in one bzrdir in bzrlib!
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
98
        return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
99
100
    def open_workingtree(self):
101
        raise NotLocalUrl(self.transport.base)
102
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
103
    def cloning_metadir(self, stacked=False):
104
        """Produce a metadir suitable for cloning with."""
105
        if stacked:
106
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6.1-rich-root")
107
        else:
108
            return bzrlib.bzrdir.format_registry.make_bzrdir("rich-root-pack")
109
110
111
class RemoteGitRepository(GitRepository):
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
112
113
    def __init__(self, gitdir, lockfiles):
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
114
        GitRepository.__init__(self, gitdir, lockfiles)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
115
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
116
    def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
117
        self._transport.fetch_pack(determine_wants, graph_walker, pack_data, progress)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
118
119
0.200.139 by Jelmer Vernooij
Share more code between local and remote classes, support opening remote branches.
120
class RemoteGitBranch(GitBranch):
121
122
    def __init__(self, bzrdir, repository, name, lockfiles):
123
        def determine_wants(heads):
124
            self._ref = heads[name]
125
        bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None, 
126
                             lambda x: mutter("git: %s" % x))
127
        super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
128
129
    def last_revision(self):
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
130
        return self.mapping.revision_id_foreign_to_bzr(self._ref)
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
131
132
133