Skip to content

Support for Python3 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
master_doc = 'index'

# General information about the project.
project = u'GitDB'
copyright = u'2011, Sebastian Thiel'
project = 'GitDB'
copyright = '2011, Sebastian Thiel'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -171,8 +171,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'GitDB.tex', u'GitDB Documentation',
u'Sebastian Thiel', 'manual'),
('index', 'GitDB.tex', 'GitDB Documentation',
'Sebastian Thiel', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
6 changes: 3 additions & 3 deletions gitdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _init_externals():


# default imports
from db import *
from base import *
from stream import *
from .db import *
from .base import *
from .stream import *

4 changes: 2 additions & 2 deletions gitdb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Module with basic data structures - they are designed to be lightweight and fast"""
from util import (
from .util import (
bin_to_hex,
zlib
)

from fun import (
from .fun import (
type_id_to_type_map,
type_to_type_id_map
)
Expand Down
12 changes: 6 additions & 6 deletions gitdb/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php

from base import *
from loose import *
from mem import *
from pack import *
from git import *
from ref import *
from .base import *
from .loose import *
from .mem import *
from .pack import *
from .git import *
from .ref import *

1 change: 1 addition & 0 deletions gitdb/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)

from itertools import chain
from functools import reduce


__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')
Expand Down
8 changes: 4 additions & 4 deletions gitdb/db/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
from base import (
from .base import (
CompoundDB,
ObjectDBW,
FileDBBase
)

from loose import LooseObjectDB
from pack import PackedDB
from ref import ReferenceDB
from .loose import LooseObjectDB
from .pack import PackedDB
from .ref import ReferenceDB

from gitdb.util import LazyMixin
from gitdb.exc import (
Expand Down
10 changes: 5 additions & 5 deletions gitdb/db/loose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
from base import (
from .base import (
FileDBBase,
ObjectDBR,
ObjectDBW
Expand Down Expand Up @@ -69,9 +69,9 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):

# On windows we need to keep it writable, otherwise it cannot be removed
# either
new_objects_mode = 0444
new_objects_mode = 0o444
if os.name == 'nt':
new_objects_mode = 0644
new_objects_mode = 0o644


def __init__(self, root_path):
Expand Down Expand Up @@ -133,7 +133,7 @@ def _map_loose_object(self, sha):
db_path = self.db_path(self.object_path(bin_to_hex(sha)))
try:
return file_contents_ro_filepath(db_path, flags=self._fd_open_flags)
except OSError,e:
except OSError as e:
if e.errno != ENOENT:
# try again without noatime
try:
Expand Down Expand Up @@ -200,7 +200,7 @@ def store(self, istream):
if istream.binsha is not None:
# copy as much as possible, the actual uncompressed item size might
# be smaller than the compressed version
stream_copy(istream.read, writer.write, sys.maxint, self.stream_chunk_size)
stream_copy(istream.read, writer.write, sys.maxsize, self.stream_chunk_size)
else:
# write object with header, we have to make a new one
write_object(istream.type, istream.size, istream.read, writer.write,
Expand Down
8 changes: 4 additions & 4 deletions gitdb/db/mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Contains the MemoryDatabase implementation"""
from loose import LooseObjectDB
from base import (
from .loose import LooseObjectDB
from .base import (
ObjectDBR,
ObjectDBW
)
Expand All @@ -23,7 +23,7 @@
DecompressMemMapReader,
)

from cStringIO import StringIO
from io import StringIO

__all__ = ("MemoryDB", )

Expand Down Expand Up @@ -85,7 +85,7 @@ def size(self):
return len(self._cache)

def sha_iter(self):
return self._cache.iterkeys()
return iter(self._cache.keys())


#{ Interface
Expand Down
5 changes: 3 additions & 2 deletions gitdb/db/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Module containing a database to deal with packs"""
from base import (
from .base import (
FileDBBase,
ObjectDBR,
CachingDB
Expand All @@ -21,6 +21,7 @@

import os
import glob
from functools import reduce

__all__ = ('PackedDB', )

Expand Down Expand Up @@ -104,7 +105,7 @@ def sha_iter(self):
for entity in self.entities():
index = entity.index()
sha_by_index = index.sha
for index in xrange(index.size()):
for index in range(index.size()):
yield sha_by_index(index)
# END for each index
# END for each entity
Expand Down
6 changes: 3 additions & 3 deletions gitdb/db/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
from base import (
from .base import (
CompoundDB,
)

Expand Down Expand Up @@ -33,7 +33,7 @@ def _update_dbs_from_ref_file(self):
dbcls = self.ObjectDBCls
if dbcls is None:
# late import
from git import GitDB
from .git import GitDB
dbcls = GitDB
# END get db type

Expand Down Expand Up @@ -68,7 +68,7 @@ def _update_dbs_from_ref_file(self):
db.databases()
# END verification
self._dbs.append(db)
except Exception, e:
except Exception as e:
# ignore invalid paths or issues
pass
# END for each path to add
Expand Down
2 changes: 1 addition & 1 deletion gitdb/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Module with common exceptions"""
from util import to_hex_sha
from .util import to_hex_sha

class ODBError(Exception):
"""All errors thrown by the object database"""
Expand Down
17 changes: 9 additions & 8 deletions gitdb/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
Keeping this code separate from the beginning makes it easier to out-source
it into c later, if required"""

from exc import (
from .exc import (
BadObjectType
)

from util import zlib
from .util import zlib
from functools import reduce
decompressobj = zlib.decompressobj

import mmap
from itertools import islice, izip
from itertools import islice

from cStringIO import StringIO
from io import StringIO

# INVARIANTS
OFS_DELTA = 6
Expand Down Expand Up @@ -249,7 +250,7 @@ def compress(self):
#if first_data_index is not None:
nd = StringIO() # new data
so = self[first_data_index].to # start offset in target buffer
for x in xrange(first_data_index, i-1):
for x in range(first_data_index, i-1):
xdc = self[x]
nd.write(xdc.data[:xdc.ts])
# END collect data
Expand Down Expand Up @@ -296,10 +297,10 @@ def check_integrity(self, target_size=-1):

left = islice(self, 0, len(self)-1)
right = iter(self)
right.next()
next(right)
# this is very pythonic - we might have just use index based access here,
# but this could actually be faster
for lft,rgt in izip(left, right):
for lft,rgt in zip(left, right):
assert lft.rbound() == rgt.to
assert lft.to + lft.ts == rgt.to
# END for each pair
Expand Down Expand Up @@ -380,7 +381,7 @@ def is_loose_object(m):
"""
:return: True the file contained in memory map m appears to be a loose object.
Only the first two bytes are needed"""
b0, b1 = map(ord, m[:2])
b0, b1 = list(map(ord, m[:2]))
word = (b0 << 8) + b1
return b0 == 0x78 and (word % 31) == 0

Expand Down
20 changes: 10 additions & 10 deletions gitdb/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
UnsupportedOperation,
ParseError
)
from util import (
from .util import (
zlib,
mman,
LazyMixin,
unpack_from,
bin_to_hex,
)

from fun import (
from .fun import (
create_pack_object_header,
pack_object_header_info,
is_equal_canonical_sha,
Expand All @@ -36,7 +36,7 @@
pass
# END try c module

from base import ( # Amazing !
from .base import ( # Amazing !
OInfo,
OStream,
OPackInfo,
Expand All @@ -45,7 +45,7 @@
ODeltaPackInfo,
ODeltaPackStream,
)
from stream import (
from .stream import (
DecompressMemMapReader,
DeltaApplyReader,
Sha1Writer,
Expand All @@ -60,7 +60,7 @@

from binascii import crc32

from itertools import izip

import tempfile
import array
import os
Expand Down Expand Up @@ -200,7 +200,7 @@ def write(self, pack_sha, write):
for t in self._objs:
tmplist[ord(t[0][0])] += 1
#END prepare fanout
for i in xrange(255):
for i in range(255):
v = tmplist[i]
sha_write(pack('>L', v))
tmplist[i+1] += v
Expand Down Expand Up @@ -407,7 +407,7 @@ def offsets(self):
a.byteswap()
return a
else:
return tuple(self.offset(index) for index in xrange(self.size()))
return tuple(self.offset(index) for index in range(self.size()))
# END handle version

def sha_to_index(self, sha):
Expand Down Expand Up @@ -673,8 +673,8 @@ def _set_cache_(self, attr):
else:
iter_offsets = iter(offsets_sorted)
iter_offsets_plus_one = iter(offsets_sorted)
iter_offsets_plus_one.next()
consecutive = izip(iter_offsets, iter_offsets_plus_one)
next(iter_offsets_plus_one)
consecutive = zip(iter_offsets, iter_offsets_plus_one)

offset_map = dict(consecutive)

Expand All @@ -694,7 +694,7 @@ def _iter_objects(self, as_stream):
"""Iterate over all objects in our index and yield their OInfo or OStream instences"""
_sha = self._index.sha
_object = self._object
for index in xrange(self._index.size()):
for index in range(self._index.size()):
yield _object(_sha(index), as_stream, index)
# END for each index

Expand Down
8 changes: 4 additions & 4 deletions gitdb/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php

from cStringIO import StringIO
from io import StringIO
import errno
import mmap
import os

from fun import (
from .fun import (
msb_size,
stream_copy,
apply_delta_data,
Expand All @@ -17,7 +17,7 @@
delta_types
)

from util import (
from .util import (
allocate_memory,
LazyMixin,
make_sha,
Expand Down Expand Up @@ -417,7 +417,7 @@ def _set_cache_brute_(self, attr):
# For the actual copying, we use a seek and write pattern of buffer
# slices.
final_target_size = None
for (dbuf, offset, src_size, target_size), dstream in reversed(zip(buffer_info_list, self._dstreams)):
for (dbuf, offset, src_size, target_size), dstream in reversed(list(zip(buffer_info_list, self._dstreams))):
# allocate a buffer to hold all delta data - fill in the data for
# fast access. We do this as we know that reading individual bytes
# from our stream would be slower than necessary ( although possible )
Expand Down
Loading