Skip to content
This repository was archived by the owner on Jul 26, 2026. It is now read-only.

Commit b6c493d

Browse files
committed
Pick off the low hanging fruit
This fixes most of the import errors that came from using the implicit relative imports that Python 2 supports. This also fixes the use of `xrange`, which has replaced `range` in Python 3. The same has happened for `izip`, which is also being aliased. The octal number syntax changed in Python 3, so we are now converting from strings using the `int` built-in function, which will produce the same output across both versions of Python.
1 parent 1c6f4c1 commit b6c493d

27 files changed

Lines changed: 228 additions & 164 deletions

gitdb/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def _init_externals():
3232

3333

3434
# default imports
35-
from db import *
36-
from base import *
37-
from stream import *
38-
35+
from gitdb.base import *
36+
from gitdb.db import *
37+
from gitdb.stream import *

gitdb/base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module with basic data structures - they are designed to be lightweight and fast"""
6-
from util import (
7-
bin_to_hex,
8-
zlib
9-
)
10-
11-
from fun import (
12-
type_id_to_type_map,
13-
type_to_type_id_map
14-
)
6+
from gitdb.util import (
7+
bin_to_hex,
8+
zlib
9+
)
10+
11+
from gitdb.fun import (
12+
type_id_to_type_map,
13+
type_to_type_id_map
14+
)
1515

1616
__all__ = ('OInfo', 'OPackInfo', 'ODeltaPackInfo',
1717
'OStream', 'OPackStream', 'ODeltaPackStream',

gitdb/db/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55

6-
from base import *
7-
from loose import *
8-
from mem import *
9-
from pack import *
10-
from git import *
11-
from ref import *
12-
6+
from gitdb.db.base import *
7+
from gitdb.db.loose import *
8+
from gitdb.db.mem import *
9+
from gitdb.db.pack import *
10+
from gitdb.db.git import *
11+
from gitdb.db.ref import *

gitdb/db/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121

2222
from itertools import chain
23+
from functools import reduce
2324

2425

2526
__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')

gitdb/db/git.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from base import (
6-
CompoundDB,
7-
ObjectDBW,
8-
FileDBBase
9-
)
10-
11-
from loose import LooseObjectDB
12-
from pack import PackedDB
13-
from ref import ReferenceDB
5+
from gitdb.db.base import (
6+
CompoundDB,
7+
ObjectDBW,
8+
FileDBBase
9+
)
10+
11+
from gitdb.db.loose import LooseObjectDB
12+
from gitdb.db.pack import PackedDB
13+
from gitdb.db.ref import ReferenceDB
1414

1515
from gitdb.util import LazyMixin
1616
from gitdb.exc import (

gitdb/db/loose.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from base import (
6-
FileDBBase,
7-
ObjectDBR,
8-
ObjectDBW
9-
)
5+
from gitdb.db.base import (
6+
FileDBBase,
7+
ObjectDBR,
8+
ObjectDBW
9+
)
1010

1111

1212
from gitdb.exc import (
@@ -69,11 +69,11 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
6969

7070
# On windows we need to keep it writable, otherwise it cannot be removed
7171
# either
72-
new_objects_mode = 0444
72+
new_objects_mode = int("444", 8)
7373
if os.name == 'nt':
74-
new_objects_mode = 0644
75-
76-
74+
new_objects_mode = int("644", 8)
75+
76+
7777
def __init__(self, root_path):
7878
super(LooseObjectDB, self).__init__(root_path)
7979
self._hexsha_to_file = dict()
@@ -133,7 +133,7 @@ def _map_loose_object(self, sha):
133133
db_path = self.db_path(self.object_path(bin_to_hex(sha)))
134134
try:
135135
return file_contents_ro_filepath(db_path, flags=self._fd_open_flags)
136-
except OSError,e:
136+
except OSError as e:
137137
if e.errno != ENOENT:
138138
# try again without noatime
139139
try:

gitdb/db/mem.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Contains the MemoryDatabase implementation"""
6-
from loose import LooseObjectDB
7-
from base import (
8-
ObjectDBR,
9-
ObjectDBW
10-
)
6+
from gitdb.db.loose import LooseObjectDB
7+
from gitdb.db.base import (
8+
ObjectDBR,
9+
ObjectDBW
10+
)
1111

1212
from gitdb.base import (
1313
OStream,
@@ -19,7 +19,18 @@
1919
UnsupportedOperation
2020
)
2121

22-
from cStringIO import StringIO
22+
from gitdb.stream import (
23+
ZippedStoreShaWriter,
24+
DecompressMemMapReader,
25+
)
26+
27+
try:
28+
from cStringIO import StringIO
29+
except ImportError:
30+
try:
31+
from StringIO import StringIO
32+
except ImportError:
33+
from io import StringIO
2334

2435
__all__ = ("MemoryDB", )
2536

gitdb/db/pack.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module containing a database to deal with packs"""
6-
from base import (
7-
FileDBBase,
8-
ObjectDBR,
9-
CachingDB
10-
)
6+
from gitdb.db.base import (
7+
FileDBBase,
8+
ObjectDBR,
9+
CachingDB
10+
)
1111

1212
from gitdb.util import LazyMixin
1313

@@ -19,6 +19,8 @@
1919

2020
from gitdb.pack import PackEntity
2121

22+
from functools import reduce
23+
2224
import os
2325
import glob
2426

@@ -104,7 +106,7 @@ def sha_iter(self):
104106
for entity in self.entities():
105107
index = entity.index()
106108
sha_by_index = index.sha
107-
for index in xrange(index.size()):
109+
for index in range(index.size()):
108110
yield sha_by_index(index)
109111
# END for each index
110112
# END for each entity

gitdb/db/ref.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5-
from base import (
6-
CompoundDB,
7-
)
5+
from gitdb.db.base import (
6+
CompoundDB,
7+
)
88

99
import os
1010
__all__ = ('ReferenceDB', )
@@ -33,7 +33,7 @@ def _update_dbs_from_ref_file(self):
3333
dbcls = self.ObjectDBCls
3434
if dbcls is None:
3535
# late import
36-
from git import GitDB
36+
from gitdb.db.git import GitDB
3737
dbcls = GitDB
3838
# END get db type
3939

@@ -68,7 +68,7 @@ def _update_dbs_from_ref_file(self):
6868
db.databases()
6969
# END verification
7070
self._dbs.append(db)
71-
except Exception, e:
71+
except Exception:
7272
# ignore invalid paths or issues
7373
pass
7474
# END for each path to add

gitdb/exc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module with common exceptions"""
6-
from util import to_hex_sha
6+
from gitdb.util import to_hex_sha
77

88
class ODBError(Exception):
99
"""All errors thrown by the object database"""

0 commit comments

Comments
 (0)