1
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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
17
"""A Git repository implementation that uses a Bazaar transport."""
20
from dulwich.errors import (
23
from dulwich.repo import (
33
from bzrlib.errors import (
38
class TransportRepo(BaseRepo):
40
def __init__(self, transport):
41
super(TransportRepo, self).__init__()
42
self.transport = transport
43
if self.transport.has(urlutils.join(".git", OBJECTDIR)):
45
self._controltransport = self.transport.clone('.git')
46
elif (self.transport.has(OBJECTDIR) and
47
self.transport.has(REFSDIR)):
49
self._controltransport = self.transport
51
raise NotGitRepository(self.transport)
52
object_store = TransportObjectStore(
53
self._controltransport.clone(OBJECTDIR))
54
refs = TransportRefsContainer(self._controltransport)
55
BaseRepo.__init__(self, object_store, refs)
57
def get_named_file(self, path):
58
"""Get a file from the control dir with a specific name.
60
Although the filename should be interpreted as a filename relative to
61
the control dir in a disk-baked Repo, the object returned need not be
62
pointing to a file in that location.
64
:param path: The path to the file, relative to the control dir.
65
:return: An open file object, or None if the file does not exist.
68
return self._controltransport.get(path.lstrip('/'))
72
def put_named_file(self, path, contents):
73
self._controltransport.put_bytes(path.lstrip('/'), contents)
76
"""Open the index for this repository."""
77
raise NotImplementedError
80
return "<TransportRepo for %r>" % self.transport
83
def init(cls, transport, mkdir=True):
84
transport.mkdir('.git')
85
controltransport = transport.clone('.git')
86
cls.init_bare(controltransport)
87
return cls(controltransport)
90
def init_bare(cls, transport, mkdir=True):
91
for d in BASE_DIRECTORIES:
92
transport.mkdir(urlutils.join(*d))
94
ret.refs.set_ref("HEAD", "refs/heads/master")
95
ret.put_named_file('description', "Unnamed repository")
96
ret.put_named_file('config', """[core]
97
repositoryformatversion = 0
100
logallrefupdates = true
102
ret.put_named_file('info/excludes', '')