Skip to content

Apply some v2.48 regression bugfixes #5376

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 39 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
49edce4
show-index: the short help should say the command reads from its input
gitster Dec 20, 2024
0ad3d65
object-file: fix race in object collision check
pks-t Dec 30, 2024
c1acf1a
object-file: rename variables in `check_collision()`
pks-t Jan 6, 2025
cfae50e
object-file: don't special-case missing source file in collision check
pks-t Jan 6, 2025
d7fcbe2
object-file: retry linking file into place when occluding file vanishes
pks-t Jan 6, 2025
8d24d56
test-lib: invert return value of check_test_results_san_file_empty
peff Jan 7, 2025
b9a9df9
test-lib: simplify lsan results check
peff Jan 7, 2025
164a251
test-lib: add a few comments to LSan log checking
peff Jan 7, 2025
0b43274
credential-cache: respect authtype capability
hickford Jan 9, 2025
447cdec
fetch set_head: fix non-mirror remotes in bare repositories
ferdinandyb Jan 12, 2025
71e19a0
object-name: fix resolution of object names containing curly braces
newren Jan 13, 2025
191f0c8
object-name: be more strict in parsing describe-like output
newren Jan 13, 2025
bc67b4a
reftable: write correct max_update_index to header
KarthikNayak Jan 15, 2025
5e58db6
ref-filter: move ahead-behind bases into used_atom
rscharfe Jan 18, 2025
7ee4fd1
ref-filter: move is-base tip to used_atom
rscharfe Jan 18, 2025
c5490ce
ref-filter: remove ref_format_clear()
rscharfe Jan 18, 2025
9c83589
Merge branch 'jk/lsan-race-ignore-false-positive'
gitster Jan 21, 2025
aec5e0e
Merge branch 'ps/object-collision-check'
gitster Jan 17, 2025
75bc40d
bswap.h: squelch potential sparse -Wcast-truncate warnings
gitster Jan 19, 2025
b3c9b61
packfile: factor out --pack_header argument parsing
peff Jan 19, 2025
56c5e82
parse_pack_header_option(): avoid unaligned memory writes
peff Jan 19, 2025
7215d58
index-pack, unpack-objects: use get_be32() for reading pack header
peff Jan 19, 2025
f2d9cf9
index-pack, unpack-objects: use skip_prefix to avoid magic number
peff Jan 19, 2025
7c73034
Merge branch 'jk/pack-header-parse-alignment-fix'
gitster Jan 21, 2025
369aa54
Merge branch 'en/object-name-with-funny-refname-fix'
gitster Jan 17, 2025
a5dd349
Merge branch 'kn/reflog-migration-fix'
gitster Jan 17, 2025
6638779
refs: mark `ref_transaction_update_reflog()` as static
KarthikNayak Jan 21, 2025
a89e12d
refs: use 'uint64_t' for 'ref_update.index'
KarthikNayak Jan 21, 2025
148560f
reftable: prevent 'update_index' changes after adding records
KarthikNayak Jan 21, 2025
fff597d
Merge branch 'kn/reflog-migration-fix-followup'
gitster Jan 21, 2025
120b274
Merge branch 'rs/ref-filter-used-atoms-value-fix'
gitster Jan 21, 2025
1804320
Merge branch 'bf/fetch-set-head-fix' into jch
gitster Jan 21, 2025
b37dd62
Merge branch 'jc/show-index-h-update'
gitster Jan 21, 2025
9b7de7e
Merge branch 'mh/credential-cache-authtype-request-fix'
gitster Jan 21, 2025
1edca76
trace2: prevent segfault on config collection where no value specified
ad-murray Jan 10, 2025
b7a9905
grep: prevent `^$` false match at end of file
peff Jan 13, 2025
86d0c30
update-ref: do set reflog's `old_oid`
peff Jan 21, 2025
14ed4ad
Merge branch 'fixes-from-the-git-mailing-list'
dscho Jan 22, 2025
290ad15
fixup! reftable: write correct max_update_index to header
KarthikNayak Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
object-file: retry linking file into place when occluding file vanishes
Prior to 0ad3d65 (object-file: fix race in object collision check,
2024-12-30), callers could expect that a successful return from
`finalize_object_file()` means that either the file was moved into
place, or the identical bytes were already present. If neither of those
happens, we'd return an error.

Since that commit, if the destination file disappears between our
link(3p) call and the collision check, we'd return success without
actually checking the contents, and without retrying the link. This
solves the common case that the files were indeed the same, but it means
that we may corrupt the repository if they weren't (this implies a hash
collision, but the whole point of this function is protecting against
hash collisions).

We can't be pessimistic and assume they're different; that hurts the
common case that the mentioned commit was trying to fix. But after
seeing that the destination file went away, we can retry linking again.
Adapt the code to do so when we see that the destination file has racily
vanished. This should generally succeed as we have just observed that
the destination file does not exist anymore, except in the very unlikely
event that it gets recreated by another concurrent process again.

Helped-by: Jeff King <[email protected]>
Signed-off-by: Patrick Steinhardt <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pks-t authored and gitster committed Jan 6, 2025
commit d7fcbe2c56468ac780c689b02c6a9e056ce39c12
25 changes: 21 additions & 4 deletions object-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,8 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
}

#define CHECK_COLLISION_DEST_VANISHED -2

static int check_collision(const char *source, const char *dest)
{
char buf_source[4096], buf_dest[4096];
Expand All @@ -1990,6 +1992,8 @@ static int check_collision(const char *source, const char *dest)
if (fd_dest < 0) {
if (errno != ENOENT)
ret = error_errno(_("unable to open %s"), dest);
else
ret = CHECK_COLLISION_DEST_VANISHED;
goto out;
}

Expand Down Expand Up @@ -2037,8 +2041,11 @@ int finalize_object_file(const char *tmpfile, const char *filename)
int finalize_object_file_flags(const char *tmpfile, const char *filename,
enum finalize_object_file_flags flags)
{
struct stat st;
int ret = 0;
unsigned retries = 0;
int ret;

retry:
ret = 0;

if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
goto try_rename;
Expand All @@ -2059,6 +2066,8 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
* left to unlink.
*/
if (ret && ret != EEXIST) {
struct stat st;

try_rename:
if (!stat(filename, &st))
ret = EEXIST;
Expand All @@ -2074,9 +2083,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
errno = saved_errno;
return error_errno(_("unable to write file %s"), filename);
}
if (!(flags & FOF_SKIP_COLLISION_CHECK) &&
check_collision(tmpfile, filename))
if (!(flags & FOF_SKIP_COLLISION_CHECK)) {
ret = check_collision(tmpfile, filename);
if (ret == CHECK_COLLISION_DEST_VANISHED) {
if (retries++ > 5)
return error(_("unable to write repeatedly vanishing file %s"),
filename);
goto retry;
}
else if (ret)
return -1;
}
unlink_or_warn(tmpfile);
}

Expand Down