Skip to content

Commit

Permalink
pack-objects: extract should_attempt_deltas()
Browse files Browse the repository at this point in the history
This will be helpful in a future change that introduces a new way to
compute deltas.

Be careful to preserve the nr_deltas counting logic in the existing
method, but take the rest of the logic wholesale.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
  • Loading branch information
derrickstolee committed Oct 8, 2024
1 parent 214e10a commit cd360ad
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,33 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
return 0;
}

static int should_attempt_deltas(struct object_entry *entry)
{
if (DELTA(entry))
return 0;

if (!entry->type_valid ||
oe_size_less_than(&to_pack, entry, 50))
return 0;

if (entry->no_try_delta)
return 0;

if (!entry->preferred_base) {
if (oe_type(entry) < 0)
die(_("unable to get type of object %s"),
oid_to_hex(&entry->idx.oid));
} else if (oe_type(entry) < 0) {
/*
* This object is not found, but we
* don't have to include it anyway.
*/
return 0;
}

return 1;
}

static void prepare_pack(int window, int depth)
{
struct object_entry **delta_list;
Expand Down Expand Up @@ -3197,33 +3224,11 @@ static void prepare_pack(int window, int depth)
for (i = 0; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;

if (DELTA(entry))
/* This happens if we decided to reuse existing
* delta from a pack. "reuse_delta &&" is implied.
*/
continue;

if (!entry->type_valid ||
oe_size_less_than(&to_pack, entry, 50))
if (!should_attempt_deltas(entry))
continue;

if (entry->no_try_delta)
continue;

if (!entry->preferred_base) {
if (!entry->preferred_base)
nr_deltas++;
if (oe_type(entry) < 0)
die(_("unable to get type of object %s"),
oid_to_hex(&entry->idx.oid));
} else {
if (oe_type(entry) < 0) {
/*
* This object is not found, but we
* don't have to include it anyway.
*/
continue;
}
}

delta_list[n++] = entry;
}
Expand Down

0 comments on commit cd360ad

Please sign in to comment.