diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-10-22 11:11:25 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2016-10-22 11:11:25 +0200 |
commit | caa0ea7a0893fe90ea043843d4e6ad407126d7b8 (patch) | |
tree | 2f688eb182f2e76091134c47c4a327681c12e15b /git/index | |
parent | afcd64ebbb770908bd2a751279ff070dea5bb97c (diff) | |
parent | cc77e6b2862733a211c55cf29cc7a83c36c27919 (diff) | |
download | gitpython-caa0ea7a0893fe90ea043843d4e6ad407126d7b8.tar.gz |
Merge branch 'cygwin' of https://github.com/ankostis/GitPython into ankostis-cygwin
Diffstat (limited to 'git/index')
-rw-r--r-- | git/index/base.py | 76 | ||||
-rw-r--r-- | git/index/fun.py | 34 | ||||
-rw-r--r-- | git/index/util.py | 12 |
3 files changed, 60 insertions, 62 deletions
diff --git a/git/index/base.py b/git/index/base.py index c93a999b..80862882 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -3,34 +3,28 @@ # # 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, @@ -38,26 +32,21 @@ from git.objects import ( 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, 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 + +import git.diff as diff +import os.path as osp from .fun import ( entry_key, @@ -69,10 +58,17 @@ from .fun import ( 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') @@ -354,7 +350,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): 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 @@ -374,8 +370,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): 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: @@ -407,7 +403,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): 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: @@ -569,7 +565,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): 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") @@ -617,12 +613,12 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): 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, diff --git a/git/index/fun.py b/git/index/fun.py index ddb04138..7f7518e1 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -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, @@ -9,13 +11,18 @@ from stat import ( 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 @@ -25,6 +32,11 @@ from git.objects.fun import ( 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, @@ -32,23 +44,11 @@ from .typ import ( 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 @@ -59,7 +59,7 @@ __all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key', 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): diff --git a/git/index/util.py b/git/index/util.py index 5d72a9cc..02742a5d 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -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 @@ -32,8 +34,8 @@ class TemporaryFileSwap(object): 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 |