docs: Recommend to use '* merge=mergiraf' #384

Merged
wetneb merged 4 commits from wetneb/mergiraf:simplify_gitattributes into main 2025-05-23 17:46:50 +02:00
Owner

Fixes #57. Also closes #244.

I'm trying out this setup myself to see if I notice any issue with it. I think the fallback to line-based merge is quick enough that this doesn't add too much overhead for file types we don't support.

Fixes #57. Also closes #244. I'm trying out this setup myself to see if I notice any issue with it. I think the fallback to line-based merge is quick enough that this doesn't add too much overhead for file types we don't support.
Owner

By the way, maybe it would be possible to incorporate the line-based-fallback logic into Git itself? So we would return a special exit code if we know we can't handle the given language, and Git would in turn run git merge-file internally, which might be faster than us shelling out. I think this functionality would be helpful even outside Mergiraf (in fact I believe the issue would've already been implemented if custom merge drivers were more prevalent).

In fact, doesn't the error code thing basically exist already? Quoting "Defining a custom merge driver":

When the driver crashes (e.g. killed by SEGV), it is expected to exit with non-zero status that are higher than 128, and in such a case, the merge results in a failure (which is different from producing a conflict).

So Git could perform the fallback on exit code >128

By the way, maybe it would be possible to incorporate the line-based-fallback logic into Git itself? So we would return a special exit code if we know we can't handle the given language, and Git would in turn run `git merge-file` internally, which might be faster than us shelling out. I think this functionality would be helpful even outside Mergiraf (in fact I believe the issue would've already been implemented if custom merge drivers were more prevalent). In fact, doesn't the error code thing basically exist already? Quoting ["Defining a custom merge driver"](https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver): > When the driver crashes (e.g. killed by SEGV), it is expected to exit with non-zero status that are higher than 128, and in such a case, the merge results in a failure (which is different from producing a conflict). So Git could perform the fallback on exit code >128
Author
Owner

That sounds like a good idea! But at the moment (git v2.47.2), it seems that git simply aborts the entire operation if mergiraf returns code 129. If Git was to change this in a later version, then we'd need to know the Git version to know if we can allow ourselves to fail, or if we should handle the fallback on our side. So that would probably mean running git --version to find out?But at that rate we might as well run git merge-file directly, perhaps…

One question I have is whether we should rather use our own line-based merging (which doesn't require starting a new process) or git's own (which might better respect git's configuration, and is likely more optimized than the diffy implementation).

That sounds like a good idea! But at the moment (git v2.47.2), it seems that git simply aborts the entire operation if mergiraf returns code 129. If Git was to change this in a later version, then we'd need to know the Git version to know if we can allow ourselves to fail, or if we should handle the fallback on our side. So that would probably mean running `git --version` to find out?But at that rate we might as well run `git merge-file` directly, perhaps… One question I have is whether we should rather use our own line-based merging (which doesn't require starting a new process) or git's own (which might better respect git's configuration, and is likely more optimized than the diffy implementation).
wetneb force-pushed simplify_gitattributes from cb8d05b3a0 to 01c90a891d 2025-05-22 22:56:10 +02:00 Compare
wetneb changed title from WIP: docs: Recommend to use '* merge=mergiraf' to docs: Recommend to use '* merge=mergiraf' 2025-05-22 22:56:29 +02:00
Author
Owner

I've been trying this out on various codebases and didn't notice anything particular, beyond the warning that I disabled above, so this seems good to go as far as I am concerned.

I've been trying this out on various codebases and didn't notice anything particular, beyond the warning that I disabled above, so this seems good to go as far as I am concerned.
doc/src/usage.md Outdated
@ -49,15 +49,20 @@ $ git config --global core.attributesfile ~/.gitattributes
Then, you also need to specify for which sorts of files this merge driver should be used. Add the following lines to your global `~/.gitattributes` file:
Owner

this line probably needs to be updated as well

this line probably needs to be updated as well
Owner

One question I have is whether we should rather use our own line-based merging (which doesn't require starting a new process) or git's own (which might better respect git's configuration, and is likely more optimized than the diffy implementation).

I wanted to suggest gix as another option (gix-merge in particular), but it operates on a whole repo, so using it would be more complicated than just passing 3 strings. Digging into the source code a bit though, it seems to boil down to the same imara-diff-based merge we use: https://docs.rs/gix-merge/0.5.1/src/gix_merge/blob/builtin_driver/text/function.rs.html#28. So I guess that's another point for the first option.

Actually, I wonder whether we could just hook into these internals, and get rid of diffy-imara completely

> One question I have is whether we should rather use our own line-based merging (which doesn't require starting a new process) or git's own (which might better respect git's configuration, and is likely more optimized than the diffy implementation). I wanted to suggest gix as another option ([`gix-merge`](https://crates.io/crates/gix-merge) in particular), but it operates on a whole repo, so using it would be more complicated than just passing 3 strings. Digging into the source code a bit though, it seems to boil down to the same `imara-diff`-based merge we use: https://docs.rs/gix-merge/0.5.1/src/gix_merge/blob/builtin_driver/text/function.rs.html#28. So I guess that's another point for the first option. Actually, I wonder whether we could just hook into these internals, and get rid of diffy-imara completely
Fix doc refering to multiple lines in .gitattributes
All checks were successful
/ test (pull_request) Successful in 56s
d547f28de2
Author
Owner

Ah nice! Last time I looked I hadn't been able to find this sort of functionality there, I don't know if it's because it wasn't there yet or I didn't look closely enough.

Switching sounds good to me in principle, but looking at the dependencies of gix-merge, it seems that it's far from self-contained. It looks like diffy-imara remains more lightweight and quite fitting for us, no?

Ah nice! Last time I looked I hadn't been able to find this sort of functionality there, I don't know if it's because it wasn't there yet or I didn't look closely enough. Switching sounds good to me in principle, but looking at [the dependencies of `gix-merge`](https://crates.io/crates/gix-merge/0.5.1/dependencies), it seems that it's far from self-contained. It looks like `diffy-imara` remains more lightweight and quite fitting for us, no?
Owner

seems that it's far from self-contained

I guess the dependencies are there because of all the Git-related logic, but we kind of want that if we want to respect Git config and such, no?

Otherwise we could maybe persuade them to extract the pure string merging algorithm into a separate crate we could then take a dependency on. But this would be pretty much what we have already with diffy-imara, yeah (aside from the latter being much worse maintained by yours truly 😅)

> seems that it's far from self-contained I guess the dependencies are there because of all the Git-related logic, but we kind of want that if we want to respect Git config and such, no? Otherwise we could maybe persuade them to extract the pure string merging algorithm into a separate crate we could then take a dependency on. But this would be pretty much what we have already with diffy-imara, yeah (aside from the latter being much worse maintained by yours truly 😅)
Author
Owner

I guess the dependencies are there because of all the Git-related logic, but we kind of want that if we want to respect Git config and such, no?

Perhaps… I am not sure to what extent their implementation really does!

> I guess the dependencies are there because of all the Git-related logic, but we kind of want that if we want to respect Git config and such, no? Perhaps… I am not sure to what extent their implementation really does!
ada4a approved these changes 2025-05-23 15:29:24 +02:00
wetneb merged commit cb4df19278 into main 2025-05-23 17:46:50 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#384
No description provided.