diff options
author | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-10-15 13:42:33 +0200 |
---|---|---|
committer | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-10-16 02:46:32 +0200 |
commit | b02662d4e870a34d2c6d97d4f702fcc1311e5177 (patch) | |
tree | 6f2bc1d942f979b3bb379d833700fe33f955415d | |
parent | 0210e394e0776d0b7097bf666bebd690ed0c0e4f (diff) | |
download | gitpython-b02662d4e870a34d2c6d97d4f702fcc1311e5177.tar.gz |
src: reduce needless deps to `gitdb.util`
-rw-r--r-- | git/db.py | 5 | ||||
-rw-r--r-- | git/diff.py | 13 | ||||
-rw-r--r-- | git/index/base.py | 4 | ||||
-rw-r--r-- | git/objects/base.py | 13 | ||||
-rw-r--r-- | git/objects/commit.py | 2 | ||||
-rw-r--r-- | git/objects/tag.py | 9 | ||||
-rw-r--r-- | git/objects/tree.py | 4 | ||||
-rw-r--r-- | git/refs/log.py | 36 | ||||
-rw-r--r-- | git/refs/remote.py | 9 | ||||
-rw-r--r-- | git/refs/symbolic.py | 38 | ||||
-rw-r--r-- | git/remote.py | 35 | ||||
-rw-r--r-- | git/repo/base.py | 33 | ||||
-rw-r--r-- | git/repo/fun.py | 23 | ||||
-rw-r--r-- | git/test/performance/test_streams.py | 2 | ||||
-rw-r--r-- | git/test/test_base.py | 2 | ||||
-rw-r--r-- | git/test/test_db.py | 2 | ||||
-rw-r--r-- | git/test/test_fun.py | 31 | ||||
-rw-r--r-- | git/test/test_index.py | 3 | ||||
-rw-r--r-- | git/test/test_reflog.py | 3 | ||||
-rw-r--r-- | git/test/test_repo.py | 3 | ||||
-rw-r--r-- | git/util.py | 5 |
21 files changed, 124 insertions, 151 deletions
@@ -1,12 +1,9 @@ """Module with our own gitdb implementation - it uses the git command""" +from git.util import bin_to_hex, hex_to_bin from gitdb.base import ( OInfo, OStream ) -from gitdb.util import ( - bin_to_hex, - hex_to_bin -) from gitdb.db import GitDB # @UnusedImport from gitdb.db import LooseObjectDB diff --git a/git/diff.py b/git/diff.py index 35c7ff86..52dbf3a7 100644 --- a/git/diff.py +++ b/git/diff.py @@ -5,18 +5,17 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import re -from gitdb.util import hex_to_bin +from git.cmd import handle_process_output +from git.compat import ( + defenc, + PY3 +) +from git.util import finalize_process, hex_to_bin from .compat import binary_type from .objects.blob import Blob from .objects.util import mode_str_to_int -from git.compat import ( - defenc, - PY3 -) -from git.cmd import handle_process_output -from git.util import finalize_process __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') diff --git a/git/index/base.py b/git/index/base.py index 1e423df4..95ad8b05 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -39,11 +39,11 @@ from git.util import ( join_path_native, file_contents_ro, to_native_path_linux, - unbare_repo + unbare_repo, + to_bin_sha ) from gitdb.base import IStream from gitdb.db import MemoryDB -from gitdb.util import to_bin_sha import git.diff as diff import os.path as osp diff --git a/git/objects/base.py b/git/objects/base.py index 0b849960..d6080779 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -3,14 +3,13 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -from .util import get_object_type_by_name -from git.util import LazyMixin, join_path_native, stream_copy -from gitdb.util import ( - bin_to_hex, - basename -) +from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex import gitdb.typ as dbtyp +import os.path as osp + +from .util import get_object_type_by_name + _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" @@ -170,7 +169,7 @@ class IndexObject(Object): @property def name(self): """:return: Name portion of the path, effectively being the basename""" - return basename(self.path) + return osp.basename(self.path) @property def abspath(self): diff --git a/git/objects/commit.py b/git/objects/commit.py index 1534c552..85955806 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -5,8 +5,8 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php from gitdb import IStream -from gitdb.util import hex_to_bin from git.util import ( + hex_to_bin, Actor, Iterable, Stats, diff --git a/git/objects/tag.py b/git/objects/tag.py index cefff083..19cb04bf 100644 --- a/git/objects/tag.py +++ b/git/objects/tag.py @@ -5,12 +5,9 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """ Module containing all object based types. """ from . import base -from .util import ( - get_object_type_by_name, - parse_actor_and_date -) -from gitdb.util import hex_to_bin -from git.compat import defenc +from .util import get_object_type_by_name, parse_actor_and_date +from ..util import hex_to_bin +from ..compat import defenc __all__ = ("TagObject", ) diff --git a/git/objects/tree.py b/git/objects/tree.py index 4f853f92..46fe63e7 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php from git.util import join_path import git.diff as diff -from gitdb.util import to_bin_sha +from git.util import to_bin_sha from . import util from .base import IndexObject @@ -18,7 +18,7 @@ from .fun import ( tree_to_stream ) -from gitdb.utils.compat import PY3 +from git.compat import PY3 if PY3: cmp = lambda a, b: (a > b) - (a < b) diff --git a/git/refs/log.py b/git/refs/log.py index 3078355d..bab6ae04 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -1,31 +1,29 @@ +import re +import time + +from git.compat import ( + PY3, + xrange, + string_types, + defenc +) +from git.objects.util import ( + parse_date, + Serializable, + altz_to_utctz_str, +) from git.util import ( Actor, LockedFD, LockFile, assure_directory_exists, to_native_path, -) - -from gitdb.util import ( bin_to_hex, - join, - file_contents_ro_filepath, + file_contents_ro_filepath ) -from git.objects.util import ( - parse_date, - Serializable, - altz_to_utctz_str, -) -from git.compat import ( - PY3, - xrange, - string_types, - defenc -) +import os.path as osp -import time -import re __all__ = ["RefLog", "RefLogEntry"] @@ -185,7 +183,7 @@ class RefLog(list, Serializable): instance would be found. The path is not guaranteed to point to a valid file though. :param ref: SymbolicReference instance""" - return join(ref.repo.git_dir, "logs", to_native_path(ref.path)) + return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path)) @classmethod def iter_entries(cls, stream): diff --git a/git/refs/remote.py b/git/refs/remote.py index 1f256b75..4fc784d1 100644 --- a/git/refs/remote.py +++ b/git/refs/remote.py @@ -1,9 +1,10 @@ +import os + from git.util import join_path -from gitdb.util import join -from .head import Head +import os.path as osp -import os +from .head import Head __all__ = ["RemoteReference"] @@ -36,7 +37,7 @@ class RemoteReference(Head): # and delete remainders manually for ref in refs: try: - os.remove(join(repo.git_dir, ref.path)) + os.remove(osp.join(repo.git_dir, ref.path)) except OSError: pass # END for each ref diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index d1c412c8..3a93d81c 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -9,22 +9,14 @@ from git.util import ( join_path, join_path_native, to_native_path_linux, - assure_directory_exists + assure_directory_exists, + hex_to_bin, + LockedFD ) from gitdb.exc import ( BadObject, BadName ) -from gitdb.util import ( - join, - dirname, - isdir, - exists, - isfile, - rename, - hex_to_bin, - LockedFD -) import os.path as osp @@ -83,7 +75,7 @@ class SymbolicReference(object): @classmethod def _get_packed_refs_path(cls, repo): - return join(repo.git_dir, 'packed-refs') + return osp.join(repo.git_dir, 'packed-refs') @classmethod def _iter_packed_refs(cls, repo): @@ -136,7 +128,7 @@ class SymbolicReference(object): point to, or None""" tokens = None try: - with open(join(repo.git_dir, ref_path), 'rt') as fp: + with open(osp.join(repo.git_dir, ref_path), 'rt') as fp: value = fp.read().rstrip() # Don't only split on spaces, but on whitespace, which allows to parse lines like # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo @@ -420,8 +412,8 @@ class SymbolicReference(object): or just "myreference", hence 'refs/' is implied. Alternatively the symbolic reference to be deleted""" full_ref_path = cls.to_full_path(path) - abs_path = join(repo.git_dir, full_ref_path) - if exists(abs_path): + abs_path = osp.join(repo.git_dir, full_ref_path) + if osp.exists(abs_path): os.remove(abs_path) else: # check packed refs @@ -472,14 +464,14 @@ class SymbolicReference(object): corresponding object and a detached symbolic reference will be created instead""" full_ref_path = cls.to_full_path(path) - abs_ref_path = join(repo.git_dir, full_ref_path) + abs_ref_path = osp.join(repo.git_dir, full_ref_path) # figure out target data target = reference if resolve: target = repo.rev_parse(str(reference)) - if not force and isfile(abs_ref_path): + if not force and osp.isfile(abs_ref_path): target_data = str(target) if isinstance(target, SymbolicReference): target_data = target.path @@ -546,9 +538,9 @@ class SymbolicReference(object): if self.path == new_path: return self - new_abs_path = join(self.repo.git_dir, new_path) - cur_abs_path = join(self.repo.git_dir, self.path) - if isfile(new_abs_path): + new_abs_path = osp.join(self.repo.git_dir, new_path) + cur_abs_path = osp.join(self.repo.git_dir, self.path) + if osp.isfile(new_abs_path): if not force: # if they point to the same file, its not an error with open(new_abs_path, 'rb') as fd1: @@ -563,12 +555,12 @@ class SymbolicReference(object): os.remove(new_abs_path) # END handle existing target file - dname = dirname(new_abs_path) - if not isdir(dname): + dname = osp.dirname(new_abs_path) + if not osp.isdir(dname): os.makedirs(dname) # END create directory - rename(cur_abs_path, new_abs_path) + os.rename(cur_abs_path, new_abs_path) self.path = new_path return self diff --git a/git/remote.py b/git/remote.py index 71585a41..b920079d 100644 --- a/git/remote.py +++ b/git/remote.py @@ -5,8 +5,25 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php # Module implementing a remote object allowing easy access to git remotes +import logging import re +from git.cmd import handle_process_output, Git +from git.compat import (defenc, force_text, is_win) +from git.exc import GitCommandError +from git.util import ( + LazyMixin, + Iterable, + IterableList, + RemoteProgress, + CallableRemoteProgress +) +from git.util import ( + join_path, +) + +import os.path as osp + from .config import ( SectionConstraint, cp, @@ -18,21 +35,7 @@ from .refs import ( SymbolicReference, TagReference ) -from git.util import ( - LazyMixin, - Iterable, - IterableList, - RemoteProgress, - CallableRemoteProgress -) -from git.util import ( - join_path, -) -from git.cmd import handle_process_output, Git -from gitdb.util import join -from git.compat import (defenc, force_text, is_win) -import logging -from git.exc import GitCommandError + log = logging.getLogger('git.remote') @@ -644,7 +647,7 @@ class Remote(LazyMixin, Iterable): continue # read head information - with open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb') as fp: + with open(osp.join(self.repo.git_dir, 'FETCH_HEAD'), 'rb') as fp: fetch_head_info = [l.decode(defenc) for l in fp.readlines()] l_fil = len(fetch_info_lines) diff --git a/git/repo/base.py b/git/repo/base.py index af923bde..20b3fa27 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -29,12 +29,7 @@ from git.index import IndexFile from git.objects import Submodule, RootModule, Commit from git.refs import HEAD, Head, Reference, TagReference from git.remote import Remote, add_progress, to_progress_instance -from git.util import Actor, finalize_process, decygpath -from gitdb.util import ( - join, - isfile, - hex_to_bin -) +from git.util import Actor, finalize_process, decygpath, hex_to_bin import os.path as osp @@ -138,7 +133,7 @@ class Repo(object): self._working_tree_dir = osp.dirname(self.git_dir) break - gitpath = find_git_dir(join(curpath, '.git')) + gitpath = find_git_dir(osp.join(curpath, '.git')) if gitpath is not None: self.git_dir = osp.normpath(gitpath) self._working_tree_dir = curpath @@ -171,7 +166,7 @@ class Repo(object): self.git = self.GitCommandWrapperType(self.working_dir) # special handling, in special times - args = [join(self.git_dir, 'objects')] + args = [osp.join(self.git_dir, 'objects')] if issubclass(odbt, GitCmdObjectDB): args.append(self.git) self.odb = odbt(*args) @@ -193,12 +188,12 @@ class Repo(object): # Description property def _get_description(self): - filename = join(self.git_dir, 'description') + filename = osp.join(self.git_dir, 'description') with open(filename, 'rb') as fp: return fp.read().rstrip().decode(defenc) def _set_description(self, descr): - filename = join(self.git_dir, 'description') + filename = osp.join(self.git_dir, 'description') with open(filename, 'wb') as fp: fp.write((descr + '\n').encode(defenc)) @@ -363,11 +358,11 @@ class Repo(object): return "/etc/gitconfig" elif config_level == "user": config_home = os.environ.get("XDG_CONFIG_HOME") or osp.join(os.environ.get("HOME", '~'), ".config") - return osp.normpath(osp.expanduser(join(config_home, "git", "config"))) + return osp.normpath(osp.expanduser(osp.join(config_home, "git", "config"))) elif config_level == "global": return osp.normpath(osp.expanduser("~/.gitconfig")) elif config_level == "repository": - return osp.normpath(join(self.git_dir, "config")) + return osp.normpath(osp.join(self.git_dir, "config")) raise ValueError("Invalid configuration level: %r" % config_level) @@ -511,11 +506,11 @@ class Repo(object): return True def _get_daemon_export(self): - filename = join(self.git_dir, self.DAEMON_EXPORT_FILE) + filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE) return osp.exists(filename) def _set_daemon_export(self, value): - filename = join(self.git_dir, self.DAEMON_EXPORT_FILE) + filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE) fileexists = osp.exists(filename) if value and not fileexists: touch(filename) @@ -531,7 +526,7 @@ class Repo(object): """The list of alternates for this repo from which objects can be retrieved :return: list of strings being pathnames of alternates""" - alternates_path = join(self.git_dir, 'objects', 'info', 'alternates') + alternates_path = osp.join(self.git_dir, 'objects', 'info', 'alternates') if osp.exists(alternates_path): with open(alternates_path, 'rb') as f: @@ -551,9 +546,9 @@ class Repo(object): :note: The method does not check for the existance of the paths in alts as the caller is responsible.""" - alternates_path = join(self.git_dir, 'objects', 'info', 'alternates') + alternates_path = osp.join(self.git_dir, 'objects', 'info', 'alternates') if not alts: - if isfile(alternates_path): + if osp.isfile(alternates_path): os.remove(alternates_path) else: with open(alternates_path, 'wb') as f: @@ -582,7 +577,7 @@ class Repo(object): default_args.append(path) if index: # diff index against HEAD - if isfile(self.index.path) and \ + if osp.isfile(self.index.path) and \ len(self.git.diff('--cached', *default_args)): return True # END index handling @@ -881,7 +876,7 @@ class Repo(object): # our git command could have a different working dir than our actual # environment, hence we prepend its working dir if required if not osp.isabs(path) and git.working_dir: - path = join(git._working_dir, path) + path = osp.join(git._working_dir, path) # adjust remotes - there may be operating systems which use backslashes, # These might be given as initial paths, but when handling the config file diff --git a/git/repo/fun.py b/git/repo/fun.py index c770fd43..5fe8682d 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -6,18 +6,11 @@ from git.compat import xrange from git.exc import WorkTreeRepositoryUnsupported from git.objects import Object from git.refs import SymbolicReference +from git.util import hex_to_bin, bin_to_hex from gitdb.exc import ( BadObject, BadName, ) -from gitdb.util import ( - join, - isdir, - isfile, - dirname, - hex_to_bin, - bin_to_hex -) import os.path as osp @@ -40,13 +33,15 @@ def is_git_dir(d): but at least clearly indicates that we don't support it. There is the unlikely danger to throw if we see directories which just look like a worktree dir, but are none.""" - if isdir(d): - if isdir(join(d, 'objects')) and isdir(join(d, 'refs')): - headref = join(d, 'HEAD') - return isfile(headref) or \ + if osp.isdir(d): + if osp.isdir(osp.join(d, 'objects')) and osp.isdir(osp.join(d, 'refs')): + headref = osp.join(d, 'HEAD') + return osp.isfile(headref) or \ (osp.islink(headref) and os.readlink(headref).startswith('refs')) - elif isfile(join(d, 'gitdir')) and isfile(join(d, 'commondir')) and isfile(join(d, 'gitfile')): + elif (osp.isfile(osp.join(d, 'gitdir')) and + osp.isfile(osp.join(d, 'commondir')) and + osp.isfile(osp.join(d, 'gitfile'))): raise WorkTreeRepositoryUnsupported(d) return False @@ -65,7 +60,7 @@ def find_git_dir(d): if content.startswith('gitdir: '): path = content[8:] if not osp.isabs(path): - path = join(dirname(d), path) + path = osp.join(osp.dirname(d), path) return find_git_dir(path) # end handle exception return None diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py index 699aa25b..3909d8ff 100644 --- a/git/test/performance/test_streams.py +++ b/git/test/performance/test_streams.py @@ -9,12 +9,12 @@ from time import time from git.test.lib import ( with_rw_repo ) +from git.util import bin_to_hex from gitdb import ( LooseObjectDB, IStream ) from gitdb.test.lib import make_memory_file -from gitdb.util import bin_to_hex import os.path as osp diff --git a/git/test/test_base.py b/git/test/test_base.py index 576df961..cec40de8 100644 --- a/git/test/test_base.py +++ b/git/test/test_base.py @@ -23,7 +23,7 @@ from git.test.lib import ( with_rw_repo, with_rw_and_rw_remote_repo ) -from gitdb.util import hex_to_bin +from git.util import hex_to_bin import git.objects.base as base import os.path as osp diff --git a/git/test/test_db.py b/git/test/test_db.py index 1741e7b9..8f67dd48 100644 --- a/git/test/test_db.py +++ b/git/test/test_db.py @@ -6,7 +6,7 @@ from git.db import GitCmdObjectDB from git.exc import BadObject from git.test.lib import TestBase -from gitdb.util import bin_to_hex +from git.util import bin_to_hex import os.path as osp diff --git a/git/test/test_fun.py b/git/test/test_fun.py index 40d040b9..3be25e3e 100644 --- a/git/test/test_fun.py +++ b/git/test/test_fun.py @@ -1,6 +1,13 @@ -from git.test.lib import ( - TestBase, - with_rw_repo +from io import BytesIO +from stat import ( + S_IFDIR, + S_IFREG, + S_IFLNK +) + +from git.index import IndexFile +from git.index.fun import ( + aggressive_tree_merge ) from git.objects.fun import ( traverse_tree_recursive, @@ -8,24 +15,14 @@ from git.objects.fun import ( tree_to_stream, tree_entries_from_data ) - -from git.index.fun import ( - aggressive_tree_merge +from git.test.lib import ( + TestBase, + with_rw_repo ) - -from gitdb.util import bin_to_hex +from git.util import bin_to_hex from gitdb.base import IStream from gitdb.typ import str_tree_type -from stat import ( - S_IFDIR, - S_IFREG, - S_IFLNK -) - -from git.index import IndexFile -from io import BytesIO - class TestFun(TestBase): diff --git a/git/test/test_index.py b/git/test/test_index.py index 0fdc120c..99b35db7 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -45,9 +45,8 @@ from git.test.lib import ( ) from git.test.lib import with_rw_directory from git.util import Actor, rmtree -from git.util import HIDE_WINDOWS_KNOWN_ERRORS +from git.util import HIDE_WINDOWS_KNOWN_ERRORS, hex_to_bin from gitdb.base import IStream -from gitdb.util import hex_to_bin import os.path as osp diff --git a/git/test/test_reflog.py b/git/test/test_reflog.py index e43a1dc0..20495be1 100644 --- a/git/test/test_reflog.py +++ b/git/test/test_reflog.py @@ -10,8 +10,7 @@ from git.test.lib import ( TestBase, fixture_path ) -from git.util import Actor, rmtree -from gitdb.util import hex_to_bin +from git.util import Actor, rmtree, hex_to_bin import os.path as osp diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 4b21db4b..495c4337 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -52,8 +52,7 @@ from git.test.lib import ( ) from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath from git.test.lib import with_rw_directory -from git.util import join_path_native, rmtree, rmfile -from gitdb.util import bin_to_hex +from git.util import join_path_native, rmtree, rmfile, bin_to_hex from unittest import SkipTest import functools as fnt diff --git a/git/util.py b/git/util.py index 9658baa9..fdb12529 100644 --- a/git/util.py +++ b/git/util.py @@ -21,9 +21,12 @@ from gitdb.util import (# NOQA @IgnorePep8 make_sha, LockedFD, # @UnusedImport file_contents_ro, # @UnusedImport + file_contents_ro_filepath, # @UnusedImport LazyMixin, # @UnusedImport to_hex_sha, # @UnusedImport - to_bin_sha # @UnusedImport + to_bin_sha, # @UnusedImport + bin_to_hex, # @UnusedImport + hex_to_bin, # @UnusedImport ) from git.compat import is_win |