Skip to content

Commit b7bc6ec

Browse files
derrickstoleeGit for Windows Build Agent
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 087b7d6 commit b7bc6ec

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
@@ -3197,6 +3197,33 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
31973197
return 0;
31983198
}
31993199

3200+
static int should_attempt_deltas(struct object_entry *entry)
3201+
{
3202+
if (DELTA(entry))
3203+
return 0;
3204+
3205+
if (!entry->type_valid ||
3206+
oe_size_less_than(&to_pack, entry, 50))
3207+
return 0;
3208+
3209+
if (entry->no_try_delta)
3210+
return 0;
3211+
3212+
if (!entry->preferred_base) {
3213+
if (oe_type(entry) < 0)
3214+
die(_("unable to get type of object %s"),
3215+
oid_to_hex(&entry->idx.oid));
3216+
} else if (oe_type(entry) < 0) {
3217+
/*
3218+
* This object is not found, but we
3219+
* don't have to include it anyway.
3220+
*/
3221+
return 0;
3222+
}
3223+
3224+
return 1;
3225+
}
3226+
32003227
static void prepare_pack(int window, int depth)
32013228
{
32023229
struct object_entry **delta_list;
@@ -3227,33 +3254,11 @@ static void prepare_pack(int window, int depth)
32273254
for (i = 0; i < to_pack.nr_objects; i++) {
32283255
struct object_entry *entry = to_pack.objects + i;
32293256

3230-
if (DELTA(entry))
3231-
/* This happens if we decided to reuse existing
3232-
* delta from a pack. "reuse_delta &&" is implied.
3233-
*/
3234-
continue;
3235-
3236-
if (!entry->type_valid ||
3237-
oe_size_less_than(&to_pack, entry, 50))
3257+
if (!should_attempt_deltas(entry))
32383258
continue;
32393259

3240-
if (entry->no_try_delta)
3241-
continue;
3242-
3243-
if (!entry->preferred_base) {
3260+
if (!entry->preferred_base)
32443261
nr_deltas++;
3245-
if (oe_type(entry) < 0)
3246-
die(_("unable to get type of object %s"),
3247-
oid_to_hex(&entry->idx.oid));
3248-
} else {
3249-
if (oe_type(entry) < 0) {
3250-
/*
3251-
* This object is not found, but we
3252-
* don't have to include it anyway.
3253-
*/
3254-
continue;
3255-
}
3256-
}
32573262

32583263
delta_list[n++] = entry;
32593264
}

0 commit comments

Comments
 (0)