Skip to content

Commit b017334

Browse files
ttaylorrgitster
authored andcommitted
builtin/pack-objects.c: remove duplicate hash lookup
In the original code from 08cdfb1 (pack-objects --keep-unreachable, 2007-09-16), we add each object to the packing list with type `obj->type`, where `obj` comes from `lookup_unknown_object()`. Unless we had already looked up and parsed the object, this will be `OBJ_NONE`. That's fine, since oe_set_type() sets the type_valid bit to '0', and we determine the real type later on. So the only thing we need from the object lookup is access to the `flags` field so that we can mark that we've added the object with `OBJECT_ADDED` to avoid adding it again (we can just pass `OBJ_NONE` directly instead of grabbing it from the object). But add_object_entry() already rejects duplicates! This has been the behavior since 7a979d9 (Thin pack - create packfile with missing delta base., 2006-02-19), but 08cdfb1 didn't take advantage of it. Moreover, to do the OBJECT_ADDED check, we have to do a hash lookup in `obj_hash`. So we can drop the lookup_unknown_object() call completely, *and* the OBJECT_ADDED flag, too, since the spot we're touching here is the only location that checks it. In the end, we perform the same number of hash lookups, but with the added bonus that we don't waste memory allocating an OBJ_NONE object (if we were traversing, we'd need it eventually, but the whole point of this code path is not to traverse). Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9fd2f2 commit b017334

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

builtin/pack-objects.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,13 +3405,9 @@ static void read_object_list_from_stdin(void)
34053405
}
34063406
}
34073407

3408-
/* Remember to update object flag allocation in object.h */
3409-
#define OBJECT_ADDED (1u<<20)
3410-
34113408
static void show_commit(struct commit *commit, void *data)
34123409
{
34133410
add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0);
3414-
commit->object.flags |= OBJECT_ADDED;
34153411

34163412
if (write_bitmap_index)
34173413
index_commit_for_bitmap(commit);
@@ -3424,7 +3420,6 @@ static void show_object(struct object *obj, const char *name, void *data)
34243420
{
34253421
add_preferred_base_object(name);
34263422
add_object_entry(&obj->oid, obj->type, name, 0);
3427-
obj->flags |= OBJECT_ADDED;
34283423

34293424
if (use_delta_islands) {
34303425
const char *p;
@@ -3510,11 +3505,7 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
35103505
uint32_t pos,
35113506
void *_data)
35123507
{
3513-
struct object *obj = lookup_unknown_object(the_repository, oid);
3514-
if (obj->flags & OBJECT_ADDED)
3515-
return 0;
3516-
add_object_entry(oid, obj->type, "", 0);
3517-
obj->flags |= OBJECT_ADDED;
3508+
add_object_entry(oid, OBJ_NONE, "", 0);
35183509
return 0;
35193510
}
35203511

object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct object_array {
7575
* builtin/fsck.c: 0--3
7676
* builtin/gc.c: 0
7777
* builtin/index-pack.c: 2021
78-
* builtin/pack-objects.c: 20
7978
* builtin/reflog.c: 10--12
8079
* builtin/show-branch.c: 0-------------------------------------------26
8180
* builtin/unpack-objects.c: 2021

0 commit comments

Comments
 (0)