frej / fast-export

A mercurial to git converter using git-fast-import
http://repo.or.cz/w/fast-export.git
808 stars 255 forks source link

Type error when calling fast-export #233

Closed juan88 closed 4 years ago

juan88 commented 4 years ago

I'm having this error when trying to migrate an HG repository. I don't know how to provide more info apart from the traceback. Please let me know how can I help.

Thanks!

Traceback (most recent call last):
  File "/code/fast-export/hg-fast-export.py", line 719, in <module>
    plugins=plugins_dict))
  File "/code/fast-export/hg-fast-export.py", line 535, in hg2git
    if not verify_heads(ui,repo,heads_cache,force,branchesmap):
  File "/code/fast-export/hg-fast-export.py", line 494, in verify_heads
    b'\n%s (repo) != %s (cache)\n' % (b, b'<None>' if sha1 is None else sha1, c)
TypeError: %b requires bytes, or an object that implements __bytes__, not 'NoneType'
chrisjbillington commented 4 years ago

Could you perhaps add this printline and post what it prints so we can see which of the objects being printed is unexpectedly None?

@@ -488,6 +488,7 @@ def verify_heads(ui,repo,cache,force,branchesmap):
     sanitized_name=sanitize_name(b,"branch",branchesmap)
     sha1=get_git_sha1(sanitized_name)
     c=cache.get(sanitized_name)
+    print(b, sha1, c, file=sys.stderr)
     if sha1!=c:
       stderr_buffer.write(
         b'Error: Branch [%s] modified outside hg-fast-export:'

Since the bug you reported against hg-export-tool was Python 3.5-specific, with the json module handling bytestrings differently, I'm expecting that it's likely this one might be due to something similar (though not the json module since it is not used here).

juan88 commented 4 years ago

Hello and thanks for the quick reply.

Here's the output of the print you've asked on one of the repos I've tried to migrate. And yes, I'm using python 3.5.

b'master' b'44c50d0fae5697ab9cdb05d0e484b97edda31042' None

frej commented 4 years ago

231 adds an encode('utf8') inside get_git_sha1, I wonder if this is an attempt to work around this bug (I have asked the author)?

chrisjbillington commented 4 years ago

Sorry for disappearing on this!

@frej I think there's something to what you're saying, though the one thing that confuses me is that I would have expected a UnicodeEncodeError from passing a string with non-ascii characters to check_call on a system with ascii as the default encoding. But if get_git_sha1 is returning None, that seems to imply it's a subprocess.CalledProcessError or that the command returns no output.

I am unable to reproduce the problem to find out, as I can't seem to coax Python 3.8 or 3.5 on my system into having ascii as the default encoding - though I know this is the case on some systems.

But I think the change in #231 represents a fix to a real problem, even if I don't quite understand why the problem causes the results it does.

@juan88 does adding the .encode('utf8') as per the change @frej linked to fix your problem?

juan88 commented 4 years ago

This seems to solve the issue. At least I do not see that error anymore. I could run the program under a docker image (mentioned in another issue I think). So there's probably something related to the encoding as you mentioned, or something happening under Python 3.5 (as some of my other issues). :+1: