Skip to content

Commit 48761b8

Browse files
committed
pack-objects: extract should_attempt_deltas()
This will be helpful in a future change. Signed-off-by: Derrick Stolee <[email protected]>
1 parent d835e3b commit 48761b8

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
@@ -3147,6 +3147,33 @@ static int add_ref_tag(const char *tag UNUSED, const struct object_id *oid,
31473147
return 0;
31483148
}
31493149

3150+
static int should_attempt_deltas(struct object_entry *entry)
3151+
{
3152+
if (DELTA(entry))
3153+
return 0;
3154+
3155+
if (!entry->type_valid ||
3156+
oe_size_less_than(&to_pack, entry, 50))
3157+
return 0;
3158+
3159+
if (entry->no_try_delta)
3160+
return 0;
3161+
3162+
if (!entry->preferred_base) {
3163+
if (oe_type(entry) < 0)
3164+
die(_("unable to get type of object %s"),
3165+
oid_to_hex(&entry->idx.oid));
3166+
} else if (oe_type(entry) < 0) {
3167+
/*
3168+
* This object is not found, but we
3169+
* don't have to include it anyway.
3170+
*/
3171+
return 0;
3172+
}
3173+
3174+
return 1;
3175+
}
3176+
31503177
static void prepare_pack(int window, int depth)
31513178
{
31523179
struct object_entry **delta_list;
@@ -3177,33 +3204,11 @@ static void prepare_pack(int window, int depth)
31773204
for (i = 0; i < to_pack.nr_objects; i++) {
31783205
struct object_entry *entry = to_pack.objects + i;
31793206

3180-
if (DELTA(entry))
3181-
/* This happens if we decided to reuse existing
3182-
* delta from a pack. "reuse_delta &&" is implied.
3183-
*/
3184-
continue;
3185-
3186-
if (!entry->type_valid ||
3187-
oe_size_less_than(&to_pack, entry, 50))
3207+
if (!should_attempt_deltas(entry))
31883208
continue;
31893209

3190-
if (entry->no_try_delta)
3191-
continue;
3192-
3193-
if (!entry->preferred_base) {
3210+
if (!entry->preferred_base)
31943211
nr_deltas++;
3195-
if (oe_type(entry) < 0)
3196-
die(_("unable to get type of object %s"),
3197-
oid_to_hex(&entry->idx.oid));
3198-
} else {
3199-
if (oe_type(entry) < 0) {
3200-
/*
3201-
* This object is not found, but we
3202-
* don't have to include it anyway.
3203-
*/
3204-
continue;
3205-
}
3206-
}
32073212

32083213
delta_list[n++] = entry;
32093214
}

0 commit comments

Comments
 (0)