Skip to content

Commit f50643f

Browse files
committed
Added basic frame for packfile implementation and testing, as well as the testing of the corresponding PackedDB. It wants to be filled out now, but the design not yet done either actually
1 parent 937d592 commit f50643f

9 files changed

Lines changed: 103 additions & 2 deletions

db/pack.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,41 @@
44
ObjectDBR
55
)
66

7+
from gitdb.exc import (
8+
UnsupportedOperation,
9+
)
10+
711
__all__ = ('PackedDB', )
812

913
class PackedDB(FileDBBase, ObjectDBR):
1014
"""A database operating on a set of object packs"""
1115

16+
def __init__(self, root_path):
17+
super(PackedDB, self).__init__(root_path)
18+
19+
20+
#{ Object DB Read
21+
22+
def has_object(self, sha):
23+
raise NotImplementedError()
24+
25+
def info(self, sha):
26+
raise NotImplementedError()
27+
28+
def stream(self, sha):
29+
raise NotImplementedError()
30+
31+
#} END object db read
32+
33+
#{ object db write
34+
35+
def store(self, istream):
36+
"""Storing individual objects is not feasible as a pack is designed to
37+
hold multiple objects. Writing or rewriting packs for single objects is
38+
inefficient"""
39+
raise UnsupportedOperation()
40+
41+
def store_async(self, reader):
42+
raise NotImplementedError()
43+
44+
#} END object db write

exc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ class BadObject(ODBError):
1212
class BadObjectType(ODBError):
1313
"""The object had an unsupported type"""
1414

15+
class UnsupportedOperation(ODBError):
16+
"""Thrown if the given operation cannot be supported by the object database"""

pack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains PackIndex and PackFile implementations"""

test/db/lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Base classes for object db testing"""
22
from gitdb.test.lib import (
33
with_rw_directory,
4+
with_packs,
45
ZippedStoreShaWriter,
56
TestBase
67
)
@@ -16,11 +17,10 @@
1617
from gitdb.typ import str_blob_type
1718

1819
from async import IteratorReader
19-
2020
from cStringIO import StringIO
2121

2222

23-
__all__ = ('TestDBBase', 'with_rw_directory' )
23+
__all__ = ('TestDBBase', 'with_rw_directory', 'with_packs' )
2424

2525
class TestDBBase(TestBase):
2626
"""Base class providing testing routines on databases"""

test/db/test_pack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from lib import *
2+
from gitdb.db import PackedDB
3+
4+
class TestPackDB(TestDBBase):
5+
6+
@with_rw_directory
7+
@with_packs
8+
def test_writing(self, path):
9+
ldb = PackedDB(path)
10+
# TODO
11+
12+
Binary file not shown.
Binary file not shown.

test/lib.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from array import array
1111
from cStringIO import StringIO
1212

13+
import glob
1314
import unittest
1415
import tempfile
1516
import shutil
@@ -46,10 +47,46 @@ def wrapper(self):
4647
return wrapper
4748

4849

50+
def with_packs(func):
51+
"""Function that provides a path into which the packs for testing should be
52+
copied. Will pass on the path to the actual function afterwards"""
53+
def wrapper(self, path):
54+
src_pack_glob = fixture_path('packs/*')
55+
copy_files_globbed(src_pack_glob, path, hard_link_ok=True)
56+
return func(self, path)
57+
# END wrapper
58+
59+
wrapper.__name__ = func.__name__
60+
return wrapper
61+
4962
#} END decorators
5063

5164
#{ Routines
5265

66+
def fixture_path(relapath=''):
67+
""":return: absolute path into the fixture directory
68+
:param relapath: relative path into the fixtures directory, or ''
69+
to obtain the fixture directory itself"""
70+
return os.path.join(os.path.dirname(__file__), 'fixtures', relapath)
71+
72+
def copy_files_globbed(source_glob, target_dir, hard_link_ok=False):
73+
"""Copy all files found according to the given source glob into the target directory
74+
:param hard_link_ok: if True, hard links will be created if possible. Otherwise
75+
the files will be copied"""
76+
for src_file in glob.glob(source_glob):
77+
if hard_link_ok and hasattr(os, 'link'):
78+
target = os.path.join(target_dir, os.path.basename(src_file))
79+
try:
80+
os.link(src_file, target)
81+
except OSError:
82+
shutil.copy(src_file, target_dir)
83+
# END handle cross device links ( and resulting failure )
84+
else:
85+
shutil.copy(src_file, target_dir)
86+
# END try hard link
87+
# END for each file to copy
88+
89+
5390
def make_bytes(size_in_bytes, randomize=False):
5491
""":return: string with given size in bytes
5592
:param randomize: try to produce a very random stream"""

test/test_pack.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Test everything about packs reading and writing"""
2+
3+
from lib import (
4+
TestBase,
5+
with_rw_directory,
6+
with_packs
7+
)
8+
9+
10+
class TestPack(TestBase):
11+
12+
@with_rw_directory
13+
@with_packs
14+
def test_reading(self, pack_dir):
15+
# initialze a pack file for reading
16+
pass

0 commit comments

Comments
 (0)