Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
change codes with open func support encoding="utf-8"
  • Loading branch information
wangweichen committed Jul 13, 2017
commit d3e10783342ca24fd945766fac005ea0fedb89ec
10 changes: 5 additions & 5 deletions git/refs/symbolic.py
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import os

import codecs
from git.compat import (
string_types,
defenc
Expand DownExpand Up@@ -76,7 +76,7 @@ def abspath(self):
@classmethod
def _get_packed_refs_path(cls, repo):
try:
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
commondir = codecs.open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
except (OSError, IOError):
commondir = '.'
repodir = osp.join(repo.git_dir, commondir)
Expand All@@ -87,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', encoding="utf-8") 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:
Expand DownExpand Up@@ -133,7 +133,7 @@ def _get_ref_info_helper(cls, repo, repodir, ref_path):
point to, or None"""
tokens = None
try:
with open(osp.join(repodir, ref_path), 'rt', encoding="utf-8") 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
Expand DownExpand Up@@ -173,7 +173,7 @@ def _get_ref_info(cls, repo, ref_path):
return cls._get_ref_info_helper(repo, repo.git_dir, ref_path)
except ValueError:
try:
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
commondir = codecs.open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
except (OSError, IOError):
commondir = '.'

Expand Down
18 changes: 9 additions & 9 deletions git/repo/fun.py
Original file line numberDiff line numberDiff line change
@@ -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')
Expand DownExpand Up@@ -58,7 +58,7 @@ def find_worktree_git_dir(dotgit):
return None

try:
lines = open(dotgit, 'r', encoding="utf-8").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
Expand All@@ -73,7 +73,7 @@ def find_submodule_git_dir(d):
return d

try:
with open(d, encoding="utf-8") as fp:
with codecs.open(d, encoding="utf-8") as fp:
content = fp.read().rstrip()
except (IOError, OSError):
# it's probably not a file
Expand Down