Skip to content

Commit 5181437

Browse files
author
wangweichen
committed
fix open func encoding error.
1 parent cf8dc25 commit 5181437

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ nbproject
1414
.DS_Store
1515
/*egg-info
1616
/.tox
17+
.idea/

git/refs/symbolic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def abspath(self):
7676
@classmethod
7777
def _get_packed_refs_path(cls, repo):
7878
try:
79-
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt').readlines()[0].strip()
79+
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
8080
except (OSError, IOError):
8181
commondir = '.'
8282
repodir = osp.join(repo.git_dir, commondir)
@@ -87,7 +87,7 @@ def _iter_packed_refs(cls, repo):
8787
"""Returns an iterator yielding pairs of sha1/path pairs (as bytes) for the corresponding refs.
8888
:note: The packed refs file will be kept open as long as we iterate"""
8989
try:
90-
with open(cls._get_packed_refs_path(repo), 'rt') as fp:
90+
with open(cls._get_packed_refs_path(repo), 'rt', encoding="utf-8") as fp:
9191
for line in fp:
9292
line = line.strip()
9393
if not line:
@@ -133,7 +133,7 @@ def _get_ref_info_helper(cls, repo, repodir, ref_path):
133133
point to, or None"""
134134
tokens = None
135135
try:
136-
with open(osp.join(repodir, ref_path), 'rt') as fp:
136+
with open(osp.join(repodir, ref_path), 'rt', encoding="utf-8") as fp:
137137
value = fp.read().rstrip()
138138
# Don't only split on spaces, but on whitespace, which allows to parse lines like
139139
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -173,7 +173,7 @@ def _get_ref_info(cls, repo, ref_path):
173173
return cls._get_ref_info_helper(repo, repo.git_dir, ref_path)
174174
except ValueError:
175175
try:
176-
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt').readlines()[0].strip()
176+
commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
177177
except (OSError, IOError):
178178
commondir = '.'
179179

git/repo/fun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def find_worktree_git_dir(dotgit):
5858
return None
5959

6060
try:
61-
lines = open(dotgit, 'r').readlines()
61+
lines = open(dotgit, 'r', encoding="utf-8").readlines()
6262
for key, value in [line.strip().split(': ') for line in lines]:
6363
if key == 'gitdir':
6464
return value
@@ -73,7 +73,7 @@ def find_submodule_git_dir(d):
7373
return d
7474

7575
try:
76-
with open(d) as fp:
76+
with open(d, encoding="utf-8") as fp:
7777
content = fp.read().rstrip()
7878
except (IOError, OSError):
7979
# it's probably not a file

0 commit comments

Comments
 (0)