* Fix memory leak in C implementation of sorted_tree_items. (Dave Borowitz)
+ * Use correct path separators for named repo files. (Dave Borowitz)
+
FEATURES
* Move named file initilization to BaseRepo. (Dave Borowitz)
'filemode = true\n'
'bare = false\n'
'logallrefupdates = true\n'))
- self._put_named_file('info/exclude', '')
+ self._put_named_file(os.path.join('info', 'exclude'), '')
def get_named_file(self, path):
"""Get a file from the control dir with a specific name.
:param path: The path to the file, relative to the control dir.
:contents: A string to write to the file.
"""
+ path = path.lstrip(os.path.sep)
f = GitFile(os.path.join(self.controldir(), path), 'wb')
try:
f.write(contents)
:param path: The path to the file, relative to the control dir.
:return: An open file object, or None if the file does not exist.
"""
+ # TODO(dborowitz): sanitize filenames, since this is used directly by
+ # the dumb web serving code.
+ path = path.lstrip(os.path.sep)
try:
- return open(os.path.join(self.controldir(), path.lstrip('/')), 'rb')
+ return open(os.path.join(self.controldir(), path), 'rb')
except (IOError, OSError), e:
if e.errno == errno.ENOENT:
return None
class CreateRepositoryTests(unittest.TestCase):
- def test_create(self):
+ def assertFileContentsEqual(self, expected, repo, path):
+ f = repo.get_named_file(path)
+ if not f:
+ self.assertEqual(expected, None)
+ else:
+ try:
+ self.assertEqual(expected, f.read())
+ finally:
+ f.close()
+
+ def _check_repo_contents(self, repo):
+ self.assertTrue(repo.bare)
+ self.assertFileContentsEqual('Unnamed repository', repo, 'description')
+ self.assertFileContentsEqual('', repo, os.path.join('info', 'exclude'))
+ self.assertFileContentsEqual(None, repo, 'nonexistent file')
+
+ def test_create_disk(self):
tmp_dir = tempfile.mkdtemp()
try:
repo = Repo.init_bare(tmp_dir)
self.assertEquals(tmp_dir, repo._controldir)
+ self._check_repo_contents(repo)
finally:
shutil.rmtree(tmp_dir)
"""HTTP server for dulwich that implements the git smart HTTP protocol."""
from cStringIO import StringIO
+import os
import re
import time
raise
+def _url_to_path(url):
+ return url.replace('/', os.path.sep)
+
+
def get_text_file(req, backend, mat):
req.nocache()
- return send_file(req, get_repo(backend, mat).get_named_file(mat.group()),
+ path = _url_to_path(mat.group())
+ return send_file(req, get_repo(backend, mat).get_named_file(path),
'text/plain')
def get_pack_file(req, backend, mat):
req.cache_forever()
- return send_file(req, get_repo(backend, mat).get_named_file(mat.group()),
+ path = _url_to_path(mat.group())
+ return send_file(req, get_repo(backend, mat).get_named_file(path),
'application/x-git-packed-objects')
def get_idx_file(req, backend, mat):
req.cache_forever()
- return send_file(req, get_repo(backend, mat).get_named_file(mat.group()),
+ path = _url_to_path(mat.group())
+ return send_file(req, get_repo(backend, mat).get_named_file(path),
'application/x-git-packed-objects-toc')