Skip to content

open func support "utf-8" #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
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
Next Next commit
fix open func encoding error.
wangweichen committed Jul 13, 2017
commit 518143743f60a3fc3864fe2f4a6784cc948c96a2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -14,3 +14,4 @@ nbproject
.DS_Store
/*egg-info
/.tox
.idea/
8 changes: 4 additions & 4 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
@@ -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').readlines()[0].strip()
commondir = 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)
@@ -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') as fp:
with open(cls._get_packed_refs_path(repo), 'rt', encoding="utf-8") as fp:
for line in fp:
line = line.strip()
if not line:
@@ -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') as fp:
with 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
@@ -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').readlines()[0].strip()
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
except (OSError, IOError):
commondir = '.'

4 changes: 2 additions & 2 deletions git/repo/fun.py
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ def find_worktree_git_dir(dotgit):
return None

try:
lines = open(dotgit, 'r').readlines()
lines = 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 open(d, encoding="utf-8") as fp:
content = fp.read().rstrip()
except (IOError, OSError):
# it's probably not a file