Skip to content

Commit

Permalink
src: import os.path as osp
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Oct 16, 2016
1 parent a2d248b commit 0210e39
Show file tree
Hide file tree
Showing 24 changed files with 361 additions and 332 deletions.
7 changes: 5 additions & 2 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
# flake8: noqa
#@PydevCodeAnalysisIgnore
import inspect
import os
import sys
import inspect

import os.path as osp


__version__ = 'git'

Expand All @@ -16,7 +19,7 @@
def _init_externals():
"""Initialize external projects by putting them into the path"""
if __version__ == 'git':
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'ext', 'gitdb'))
sys.path.insert(0, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))

try:
import gitdb
Expand Down
36 changes: 20 additions & 16 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
"""Module containing module parser implementation able to properly read and write
configuration files"""

import re
try:
import ConfigParser as cp
except ImportError:
# PY3
import configparser as cp
import abc
from functools import wraps
import inspect
import logging
import abc
import os
import re

from functools import wraps

from git.odict import OrderedDict
from git.util import LockFile
from git.compat import (
string_types,
FileType,
Expand All @@ -29,6 +21,18 @@
with_metaclass,
PY3
)
from git.odict import OrderedDict
from git.util import LockFile

import os.path as osp


try:
import ConfigParser as cp
except ImportError:
# PY3
import configparser as cp


__all__ = ('GitConfigParser', 'SectionConstraint')

Expand Down Expand Up @@ -408,15 +412,15 @@ def read(self):
if self._has_includes():
for _, include_path in self.items('include'):
if include_path.startswith('~'):
include_path = os.path.expanduser(include_path)
if not os.path.isabs(include_path):
include_path = osp.expanduser(include_path)
if not osp.isabs(include_path):
if not file_ok:
continue
# end ignore relative paths if we don't know the configuration file path
assert os.path.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
include_path = os.path.join(os.path.dirname(file_path), include_path)
assert osp.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
include_path = osp.join(osp.dirname(file_path), include_path)
# end make include path absolute
include_path = os.path.normpath(include_path)
include_path = osp.normpath(include_path)
if include_path in seen or not os.access(include_path, os.R_OK):
continue
seen.add(include_path)
Expand Down
74 changes: 35 additions & 39 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,36 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import tempfile
import os
import sys
import subprocess
import glob
from io import BytesIO

import os
from stat import S_ISLNK
import subprocess
import sys
import tempfile

from .typ import (
BaseIndexEntry,
IndexEntry,
)

from .util import (
TemporaryFileSwap,
post_clear_cache,
default_index,
git_working_dir
from git.compat import (
izip,
xrange,
string_types,
force_bytes,
defenc,
mviter,
is_win
)

import git.diff as diff
from git.exc import (
GitCommandError,
CheckoutError,
InvalidGitRepositoryError
)

from git.objects import (
Blob,
Submodule,
Tree,
Object,
Commit,
)

from git.objects.util import Serializable
from git.compat import (
izip,
xrange,
string_types,
force_bytes,
defenc,
mviter,
is_win
)

from git.util import (
LazyMixin,
LockedFD,
Expand All @@ -58,6 +41,12 @@
to_native_path_linux,
unbare_repo
)
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

from .fun import (
entry_key,
Expand All @@ -69,10 +58,17 @@
S_IFGITLINK,
run_commit_hook
)
from .typ import (
BaseIndexEntry,
IndexEntry,
)
from .util import (
TemporaryFileSwap,
post_clear_cache,
default_index,
git_working_dir
)

from gitdb.base import IStream
from gitdb.db import MemoryDB
from gitdb.util import to_bin_sha

__all__ = ('IndexFile', 'CheckoutError')

Expand Down Expand Up @@ -354,7 +350,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
index.entries # force it to read the file as we will delete the temp-file
del(index_handler) # release as soon as possible
finally:
if os.path.exists(tmp_index):
if osp.exists(tmp_index):
os.remove(tmp_index)
# END index merge handling

Expand All @@ -374,8 +370,8 @@ def raise_exc(e):
rs = r + os.sep
for path in paths:
abs_path = path
if not os.path.isabs(abs_path):
abs_path = os.path.join(r, path)
if not osp.isabs(abs_path):
abs_path = osp.join(r, path)
# END make absolute path

try:
Expand Down Expand Up @@ -407,7 +403,7 @@ def raise_exc(e):
for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable
for rela_file in files:
# add relative paths only
yield os.path.join(root.replace(rs, ''), rela_file)
yield osp.join(root.replace(rs, ''), rela_file)
# END for each file in subdir
# END for each subdirectory
except OSError:
Expand Down Expand Up @@ -569,7 +565,7 @@ def _process_diff_args(self, args):
def _to_relative_path(self, path):
""":return: Version of path relative to our git directory or raise ValueError
if it is not within our git direcotory"""
if not os.path.isabs(path):
if not osp.isabs(path):
return path
if self.repo.bare:
raise InvalidGitRepositoryError("require non-bare repository")
Expand Down Expand Up @@ -617,12 +613,12 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
entries_added = list()
if path_rewriter:
for path in paths:
if os.path.isabs(path):
if osp.isabs(path):
abspath = path
gitrelative_path = path[len(self.repo.working_tree_dir) + 1:]
else:
gitrelative_path = path
abspath = os.path.join(self.repo.working_tree_dir, gitrelative_path)
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
# end obtain relative and absolute paths

blob = Blob(self.repo, Blob.NULL_BIN_SHA,
Expand Down
34 changes: 17 additions & 17 deletions git/index/fun.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Contains standalone functions to accompany the index implementation and make it
# more versatile
# NOTE: Autodoc hates it if this is a docstring
from io import BytesIO
import os
from stat import (
S_IFDIR,
S_IFLNK,
Expand All @@ -9,13 +11,18 @@
S_IFMT,
S_IFREG,
)

from io import BytesIO
import os
import subprocess

from git.util import IndexFileSHA1Writer, finalize_process
from git.cmd import PROC_CREATIONFLAGS, handle_process_output
from git.compat import (
PY3,
defenc,
force_text,
force_bytes,
is_posix,
safe_encode,
safe_decode,
)
from git.exc import (
UnmergedEntriesError,
HookExecutionError
Expand All @@ -25,30 +32,23 @@
traverse_tree_recursive,
traverse_trees_recursive
)
from git.util import IndexFileSHA1Writer, finalize_process
from gitdb.base import IStream
from gitdb.typ import str_tree_type

import os.path as osp

from .typ import (
BaseIndexEntry,
IndexEntry,
CE_NAMEMASK,
CE_STAGESHIFT
)

from .util import (
pack,
unpack
)

from gitdb.base import IStream
from gitdb.typ import str_tree_type
from git.compat import (
PY3,
defenc,
force_text,
force_bytes,
is_posix,
safe_encode,
safe_decode,
)

S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
CE_NAMEMASK_INV = ~CE_NAMEMASK
Expand All @@ -59,7 +59,7 @@

def hook_path(name, git_dir):
""":return: path to the given named hook in the given git repository directory"""
return os.path.join(git_dir, 'hooks', name)
return osp.join(git_dir, 'hooks', name)


def run_commit_hook(name, index):
Expand Down
12 changes: 7 additions & 5 deletions git/index/util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Module containing index utilities"""
from functools import wraps
import os
import struct
import tempfile
import os

from functools import wraps

from git.compat import is_win

import os.path as osp


__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')

#{ Aliases
Expand All @@ -32,8 +34,8 @@ def __init__(self, file_path):
pass

def __del__(self):
if os.path.isfile(self.tmp_file_path):
if is_win and os.path.exists(self.file_path):
if osp.isfile(self.tmp_file_path):
if is_win and osp.exists(self.file_path):
os.remove(self.file_path)
os.rename(self.tmp_file_path, self.file_path)
# END temp file exists
Expand Down
Loading

0 comments on commit 0210e39

Please sign in to comment.