Skip to content

Commit 5045759

Browse files
ttaylorrvdye
authored andcommitted
builtin/pack-objects.c: ensure included --stdin-packs exist
A subsequent patch will teach `want_object_in_pack()` to set its `*found_pack` and `*found_offset` poitners to NULL when the provided pack does not pass the `is_pack_valid()` check. The `--stdin-packs` mode of `pack-objects` is not quite prepared to handle this. To prepare it for this change, do the following two things: - Ensure provided packs pass the `is_pack_valid()` check when collecting the caller-provided packs into the "included" and "excluded" lists. - Gracefully handle any _invalid_ packs being passed to `want_object_in_pack()`. Calling `is_pack_valid()` early on makes it substantially less likely that we will have to deal with a pack going away, since we'll have an open file descriptor on its contents much earlier. But even packs with open descriptors can become invalid in the future if we (a) hit our open descriptor limit, forcing us to close some open packs, and (b) one of those just-closed packs has gone away in the meantime. `add_object_entry_from_pack()` depends on having a non-NULL `*found_pack`, since it passes that pointer to `packed_object_info()`, meaning that we would SEGV if the pointer became NULL (like we propose to do in `want_object_in_pack()` in the following patch). But avoiding calling `packed_object_info()` entirely is OK, too, since its only purpose is to identify which objects in the included packs are commits, so that they can form the tips of the advisory traversal used to discover the object namehashes. Failing to do this means that at worst we will produce lower-quality deltas, but it does not prevent us from generating the pack as long as we can find a copy of each object from the disappearing pack in some other part of the repository. Co-authored-by: Victoria Dye <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 58a6abb commit 5045759

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

builtin/pack-objects.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,10 +3193,8 @@ static int add_object_entry_from_pack(const struct object_id *oid,
31933193
uint32_t pos,
31943194
void *_data)
31953195
{
3196-
struct rev_info *revs = _data;
3197-
struct object_info oi = OBJECT_INFO_INIT;
31983196
off_t ofs;
3199-
enum object_type type;
3197+
enum object_type type = OBJ_NONE;
32003198

32013199
display_progress(progress_state, ++nr_seen);
32023200

@@ -3207,19 +3205,24 @@ static int add_object_entry_from_pack(const struct object_id *oid,
32073205
if (!want_object_in_pack(oid, 0, &p, &ofs))
32083206
return 0;
32093207

3210-
oi.typep = &type;
3211-
if (packed_object_info(the_repository, p, ofs, &oi) < 0)
3212-
die(_("could not get type of object %s in pack %s"),
3213-
oid_to_hex(oid), p->pack_name);
3214-
else if (type == OBJ_COMMIT) {
3215-
/*
3216-
* commits in included packs are used as starting points for the
3217-
* subsequent revision walk
3218-
*/
3219-
add_pending_oid(revs, NULL, oid, 0);
3220-
}
3208+
if (p) {
3209+
struct rev_info *revs = _data;
3210+
struct object_info oi = OBJECT_INFO_INIT;
32213211

3222-
stdin_packs_found_nr++;
3212+
oi.typep = &type;
3213+
if (packed_object_info(the_repository, p, ofs, &oi) < 0) {
3214+
die(_("could not get type of object %s in pack %s"),
3215+
oid_to_hex(oid), p->pack_name);
3216+
} else if (type == OBJ_COMMIT) {
3217+
/*
3218+
* commits in included packs are used as starting points for the
3219+
* subsequent revision walk
3220+
*/
3221+
add_pending_oid(revs, NULL, oid, 0);
3222+
}
3223+
3224+
stdin_packs_found_nr++;
3225+
}
32233226

32243227
create_object_entry(oid, type, 0, 0, 0, p, ofs);
32253228

@@ -3338,6 +3341,8 @@ static void read_packs_list_from_stdin(void)
33383341
struct packed_git *p = item->util;
33393342
if (!p)
33403343
die(_("could not find pack '%s'"), item->string);
3344+
if (!is_pack_valid(p))
3345+
die(_("packfile %s cannot be accessed"), p->pack_name);
33413346
}
33423347

33433348
/*

0 commit comments

Comments
 (0)