Skip to content

Commit 9a00ffd

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 1a3ea78 commit 9a00ffd

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
@@ -3175,6 +3175,33 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
31753175
return 0;
31763176
}
31773177

3178+
static int should_attempt_deltas(struct object_entry *entry)
3179+
{
3180+
if (DELTA(entry))
3181+
return 0;
3182+
3183+
if (!entry->type_valid ||
3184+
oe_size_less_than(&to_pack, entry, 50))
3185+
return 0;
3186+
3187+
if (entry->no_try_delta)
3188+
return 0;
3189+
3190+
if (!entry->preferred_base) {
3191+
if (oe_type(entry) < 0)
3192+
die(_("unable to get type of object %s"),
3193+
oid_to_hex(&entry->idx.oid));
3194+
} else if (oe_type(entry) < 0) {
3195+
/*
3196+
* This object is not found, but we
3197+
* don't have to include it anyway.
3198+
*/
3199+
return 0;
3200+
}
3201+
3202+
return 1;
3203+
}
3204+
31783205
static void prepare_pack(int window, int depth)
31793206
{
31803207
struct object_entry **delta_list;
@@ -3205,33 +3232,11 @@ static void prepare_pack(int window, int depth)
32053232
for (i = 0; i < to_pack.nr_objects; i++) {
32063233
struct object_entry *entry = to_pack.objects + i;
32073234

3208-
if (DELTA(entry))
3209-
/* This happens if we decided to reuse existing
3210-
* delta from a pack. "reuse_delta &&" is implied.
3211-
*/
3212-
continue;
3213-
3214-
if (!entry->type_valid ||
3215-
oe_size_less_than(&to_pack, entry, 50))
3235+
if (!should_attempt_deltas(entry))
32163236
continue;
32173237

3218-
if (entry->no_try_delta)
3219-
continue;
3220-
3221-
if (!entry->preferred_base) {
3238+
if (!entry->preferred_base)
32223239
nr_deltas++;
3223-
if (oe_type(entry) < 0)
3224-
die(_("unable to get type of object %s"),
3225-
oid_to_hex(&entry->idx.oid));
3226-
} else {
3227-
if (oe_type(entry) < 0) {
3228-
/*
3229-
* This object is not found, but we
3230-
* don't have to include it anyway.
3231-
*/
3232-
continue;
3233-
}
3234-
}
32353240

32363241
delta_list[n++] = entry;
32373242
}

0 commit comments

Comments
 (0)