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

Don't add file if plugin sets content to `None` #321

Closed sth closed 6 months ago

sth commented 6 months ago

I was looking for a way to filter the files that get included in the new repository. Currently a plugin can modify the content, but not completely remove it.

A straight forward way for a plugin to show it doesn't want the file is to set file_data['data'] to None. In the main script this can also easily be handled: Only output the file if its data is not None.

The change is quite minimal and shouldn't interfere with any existing code.

frej commented 6 months ago

I like the idea, but I would like to see a test case where a file is removed using the plugin. The test case should also check that nothing bad happens when a plugin-deleted file is removed in a later mercurial commit.

sth commented 6 months ago

Added a test that adds, modifies and removes a file in the hg repository and uses a plugin to remove that file when converting to git. The resulting git repository then doesn't contain any references to the "bad" files.

There are some empty commits in the resulting repository, because all the changes done in those commits were to "bad" files. This has no negative consequences despite maybe looking a bit odd at first sight. But it makes sense since all the changes in those commits were to files that got removed.

frej commented 6 months ago

Please squash the fix into the commit for the test case. Unless you protest, I can do that when I get time to start merging later today.

sth commented 6 months ago

I squashed it.

frej commented 6 months ago

Thank you for your contribution @sth.