1
# repository.py -- For dealing wih git repositories.
2
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; version 2
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
from objects import ShaFile
26
class Repository(object):
28
ref_locs = ['', 'refs', 'refs/tags', 'refs/heads', 'refs/remotes']
30
def __init__(self, root):
37
return os.path.join(self.basedir(), objectdir)
39
def _get_ref(self, file):
43
if contents.startswith(symref):
44
ref = contents[len(symref):]
48
assert len(contents) == 41, 'Invalid ref'
54
for dir in self.ref_locs:
55
file = os.path.join(self.basedir(), dir, name)
56
if os.path.exists(file):
57
return self._get_ref(file)
60
return self.ref('HEAD')
62
def get_object(self, sha):
63
assert len(sha) == 40, "Incorrect sha length"
66
path = os.path.join(self.object_dir(), dir, file)
67
if not os.path.exists(path):
69
return ShaFile.from_file(path)