Skip to content

Commit 4ba7825

Browse files
derrickstoleedscho
authored andcommitted
pack-objects: extract should_attempt_deltas()
This will be helpful in a future change. Signed-off-by: Derrick Stolee <[email protected]>
1 parent c828be5 commit 4ba7825

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

builtin/pack-objects.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,6 +3163,33 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
31633163
return 0;
31643164
}
31653165

3166+
static int should_attempt_deltas(struct object_entry *entry)
3167+
{
3168+
if (DELTA(entry))
3169+
return 0;
3170+
3171+
if (!entry->type_valid ||
3172+
oe_size_less_than(&to_pack, entry, 50))
3173+
return 0;
3174+
3175+
if (entry->no_try_delta)
3176+
return 0;
3177+
3178+
if (!entry->preferred_base) {
3179+
if (oe_type(entry) < 0)
3180+
die(_("unable to get type of object %s"),
3181+
oid_to_hex(&entry->idx.oid));
3182+
} else if (oe_type(entry) < 0) {
3183+
/*
3184+
* This object is not found, but we
3185+
* don't have to include it anyway.
3186+
*/
3187+
return 0;
3188+
}
3189+
3190+
return 1;
3191+
}
3192+
31663193
static void prepare_pack(int window, int depth)
31673194
{
31683195
struct object_entry **delta_list;
@@ -3193,33 +3220,11 @@ static void prepare_pack(int window, int depth)
31933220
for (i = 0; i < to_pack.nr_objects; i++) {
31943221
struct object_entry *entry = to_pack.objects + i;
31953222

3196-
if (DELTA(entry))
3197-
/* This happens if we decided to reuse existing
3198-
* delta from a pack. "reuse_delta &&" is implied.
3199-
*/
3200-
continue;
3201-
3202-
if (!entry->type_valid ||
3203-
oe_size_less_than(&to_pack, entry, 50))
3223+
if (!should_attempt_deltas(entry))
32043224
continue;
32053225

3206-
if (entry->no_try_delta)
3207-
continue;
3208-
3209-
if (!entry->preferred_base) {
3226+
if (!entry->preferred_base)
32103227
nr_deltas++;
3211-
if (oe_type(entry) < 0)
3212-
die(_("unable to get type of object %s"),
3213-
oid_to_hex(&entry->idx.oid));
3214-
} else {
3215-
if (oe_type(entry) < 0) {
3216-
/*
3217-
* This object is not found, but we
3218-
* don't have to include it anyway.
3219-
*/
3220-
continue;
3221-
}
3222-
}
32233228

32243229
delta_list[n++] = entry;
32253230
}

0 commit comments

Comments
 (0)