diff --git a/.gitignore b/.gitignore index d35cddebd..b3bc93624 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ nbproject .DS_Store /*egg-info /.tox +.idea/ \ No newline at end of file diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index bef6ba3ce..53e987a72 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -1,4 +1,10 @@ import os +import os.path as osp +import codecs +from gitdb.exc import ( + BadObject, + BadName +) from git.compat import ( string_types, @@ -13,16 +19,8 @@ hex_to_bin, LockedFD ) -from gitdb.exc import ( - BadObject, - BadName -) - -import os.path as osp - from .log import RefLog - __all__ = ["SymbolicReference"] @@ -35,7 +33,6 @@ def _git_dir(repo, path): class SymbolicReference(object): - """Represents a special case of a reference such that this reference is symbolic. It does not point to a specific commit, but to another Head, which itself specifies a commit. @@ -90,7 +87,7 @@ def _iter_packed_refs(cls, repo): """Returns an iterator yielding pairs of sha1/path pairs (as bytes) for the corresponding refs. :note: The packed refs file will be kept open as long as we iterate""" try: - with open(cls._get_packed_refs_path(repo), 'rt') as fp: + with codecs.open(cls._get_packed_refs_path(repo), 'rt', encoding="utf-8") as fp: for line in fp: line = line.strip() if not line: @@ -108,14 +105,14 @@ def _iter_packed_refs(cls, repo): continue yield tuple(line.split(' ', 1)) - # END for each line + # END for each line except (OSError, IOError): return - # END no packed-refs file handling - # NOTE: Had try-finally block around here to close the fp, - # but some python version wouldn't allow yields within that. - # I believe files are closing themselves on destruction, so it is - # alright. + # END no packed-refs file handling + # NOTE: Had try-finally block around here to close the fp, + # but some python version wouldn't allow yields within that. + # I believe files are closing themselves on destruction, so it is + # alright. @classmethod def dereference_recursive(cls, repo, ref_path): @@ -127,7 +124,7 @@ def dereference_recursive(cls, repo, ref_path): hexsha, ref_path = cls._get_ref_info(repo, ref_path) if hexsha is not None: return hexsha - # END recursive dereferencing + # END recursive dereferencing @classmethod def _get_ref_info_helper(cls, repo, ref_path): @@ -137,12 +134,12 @@ def _get_ref_info_helper(cls, repo, ref_path): tokens = None repodir = _git_dir(repo, ref_path) try: - with open(osp.join(repodir, ref_path), 'rt') as fp: + with codecs.open(osp.join(repodir, ref_path), 'rt', encoding="utf-8") 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 tokens = value.split() - assert(len(tokens) != 0) + assert (len(tokens) != 0) except (OSError, IOError): # Probably we are just packed, find our entry in the packed refs file # NOTE: We are not a symbolic ref if we are in a packed file, as these @@ -153,7 +150,7 @@ def _get_ref_info_helper(cls, repo, ref_path): # sha will be used tokens = sha, path break - # END for each packed ref + # END for each packed ref # END handle packed refs if tokens is None: raise ValueError("Reference at %r does not exist" % ref_path) @@ -216,7 +213,7 @@ def set_commit(self, commit, logmsg=None): invalid_type = self.repo.rev_parse(commit).type != Commit.type except (BadObject, BadName): raise ValueError("Invalid object: %s" % commit) - # END handle exception + # END handle exception # END verify type if invalid_type: @@ -294,11 +291,11 @@ def set_reference(self, ref, logmsg=None): write_value = ref.hexsha elif isinstance(ref, string_types): try: - obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags + obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags write_value = obj.hexsha except (BadObject, BadName): raise ValueError("Could not extract object from %s" % ref) - # END end try string + # END end try string else: raise ValueError("Unrecognized Value: %r" % ref) # END try commit attribute @@ -314,7 +311,7 @@ def set_reference(self, ref, logmsg=None): oldbinsha = self.commit.binsha except ValueError: oldbinsha = Commit.NULL_BIN_SHA - # END handle non-existing + # END handle non-existing # END retrieve old hexsha fpath = self.abspath @@ -470,7 +467,7 @@ def delete(cls, repo, path): reflog_path = RefLog.path(cls(repo, full_ref_path)) if osp.isfile(reflog_path): os.remove(reflog_path) - # END remove reflog + # END remove reflog @classmethod def _create(cls, repo, path, resolve, reference, force, logmsg=None): @@ -566,8 +563,8 @@ def rename(self, new_path, force=False): f2 = fd2.read().strip() if f1 != f2: raise OSError("File at path %r already exists" % new_abs_path) - # else: we could remove ourselves and use the otherone, but - # but clarity we just continue as usual + # else: we could remove ourselves and use the otherone, but + # but clarity we just continue as usual # END not force handling os.remove(new_abs_path) # END handle existing target file @@ -602,14 +599,14 @@ def _iter_items(cls, repo, common_path=None): continue abs_path = to_native_path_linux(join_path(root, f)) rela_paths.add(abs_path.replace(to_native_path_linux(repo.common_dir) + '/', "")) - # END for each file in root directory + # END for each file in root directory # END for each directory to walk # read packed refs for sha, rela_path in cls._iter_packed_refs(repo): # @UnusedVariable if rela_path.startswith(common_path): rela_paths.add(rela_path) - # END relative path matches common path + # END relative path matches common path # END packed refs reading # return paths in sorted order @@ -618,7 +615,7 @@ def _iter_items(cls, repo, common_path=None): yield cls.from_path(repo, path) except ValueError: continue - # END for each sorted relative refpath + # END for each sorted relative refpath @classmethod def iter_items(cls, repo, common_path=None): @@ -662,7 +659,7 @@ def from_path(cls, repo, path): return instance except ValueError: pass - # END exception handling + # END exception handling # END for each type to try raise ValueError("Could not find reference type suitable to handle path %r" % path) diff --git a/git/repo/fun.py b/git/repo/fun.py index 6aefd9d66..21f1ec00c 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -1,21 +1,21 @@ """Package with general repository related functions""" +import codecs import os +import os.path as osp import stat from string import digits -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, decygpath from gitdb.exc import ( BadObject, BadName, ) -import os.path as osp from git.cmd import Git - +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, decygpath __all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_submodule_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', 'to_commit', 'find_worktree_git_dir') @@ -58,7 +58,7 @@ def find_worktree_git_dir(dotgit): return None try: - lines = open(dotgit, 'r').readlines() + lines = codecs.open(dotgit, 'r', encoding="utf-8").readlines() for key, value in [line.strip().split(': ') for line in lines]: if key == 'gitdir': return value @@ -73,7 +73,7 @@ def find_submodule_git_dir(d): return d try: - with open(d) as fp: + with codecs.open(d, encoding="utf-8") as fp: content = fp.read().rstrip() except (IOError, OSError): # it's probably not a file