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

Fix rev index #599

Merged
merged 2 commits into from
Aug 25, 2023
Merged

Fix rev index #599

merged 2 commits into from
Aug 25, 2023

Conversation

jeffhostetler
Copy link

git index-pack fails when the -o argument is used and the requested IDX file does not have the standard .idx suffix. The reverse index code assumes the .idx suffix when it generates the .rev pathname.

Silently disable the reverse index when the suffix is different.

Added a test to confirm the breakage and then updated it to confirm the fix.

This is being patched into vfs-2.41.0.5 directly, but the fixes should be backported to upstream Git and to vfs-2.42.0.

Add test case to demonstrate that `git index-pack -o <idx-path> pack-path`
fails if <idx-path> does not end in ".idx" when `--rev-index` is
enabled.

In e37d0b8 (builtin/index-pack.c: write reverse indexes, 2021-01-25)
we learned to create `.rev` reverse indexes in addition to `.idx` index
files.  The `.rev` file pathname is constructed by replacing the suffix
on the `.idx` file.  The code assumes a hard-coded "idx" suffix.

In a8dd7e0 (config: enable `pack.writeReverseIndex` by default, 2023-04-12)
reverse indexes were enabled by default.

If the `-o <idx-path>` argument is used, the index file may have a
different suffix.  This causes an error when it tries to create the
reverse index pathname.

The test here demonstrates the failure.  (The test forces `--rev-index`
to avoid interaction with `GIT_TEST_NO_WRITE_REV_INDEX` during CI runs.)

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Teach index-pack to silently omit the reverse index if the
index file does not have the standard ".idx" suffix.

In e37d0b8 (builtin/index-pack.c: write reverse indexes, 2021-01-25)
we learned to create `.rev` reverse indexes in addition to `.idx` index
files.  The `.rev` file pathname is constructed by replacing the suffix
on the `.idx` file.  The code assumes a hard-coded "idx" suffix.

In a8dd7e0 (config: enable `pack.writeReverseIndex` by default, 2023-04-12)
reverse indexes were enabled by default.

If the `-o <idx-path>` argument is used, the index file may have a
different suffix.  This causes an error when it tries to create the
reverse index pathname.

Since we do not know why the user requested a non-standard suffix for
the index, we cannot guess what the proper corresponding suffix should
be for the reverse index.  So we disable it.

The t5300 test has been updated to verify that we no longer error
out and that the .rev file is not created.

TODO We could warn the user that we skipped it (perhaps only if they
TODO explicitly requested `--rev-index` on the command line).
TODO
TODO Ideally, we should add an `--rev-index-path=<path>` argument
TODO or change `--rev-index` to take a pathname.
TODO
TODO I'll leave these questions for a future series.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Copy link
Collaborator

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

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

This will definitely unblock the release. I have doubts that upstream would settle for this disabling, though it does bring the behavior back in line with pre-2.41.0 behavior. It's strange that the index name would disable the rev-index feature.

I was expecting that the behavior would instead strip the suffix from the -o option (if possible, and append to the filename otherwise).

For the current strategy, I only have a comment that the --no-rev-index behavior could be documented as working with a non-.idx filename.


# Non .idx suffix
cat test-1-${packname_1}.pack >test-complain-1.pack &&
test_must_fail git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack 2>err &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to demonstrate the command succeeds when given .idx-suffix to -o and --no-rev-index, isolating the issue to the rev-index option?

@jeffhostetler jeffhostetler merged commit 304f0a3 into vfs-2.41.0.5 Aug 25, 2023
86 checks passed
@jeffhostetler jeffhostetler deleted the fix-rev-index branch August 25, 2023 17:51
@dscho
Copy link
Member

dscho commented Aug 25, 2023

An alternative to disabling the revindex in the case of a file name that does not end in .idx would be to:

  • Modify the condition in derive_filename() to allow not only the .idx file extension but any extension that ends in .<only-alphabetical-letters>idx, such as .tempidx (which would then derive the file extension .temprev).
  • Change the die() in derive_filename() to a warning(...); return NULL; and teach the callers to handle NULL (the .rev caller by turning off revindex, as this PR does). Or even better: add an int gentle function parameter that decides whether to die() or to warn.

I imagine that that variant could potentially be welcomed on the Git mailing list.

@jeffhostetler
Copy link
Author

I've created an issue to track and upstream this.

dscho pushed a commit that referenced this pull request Aug 28, 2023
`git index-pack` fails when the `-o` argument is used and the requested
IDX file does not have the standard `.idx` suffix. The reverse index
code assumes the `.idx` suffix when it generates the `.rev` pathname.

Silently disable the reverse index when the suffix is different.

Added a test to confirm the breakage and then updated it to confirm the
fix.

This is being patched into vfs-2.41.0.5 directly, but the fixes should
be backported to upstream Git and to vfs-2.42.0.
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.

3 participants