Skip to content

Commit 2ba602c

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 9e541b9 commit 2ba602c

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
@@ -3283,6 +3283,33 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
32833283
return 0;
32843284
}
32853285

3286+
static int should_attempt_deltas(struct object_entry *entry)
3287+
{
3288+
if (DELTA(entry))
3289+
return 0;
3290+
3291+
if (!entry->type_valid ||
3292+
oe_size_less_than(&to_pack, entry, 50))
3293+
return 0;
3294+
3295+
if (entry->no_try_delta)
3296+
return 0;
3297+
3298+
if (!entry->preferred_base) {
3299+
if (oe_type(entry) < 0)
3300+
die(_("unable to get type of object %s"),
3301+
oid_to_hex(&entry->idx.oid));
3302+
} else if (oe_type(entry) < 0) {
3303+
/*
3304+
* This object is not found, but we
3305+
* don't have to include it anyway.
3306+
*/
3307+
return 0;
3308+
}
3309+
3310+
return 1;
3311+
}
3312+
32863313
static void prepare_pack(int window, int depth)
32873314
{
32883315
struct object_entry **delta_list;
@@ -3313,33 +3340,11 @@ static void prepare_pack(int window, int depth)
33133340
for (i = 0; i < to_pack.nr_objects; i++) {
33143341
struct object_entry *entry = to_pack.objects + i;
33153342

3316-
if (DELTA(entry))
3317-
/* This happens if we decided to reuse existing
3318-
* delta from a pack. "reuse_delta &&" is implied.
3319-
*/
3320-
continue;
3321-
3322-
if (!entry->type_valid ||
3323-
oe_size_less_than(&to_pack, entry, 50))
3343+
if (!should_attempt_deltas(entry))
33243344
continue;
33253345

3326-
if (entry->no_try_delta)
3327-
continue;
3328-
3329-
if (!entry->preferred_base) {
3346+
if (!entry->preferred_base)
33303347
nr_deltas++;
3331-
if (oe_type(entry) < 0)
3332-
die(_("unable to get type of object %s"),
3333-
oid_to_hex(&entry->idx.oid));
3334-
} else {
3335-
if (oe_type(entry) < 0) {
3336-
/*
3337-
* This object is not found, but we
3338-
* don't have to include it anyway.
3339-
*/
3340-
continue;
3341-
}
3342-
}
33433348

33443349
delta_list[n++] = entry;
33453350
}

0 commit comments

Comments
 (0)