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

Running content filter fails, maybe because of an empty commit #328

Closed hetas closed 6 months ago

hetas commented 6 months ago

Running the content filter with --filter-contents fails for me with this error message

Traceback (most recent call last):
  File "/mnt/c/work/hg-fast-export/fast-export/hg-fast-export.py", line 694, in <module>
    sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile,
  File "/mnt/c/work/hg-fast-export/fast-export/hg-fast-export.py", line 547, in hg2git
    c=export_commit(ui,repo,rev,old_marks,max,c,authors,branchesmap,
  File "/mnt/c/work/hg-fast-export/fast-export/hg-fast-export.py", line 324, in export_commit
    filter(file_data)
  File "/mnt/c/work/hg-fast-export/fast-export/pluginloader/../plugins/shell_filter_file_contents/__init__.py", line 18, in file_data_filter
    filter_cmd = self.filter_contents + [filename, node.hex(file_ctx.filenode()), '1' if file_ctx.isbinary() else '0']
AttributeError: 'NoneType' object has no attribute 'filenode'

I was running hg-fast-export on Windows Subsystem for Linux.

Judging by the state of the conversion at the point of failure it seems that a branch opening commit without files is causing this.

I was able to get passed the error with this patch

diff --git a/plugins/shell_filter_file_contents/__init__.py b/plugins/shell_filter_file_contents/__init__.py
index 84fd938..4030da0 100644
--- a/plugins/shell_filter_file_contents/__init__.py
+++ b/plugins/shell_filter_file_contents/__init__.py
@@ -15,6 +15,8 @@ class Filter:
         d = file_data['data']
         file_ctx = file_data['file_ctx']
         filename = file_data['filename']
+        if file_ctx == None:
+            return
         filter_cmd = self.filter_contents + [filename, node.hex(file_ctx.filenode()), '1' if file_ctx.isbinary() else '0']
         try:
             filter_proc = subprocess.Popen(filter_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

I can create a pull request for this patch, but I'm not sure if this is the right place for this fix. It seems that in hg-fast-export.py::export_file_contents files for the commits are iterated. And if there is no files I don't know how the shell_filter_file_contents-plugin get's invoked in the first place. And I don't really have time to investige further at this point.

frej commented 6 months ago

And if there is no files I don't know how the shell_filter_file_contents-plugin get's invoked in the first place.

It was introduced by #318 and is even documented in the readme :), #328 should fix it.

frej commented 6 months ago

Closed by #328.