Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d3e1078

Browse filesBrowse files
author
wangweichen
committed
change codes with open func support encoding="utf-8"
1 parent 5181437 commit d3e1078
Copy full SHA for d3e1078

2 files changed

+14-14Lines changed: 14 additions & 14 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/refs/symbolic.py‎

Copy file name to clipboardExpand all lines: git/refs/symbolic.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
2+
import codecs
33
from git.compat import (
44
string_types,
55
defenc
@@ -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', encoding="utf-8").readlines()[0].strip()
79+
commondir = codecs.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', encoding="utf-8") as fp:
90+
with codecs.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', encoding="utf-8") as fp:
136+
with codecs.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', encoding="utf-8").readlines()[0].strip()
176+
commondir = codecs.open(osp.join(repo.git_dir, 'commondir'), 'rt', encoding="utf-8").readlines()[0].strip()
177177
except (OSError, IOError):
178178
commondir = '.'
179179

Collapse file

‎git/repo/fun.py‎

Copy file name to clipboardExpand all lines: git/repo/fun.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""Package with general repository related functions"""
2+
import codecs
23
import os
4+
import os.path as osp
35
import stat
46
from string import digits
57

6-
from git.compat import xrange
7-
from git.exc import WorkTreeRepositoryUnsupported
8-
from git.objects import Object
9-
from git.refs import SymbolicReference
10-
from git.util import hex_to_bin, bin_to_hex, decygpath
118
from gitdb.exc import (
129
BadObject,
1310
BadName,
1411
)
1512

16-
import os.path as osp
1713
from git.cmd import Git
18-
14+
from git.compat import xrange
15+
from git.exc import WorkTreeRepositoryUnsupported
16+
from git.objects import Object
17+
from git.refs import SymbolicReference
18+
from git.util import hex_to_bin, bin_to_hex, decygpath
1919

2020
__all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_submodule_git_dir', 'name_to_object', 'short_to_long', 'deref_tag',
2121
'to_commit', 'find_worktree_git_dir')
@@ -58,7 +58,7 @@ def find_worktree_git_dir(dotgit):
5858
return None
5959

6060
try:
61-
lines = open(dotgit, 'r', encoding="utf-8").readlines()
61+
lines = codecs.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, encoding="utf-8") as fp:
76+
with codecs.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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.