Equivalent of .gitattributes export-ignore for Mercurial?

Manuel Jacob me at manueljacob.de
Wed Jan 31 16:50:25 UTC 2024


On 31/01/2024 11.22, PIERRE AUGIER wrote:
> Hi,
> 
> For Git repositories, [Meson](https://mesonbuild.com/) is sensible to .gitattributes export-ignore to choose which files are included in a dist archive. In the background it uses `git archive`. This is convenient because .gitattributes is versioned.
> 
> I'd like to find if something similar can be done for Mercurial repositories.
> 
> I guess Meson uses `hg archive`.

You’re right. Out of interest, I looked it up: 
https://github.com/mesonbuild/meson/blob/55d30b61ffadb014abb0c814c039ebebfc7df347/mesonbuild/mdist.py#L240

> I didn't find in the doc how to configure `hg archive` and if it is possible to configure it from a versioned file in the repository.
> 
> Is it already possible? If no, would it be possible to do that with a future Mercurial version?

In the Mercurial code, I didn’t find any such functionality.

I see that it would be useful to have a versioned file to be able to 
exclude specific files from the dist file. However, I think that such a 
functionality would better be part of Meson than Mercurial.

Mercurial‘s archive command is to “create an unversioned archive of a 
repository revision” (according to the help text). If some files would 
be excluded from that archive when running the archive command, the 
command would not work as described. I think that the purpose of the 
archive command is incompatible with not including specific files, 
unless the user (asking for the archive to be created) asks for it. It’s 
still possible to explicitly exclude files from the archive by using the 
--exclude options if the user wants an archive of part of the repository.

It makes sense to always exclude specific files from a dist file. But 
dist files is a concept of Meson, not of Mercurial. So I think you 
should ask the Meson developers to include such functionality. I could 
imagine that they might be reluctant to add such functionality because 
with Git, it’s possible to have that functionality without support in 
Meson. But I think that the fact that Meson uses `git archive` and `hg 
archive` should be considered purely as an implementation detail, so 
it’s a coincidence that .gitattributes can be used to exclude files from 
a dist file.


More information about the Mercurial mailing list