summaryrefslogtreecommitdiff
path: root/gitdb/db/loose.py
diff options
context:
space:
mode:
authorKevin Brown <kevin@kevinbrown.in>2014-07-13 15:35:24 -0400
committerKevin Brown <kevin@kevinbrown.in>2014-07-13 15:35:24 -0400
commit1c6f4c19289732bd13507eba9e54c9d692957137 (patch)
tree88840df38e1f1b021868803bc743a5ab3b55a327 /gitdb/db/loose.py
parent72167492334b756ddeaa606274e9348a70734cdb (diff)
downloadgitdb-1c6f4c19289732bd13507eba9e54c9d692957137.tar.gz
Automated PEP 8 fixes
Diffstat (limited to 'gitdb/db/loose.py')
-rw-r--r--gitdb/db/loose.py103
1 files changed, 51 insertions, 52 deletions
diff --git a/gitdb/db/loose.py b/gitdb/db/loose.py
index dc0ea0e..4ebca84 100644
--- a/gitdb/db/loose.py
+++ b/gitdb/db/loose.py
@@ -10,46 +10,46 @@ from base import (
from gitdb.exc import (
- InvalidDBRoot,
+ InvalidDBRoot,
BadObject,
AmbiguousObjectName
- )
+)
from gitdb.stream import (
DecompressMemMapReader,
FDCompressedSha1Writer,
FDStream,
Sha1Writer
- )
+)
from gitdb.base import (
- OStream,
- OInfo
- )
+ OStream,
+ OInfo
+)
from gitdb.util import (
- file_contents_ro_filepath,
- ENOENT,
- hex_to_bin,
- bin_to_hex,
- exists,
- chmod,
- isdir,
- isfile,
- remove,
- mkdir,
- rename,
- dirname,
- basename,
- join
- )
-
-from gitdb.fun import (
+ file_contents_ro_filepath,
+ ENOENT,
+ hex_to_bin,
+ bin_to_hex,
+ exists,
+ chmod,
+ isdir,
+ isfile,
+ remove,
+ mkdir,
+ rename,
+ dirname,
+ basename,
+ join
+)
+
+from gitdb.fun import (
chunk_size,
- loose_object_header_info,
+ loose_object_header_info,
write_object,
stream_copy
- )
+)
import tempfile
import mmap
@@ -62,11 +62,11 @@ __all__ = ( 'LooseObjectDB', )
class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
"""A database which operates on loose object files"""
-
+
# CONFIGURATION
# chunks in which data will be copied between streams
stream_chunk_size = chunk_size
-
+
# On windows we need to keep it writable, otherwise it cannot be removed
# either
new_objects_mode = 0444
@@ -81,14 +81,14 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
# Depending on the root, this might work for some mounts, for others not, which
# is why it is per instance
self._fd_open_flags = getattr(os, 'O_NOATIME', 0)
-
- #{ Interface
+
+ #{ Interface
def object_path(self, hexsha):
"""
- :return: path at which the object with the given hexsha would be stored,
+ :return: path at which the object with the given hexsha would be stored,
relative to the database root"""
return join(hexsha[:2], hexsha[2:])
-
+
def readable_db_object_path(self, hexsha):
"""
:return: readable object path to the object identified by hexsha
@@ -97,8 +97,8 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
return self._hexsha_to_file[hexsha]
except KeyError:
pass
- # END ignore cache misses
-
+ # END ignore cache misses
+
# try filesystem
path = self.db_path(self.object_path(hexsha))
if exists(path):
@@ -106,11 +106,11 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
return path
# END handle cache
raise BadObject(hexsha)
-
+
def partial_to_complete_sha_hex(self, partial_hexsha):
""":return: 20 byte binary sha1 string which matches the given name uniquely
:param name: hexadecimal partial name
- :raise AmbiguousObjectName:
+ :raise AmbiguousObjectName:
:raise BadObject: """
candidate = None
for binsha in self.sha_iter():
@@ -123,9 +123,9 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
if candidate is None:
raise BadObject(partial_hexsha)
return candidate
-
+
#} END interface
-
+
def _map_loose_object(self, sha):
"""
:return: memory map of that file to allow random read access
@@ -151,13 +151,13 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
finally:
os.close(fd)
# END assure file is closed
-
+
def set_ostream(self, stream):
""":raise TypeError: if the stream does not support the Sha1Writer interface"""
if stream is not None and not isinstance(stream, Sha1Writer):
raise TypeError("Output stream musst support the %s interface" % Sha1Writer.__name__)
return super(LooseObjectDB, self).set_ostream(stream)
-
+
def info(self, sha):
m = self._map_loose_object(sha)
try:
@@ -166,12 +166,12 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
finally:
m.close()
# END assure release of system resources
-
+
def stream(self, sha):
m = self._map_loose_object(sha)
type, size, stream = DecompressMemMapReader.new(m, close_on_deletion = True)
return OStream(sha, type, size, stream)
-
+
def has_object(self, sha):
try:
self.readable_db_object_path(bin_to_hex(sha))
@@ -179,7 +179,7 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
except BadObject:
return False
# END check existance
-
+
def store(self, istream):
"""note: The sha we produce will be hex by nature"""
tmp_path = None
@@ -187,14 +187,14 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
if writer is None:
# open a tmp file to write the data to
fd, tmp_path = tempfile.mkstemp(prefix='obj', dir=self._root_path)
-
+
if istream.binsha is None:
writer = FDCompressedSha1Writer(fd)
else:
writer = FDStream(fd)
# END handle direct stream copies
# END handle custom writer
-
+
try:
try:
if istream.binsha is not None:
@@ -215,14 +215,14 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
os.remove(tmp_path)
raise
# END assure tmpfile removal on error
-
+
hexsha = None
if istream.binsha:
hexsha = istream.hexsha
else:
hexsha = writer.sha(as_hex=True)
# END handle sha
-
+
if tmp_path:
obj_path = self.db_path(self.object_path(hexsha))
obj_dir = dirname(obj_path)
@@ -234,29 +234,28 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
remove(obj_path)
# END handle win322
rename(tmp_path, obj_path)
-
+
# make sure its readable for all ! It started out as rw-- tmp file
# but needs to be rwrr
chmod(obj_path, self.new_objects_mode)
# END handle dry_run
-
+
istream.binsha = hex_to_bin(hexsha)
return istream
-
+
def sha_iter(self):
# find all files which look like an object, extract sha from there
for root, dirs, files in os.walk(self.root_path()):
root_base = basename(root)
if len(root_base) != 2:
continue
-
+
for f in files:
if len(f) != 38:
continue
yield hex_to_bin(root_base + f)
# END for each file
# END for each walk iteration
-
+
def size(self):
return len(tuple(self.sha_iter()))
-