Skip to content

encoding problem in opening packed-refs file(Windows) #750

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
elfel19 opened this issue Apr 23, 2018 · 1 comment · Fixed by #1190
Closed

encoding problem in opening packed-refs file(Windows) #750

elfel19 opened this issue Apr 23, 2018 · 1 comment · Fixed by #1190

Comments

@elfel19
Copy link

elfel19 commented Apr 23, 2018

In my packed-refs file, following contents:

# pack-refs with: peeled fully-peeled sorted 
a5052c65b74b79851e9b91589a83906deb434b8a refs/heads/master
a9a4140068e7108a57cf038c2864def8e27f06d9 refs/heads/test
a5052c65b74b79851e9b91589a83906deb434b8a refs/remotes/origin/commit_test
a5052c65b74b79851e9b91589a83906deb434b8a refs/remotes/origin/master
a9a4140068e7108a57cf038c2864def8e27f06d9 refs/remotes/origin/test
baf762435d9145df5d498962d9c6a4ca9825c66e refs/remotes/origin/ttt
df5227b1e584215e9f69a577b7b284230b5a5e1d refs/tags/테스트
^a9a4140068e7108a57cf038c2864def8e27f06d9

problem encounter from df5227b1e584215e9f69a577b7b284230b5a5e1d refs/tags/테스트,
and error message here:

  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\git\repo\base.py", line 269, in heads
    return Head.list_items(self)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\git\util.py", line 934, in list_items
    out_list.extend(cls.iter_items(repo, *args, **kwargs))
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\git\refs\symbolic.py", line 617, in _iter_items
    for sha, rela_path in cls._iter_packed_refs(repo):  # @UnusedVariable
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\git\refs\symbolic.py", line 94, in _iter_packed_refs
    for line in fp:
UnicodeDecodeError: 'cp949' codec can't decode byte 0xed in position 485: illegal multibyte sequence

(This is not common case of naming for branch or tags name as non-english. but, I need handing for this problem.)

problem point is line no.94 at _iter_packed_refs in symbolic.py.

line 93:with open(osp.join(repodir, ref_path), 'rt') as fp:
line 94:  value = fp.read().rstrip()

when open as fp, properties has

 fp: <_io.TextIOWrapper name='some\\path\\.git\\packed-refs' mode='rt' encoding='cp949'>

and next line value = fp.read().rstrip(), this builtin lib can not read non-unicode string
I think, this expected encoding is 'utf-8' or 'unicode', but is setting for default system language encoder.

So, I modified this line(no.93 and 148 at symbolic.py) for that

#with open(cls._get_packed_refs_path(repo), 'rt') as fp:
#modify: encoding option setting for multilanguage
with open(cls._get_packed_refs_path(repo), 'rt', encoding='utf-8') as fp:

after this modify, it has no problem! but, I worried about some side-effect.
few source code used yet open() function, I can not certain for every coverage from os, encoding system and etc.

please check this problem.

@brondsem
Copy link
Contributor

brondsem commented May 1, 2018

I've encountered a variation on this error when the non-ascii ref is in refs/heads instead of packed-refs.

File '/var/local/env-allura/lib/python2.7/site-packages/git/repo/base.py', line 269 in heads
  return Head.list_items(self)
File '/var/local/env-allura/lib/python2.7/site-packages/git/util.py', line 934 in list_items
  out_list.extend(cls.iter_items(repo, *args, **kwargs))
File '/var/local/env-allura/lib/python2.7/site-packages/git/refs/symbolic.py', line 601 in _iter_items
  for root, dirs, files in os.walk(join_path_native(repo.common_dir, common_path)):
File '/usr/lib64/python2.7/os.py', line 284 in walk
  if isdir(join(top, name)):
File '/usr/lib64/python2.7/posixpath.py', line 80 in join
  path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 15: ordinal not in range(128)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants