Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap GIT_DIFF_LINE_(ADD|DEL)_EOFNL to match other Diffs #6240

Merged
merged 1 commit into from Feb 20, 2024

Conversation

xphoniex
Copy link
Contributor

Generating a diff using git_diff_tree_to_tree and git_diff_from_buffer return different result for the same patch of:

$ git diff 17ec0f3 394a717
diff --git a/.env b/.env
index f9fb22f..ed7b51e 100644
--- a/.env
+++ b/.env
@@ -1 +1 @@
-hello=12345
+hello=123456
\ No newline at end of file

Diff:

from repo:::
- hello=12345
+ hello=123456<                // Notice missing \n and `<` origin, meaning deletion
\ No newline at end of file
.
from buff:::
- hello=12345
+ hello=123456
> \ No newline at end of file

We didn't add the LF, we deleted it!

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
@xphoniex
Copy link
Contributor Author

xphoniex commented Apr 7, 2022

I'm looking at failed CIs and can't really tell if there's something wrong with the code when it showing leaked memory or something wrong with bitbucket that's causing this. Can you please take a look @ethomson ?

Test code is pretty straighforward, and the only thing I'm not freeing is git_diff_line *line; which I couldn't find a _free function for e.g. git_diff_line_free.

@xphoniex
Copy link
Contributor Author

Polite reminder @ethomson .

@ethomson
Copy link
Member

Sorry for the long delay here — every time I came back to this PR, I was puzzled by the behavior. My misunderstanding was in the names of the constants — the line we're adding has a NL problem, this shouldn't that be GIT_DIFF_LINE_ADD_EOFNL?

In fact, no:

include/git2/diff.h:	GIT_DIFF_LINE_ADD_EOFNL = '>',     /**< Old has no LF at end, new does */
include/git2/diff.h:	GIT_DIFF_LINE_DEL_EOFNL = '<',     /**< Old has LF at end, new does not */

So GIT_DIFF_LINE_ADD_EOFNL means that the postimage (the delete) has the NL problem. 🥴

Thanks again for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants