/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 transportgit.py

  • Committer: Jelmer Vernooij
  • Date: 2010-02-11 23:46:31 UTC
  • mto: (0.200.718 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20100211234631-8si4dpw8ipzas3po
Simplify call to abspath, without involving private variables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
 
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
 
 
17
"""A Git repository implementation that uses a Bazaar transport."""
 
18
 
 
19
 
 
20
from dulwich.errors import (
 
21
    NotGitRepository,
 
22
    )
 
23
from dulwich.repo import (
 
24
    BaseRepo,
 
25
    OBJECTDIR,
 
26
    REFSDIR,
 
27
    BASE_DIRECTORIES
 
28
    )
 
29
 
 
30
from bzrlib import (
 
31
    urlutils,
 
32
    )
 
33
from bzrlib.errors import (
 
34
    NoSuchFile,
 
35
    )
 
36
 
 
37
 
 
38
class TransportRepo(BaseRepo):
 
39
 
 
40
    def __init__(self, transport):
 
41
        super(TransportRepo, self).__init__()
 
42
        self.transport = transport
 
43
        if self.transport.has(urlutils.join(".git", OBJECTDIR)):
 
44
            self.bare = False
 
45
            self._controltransport = self.transport.clone('.git')
 
46
        elif (self.transport.has(OBJECTDIR) and
 
47
              self.transport.has(REFSDIR)):
 
48
            self.bare = True
 
49
            self._controltransport = self.transport
 
50
        else:
 
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)
 
56
 
 
57
    def get_named_file(self, path):
 
58
        """Get a file from the control dir with a specific name.
 
59
 
 
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.
 
63
 
 
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.
 
66
        """
 
67
        try:
 
68
            return self._controltransport.get(path.lstrip('/'))
 
69
        except NoSuchFile:
 
70
            return None
 
71
 
 
72
    def put_named_file(self, path, contents):
 
73
        self._controltransport.put_bytes(path.lstrip('/'), contents)
 
74
 
 
75
    def open_index(self):
 
76
        """Open the index for this repository."""
 
77
        raise NotImplementedError
 
78
 
 
79
    def __repr__(self):
 
80
        return "<TransportRepo for %r>" % self.transport
 
81
 
 
82
    @classmethod
 
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)
 
88
 
 
89
    @classmethod
 
90
    def init_bare(cls, transport, mkdir=True):
 
91
        for d in BASE_DIRECTORIES:
 
92
            transport.mkdir(urlutils.join(*d))
 
93
        ret = cls(transport)
 
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
 
98
    filemode = true
 
99
    bare = false
 
100
    logallrefupdates = true
 
101
""")
 
102
        ret.put_named_file('info/excludes', '')
 
103
        return ret
 
104
 
 
105
    create = init_bare
 
106