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

Branch mapping not working with quotation mark #292

Closed ruku320 closed 1 year ago

ruku320 commented 1 year ago

I have a branch with the name Feature- 12V Vac "Venom". I have a branch map file to rename this branch with the following mapping: "Feature- 12V Vac \"Venom\""="Feature-_12V_Vac_Venom"

Branch mapping doesn't seem to recognize the escaped quotes correctly to rename the branch since I get the following error when I run the script to convert the repo:

Feature- 12V Vac "Venom": Exporting simple delta revision 3530/4034 with 0/5/0 added/changed/removed files Traceback (most recent call last): File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 728, in sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile, File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 581, in hg2git c=export_commit(ui,repo,rev,old_marks,max,c,authors,branchesmap, File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 372, in export_commit export_file_contents(ctx,man,changed,hgtags,fn_encoding,plugins) File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 238, in export_file_contents wr(d) File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 54, in wr wr_no_nl(msg) File "C:\git_convert\hg-export-tool-master\fast-export\hg-fast-export.py", line 51, in wr_no_nl stdout_buffer.write(msg) BrokenPipeError: [Errno 32] Broken pipe error!!!!

frej commented 1 year ago

Fast-export feeds git-fast-import through a pipe. When fast-import dies because of an error and closes its end of the pipe, fast-export crashes when it cannot write to the pipe. As fast export runs asynchronously from fast-import, the actual error that trips up fast-import is not necessarily related to what fast-export outputs to stderr right before the backtrace triggered by the broken pipe.

Git fast-import will have produced a crash log (check the CRASH REPORTS section in git-fast-import's man page) before it died, and that should give you a clue to what's wrong. My guess is that you have a dodgy author or branch name, but probably not the one you think. You didn't provide the full output from fast export, so also check the "Frequent Problems" section in the README, particularly the issue "My mapping file does not seem to work when I rename the branch git fast-import crashes on!" to eliminate that error source.

ruku320 commented 1 year ago

I am using the unmangled branch name in the map file.

This is what's in the crash log:

fast-import crash report: fast-import process: 27940 parent process : 1 at 2022-10-21 16:56:46 +0000

fatal: Branch name doesn't conform to GIT standards: refs/heads/Feature- 12V Vac "Venom"

frej commented 1 year ago

It looks like the hack in process_unicode_escape_sequences in hg-fast-export.py has stopped working and what ends in the internal mapping is b'Feature- 12V Vac \\"Venom\\"' and not the b'Feature- 12V Vac "Venom"' we want. @chrisjbillington you came up with this trick, are we so lucky you already have a solution that works on a modern Python?

Unfortunately I have very little time to spend on fast-export, so patches welcome.

chrisjbillington commented 1 year ago

The problem still seems to occur back on Python 2.7 and 3.6, so I'm not sure when it stopped working, or if it never worked as intended (I suspect the latter).

In any case, .encode('unicode-escape') is not doing what we want, it is adding extra escapes for backslashes, such that they round-trip .decode('unicode-escape').encode('unicode-escape'). But we want them to pass through the .encode() unchanged and be interpreted as the character they represent upon .decode().

PR here: https://github.com/frej/fast-export/pull/293

frej commented 1 year ago

@ruku320, please reopen if @chrisjbillington's patch doesn't resolve the problem. I'll hold off creating a new release for a couple of days until you can confirm that it works for you too (it works in my tests).

ruku320 commented 1 year ago

I can confirm that the patch fixes the problem. Thanks!