Skip to content

[gix-object] Support empty tags with or without trailing NL #1903

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

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

pierrechevalier83
Copy link
Contributor

@pierrechevalier83 pierrechevalier83 commented Mar 21, 2025

When representing an annotated tag with an empty commit message, we used to only support a tag ending with two newlines (one after the tagger line + one after the empty commit message).

This was due to a misconception that annotated tags ending with a single NL shouldn't exist in the wild since there isn't an obvious way to create them with git.
This misconception shows up in the discussion thread for issue 603

It turns out that both encodings of empty annotated tags appear in the wild.

We must be able to parse either and roundtrip for either.

Before PR 604, we used to special case the empty tag msg case and not add a NL. To be able to represent b"", b"\n", b"\n\n"..., we special case any message that is a pure sequence of b'\n' and actually parse the b'\n' into the tag's message.

This allows us to calculate the correct size that matches the number of bytes that git would produce, as well as round-trip to and from the commit encoding.

The existing tests (in particular round_trip for empty.txt and empty_missing_nl.txt) convince me that the logic is sound. Also, the size being 139 bytes for empty_missing_nl.txt and 140 bytes for empty.txt matches the output of cat file | wc -l for each file.

@Byron Byron force-pushed the tag_end_of_line branch from 2435710 to 5218202 Compare March 22, 2025 03:17
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, that's great!
I definitely had problems getting the parsing right and by now tests are all we have :D.

Regarding the commit I force-pushed, it's only changing the subject, even though it looks like I am the author now.
This is due to the author being strangely formatted:

❯ gix cat @
tree 12ca5ffc6ce6ad1682ecafdd31bb2e223f5ad0b3
parent 6d5f77413e63cad45415d0f674c58d41091bffa1
author Pierre Chevalier pierrec@meta.com <> 1742556630 +0000
committer Sebastian Thiel <sebastian.thiel@icloud.com> 1742613444 +0800
gpgsig -----BEGIN PGP SIGNATURE-----

This already was the case in the original.

❯ gix cat 2435710b4
tree 12ca5ffc6ce6ad1682ecafdd31bb2e223f5ad0b3
parent 6d5f77413e63cad45415d0f674c58d41091bffa1
author Pierre Chevalier redacted@meta.com <> 1742556630 +0000
committer Pierre Chevalier <pierrechevalier-redacted> 1742565757 +0000

Thus I'd leave it to you to change the subject and force-push again so the authorship comes out correctly. And maybe there is a way to fix the author line while at it :).

When representing an annotated tag with an empty commit message, we used
to only support a tag ending with two newlines (one after the tagger
line + one after the empty commit message).

This was due to a misconception that annotated tags ending with a single
NL shouldn't exist in the wild since there isn't an obvious way to
create them from with `git`.
This misconception shows up in the discussion thread for
[issue 603](GitoxideLabs#603)

It turns out that both encodings of empty annotated tags appear in the
wild.

We must be able to parse either and roundtrip for either.

Before [PR 604](GitoxideLabs#604), we
used to special case the empty tag msg case and not add a NL.
To be able to represent `b""`, `b"\n"`, `b"\n\n"`..., we special case
any `message` that is a pure sequence of `b'\n'` and actually parse the
`b'\n'` into the tag's message.

This allows us to calculate the correct size that matches the number of
bytes that git would produce, as well as round-trip to and from the
commit encoding.

The existing tests (in particular `round_trip` for `empty.txt` and
`empty_missing_nl.txt`) convince me that the logic is sound.
Also, the size being `139` bytes for `empty_missing_nl.txt` and `140`
bytes for `empty.txt` matches the output of `cat file | wc -l` for each
file.
@pierrechevalier83
Copy link
Contributor Author

Thus I'd leave it to you to change the subject and force-push again so the authorship comes out correctly. And maybe there is a way to fix the author line while at it :).

Thanks for the fast review. I've fixed the author/committer fields and rebased the change.

@pierrechevalier83 pierrechevalier83 requested a review from Byron March 22, 2025 06:57
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thanks! Thanks for the fast turnaround, too!

@Byron Byron merged commit 6caee49 into GitoxideLabs:main Mar 22, 2025
21 checks passed
facebook-github-bot pushed a commit to facebook/dotslash that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebookincubator/below that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebookexperimental/reverie that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebookincubator/reindeer that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebookexperimental/hermit that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request May 16, 2025
Summary:
ignore-conflict-markers

Upgrade gitoxide crates to latest release to propagate some upstream fixes:
* [[gix-object] Support empty tags with or without trailing NL](GitoxideLabs/gitoxide#1903)
* [[fix] Make Tree roundtrip by storing additional bit of information](GitoxideLabs/gitoxide#1917)
* [fix: Make email with spaces round-trip](GitoxideLabs/gitoxide#1922)
* [Make author and committer date roundtrip](GitoxideLabs/gitoxide#1935)

Reviewed By: quark-zju

Differential Revision: D74337531

fbshipit-source-id: 5361c7d4b0b52c683e05af8d19ac2169aebc8197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants