MestreLion / git-tools

Assorted git tools, including git-restore-mtime
GNU General Public License v3.0
295 stars 74 forks source link

decode("string-escape") fails with python 3 #34

Closed gebailey closed 5 years ago

gebailey commented 5 years ago

Reported via Red Hat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1748462

Reproduction (on Fedora 30 using Python 3.7.4):

[gbailey@localhost zxcv]$ git init
Initialized empty Git repository in /home/gbailey/zxcv/.git/
[gbailey@localhost zxcv]$ touch file1 "file2 with space" "\"file3"
[gbailey@localhost zxcv]$ git add .
[gbailey@localhost zxcv]$ git commit -m test
[master (root-commit) 9f05ab3] test
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 "\"file3"
 create mode 100644 file1
 create mode 100644 file2 with space
[gbailey@localhost zxcv]$ git-restore-mtime 
2 files to be processed in work dir
Traceback (most recent call last):
  File "/usr/bin/git-restore-mtime", line 332, in <module>
    parselog(args.merge, args.pathspec)
  File "/usr/bin/git-restore-mtime", line 287, in parselog
    file = file[1:-1].decode("string-escape")
AttributeError: 'str' object has no attribute 'decode'
vspinu commented 5 years ago

Same here on Ubuntu 18.04.3

9,188 files to be processed in work dir
Traceback (most recent call last):
  File "/usr/lib/git-core/git-restore-mtime", line 325, in <module>
    parselog(args.merge, args.pathspec)
  File "/usr/lib/git-core/git-restore-mtime", line 280, in parselog
    file = file[1:-1].decode("string-escape")

Interestingly, it works on some repos but fails in others (more complex ones).

Any workaround?

kilobyte commented 5 years ago

An example repository that always fails: https://github.com/pmem/pmdk — yet creating a new repo with all non-ASCII filenames from that one (unicodetest✭✮ and unicodetest✭✮.match) is not enough to reproduce the failure.

ssb22 commented 5 years ago

My workaround is to use Python 2, but its days are numbered. The script needs to be changed so that str is a byte-string rather than a Unicode string.

MestreLion commented 5 years ago

I'll soon, in the next few weeks, do a major rewrite on Python 2 / 3 compatibility, perhaps even dropping Python 2 support as it is about to be deprecated.

kilobyte commented 5 years ago

Confirmed — this works on the repo I mentioned. Thanks!