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

Stack trace upon converting a (small) hg repo #255

Closed jaques-sam closed 3 years ago

jaques-sam commented 3 years ago

Stack trace

❯ ../../upstream/fast-export/hg-fast-export.sh -r ../cppsamples
Traceback (most recent call last):
  File "/home/samja/repos/upstream/fast-export/hg-fast-export.py", line 730, in <module>
    plugins=plugins_dict))
  File "/home/samja/repos/upstream/fast-export/hg-fast-export.py", line 542, in hg2git
    if not verify_heads(ui,repo,heads_cache,force,ignore_unnamed_heads,branchesmap):
  File "/home/samja/repos/upstream/fast-export/hg-fast-export.py", line 499, 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'
git-fast-import statistics:
---------------------------------------------------------------------
Alloc'd objects:       5000
Total objects:            0 (         0 duplicates                  )
      blobs  :            0 (         0 duplicates          0 deltas of          0 attempts)
      trees  :            0 (         0 duplicates          0 deltas of          0 attempts)
      commits:            0 (         0 duplicates          0 deltas of          0 attempts)
      tags   :            0 (         0 duplicates          0 deltas of          0 attempts)
Total branches:           0 (         0 loads     )
      marks:           1024 (         0 unique    )
      atoms:              0
Memory total:          2282 KiB
       pools:          2048 KiB
     objects:           234 KiB
---------------------------------------------------------------------
pack_report: getpagesize()            =       4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit      = 8589934592
pack_report: pack_used_ctr            =          0
pack_report: pack_mmap_calls          =          0
pack_report: pack_open_windows        =          0 /          0
pack_report: pack_mapped              =          0 /          0
---------------------------------------------------------------------

Versions

❯ python --version
Python 3.5.3

❯ hg --version
Mercurial Distributed SCM (version 4.0)

❯ pip3 show mercurial
Name: mercurial
Version: 5.7

❯ git --version
git version 2.11.0

❯ git -C ../../upstream/fast-export/ log -n1 | cat                                                                                                ─╯
commit 427663c766b05ece3a2fbec5642074446b06d4af
Merge: 588e03b 056756f
Author: Frej Drejhammar <frej.drejhammar@gmail.com>
Date:   Sun Jan 10 15:18:28 2021 +0100

    Merge branch 'PR/254'
frej commented 3 years ago

The code that crashes is only allocated when a converted branch has been modified by something other than fast-export (or it looks that way to fast-export). Try to run the conversion from start in a clean directory and be sure to check if completes successfully. If you happen to have two branches which the name sanitizer maps to the same name, this could also trigger this error. The name sanitizer will print out a warning when it modifies a branch name, so check if that could explain it.

To help debug the error in the error message, could you insert a line after the if sha1!=c: on line 496 so the if-statement says:

[edit, previous version was bogus]

if sha1!=c:
      stderr_buffer.write(
        b'Error: Branch [%s] modified outside hg-fast-export:'
        b'\n%s (repo) != %s (cache)\n' % (b'<None>' if b is None else b, b'<None>' if sha1 is None else sha1, b'<None>' if c is None else c)
      )
      if not force: return False

and report what it says when the error is triggered.

Apart from that, verify that the Mercurial your python picks up when running fast-export is 5.7 and not the older 4.0 which appears to occur first in you $PATH.

Trogluddite commented 3 years ago

I ran into this issue. It seems like it's working as expected because the issue does not repro in a 'clean' git repository, but the error message did seem misleading at first.

This will repro if you git init an empty repo, and then commit a change to the repo (e.g., add a README.md) -- fast-export worked as expected if started with an empty git repo.

In the repro case, I added the line suggested above and saw:

Error: Branch [master] modified outside hg-fast-export:
498011d0910220b0b36e55da13d458fe656da61e (repo) != <None> (cache)
/usr/local/Cellar/git/2.19.2/libexec/git-core/git-fast-import statistics:

My versions:

Python 3.7.7
git version 2.19.2
Mercurial Distributed SCM (version 5.3.2)
pip-version for mercurial: Version: 5.8
frej commented 3 years ago

No response from @jaques-sam in more than 3 months. The reproducer from @Trogluddite is a case of modifying the repo outside of hg-fast-export, so closing this.