Skip to content

Commit 9a1afc7

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 b50d465 commit 9a1afc7

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

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

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

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

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

0 commit comments

Comments
 (0)