pack-objects: extract should_attempt_deltas()
This will be helpful in a future change, which will reuse this logic. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
May 16, 2025 at 18:11 UTC
4bc0ba082907464fd940d9025b641d52ce6e56e3
1 file changed
+32
-24
builtin/pack-objects.c
+32
-24
@@ -3196,6 +3196,36 @@ static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, cons
3196
return 0;
3197
}
3198
3199
+static int should_attempt_deltas(struct object_entry *entry)
3200
+{
3201
+ if (DELTA(entry))
3202
+ /* This happens if we decided to reuse existing
3203
+ * delta from a pack. "reuse_delta &&" is implied.
3204
+ */
3205
+ return 0;
3206
+
3207
+ if (!entry->type_valid ||
3208
+ oe_size_less_than(&to_pack, entry, 50))
3209
+ return 0;
3210
+
3211
+ if (entry->no_try_delta)
3212
+ return 0;
3213
+
3214
+ if (!entry->preferred_base) {
3215
+ if (oe_type(entry) < 0)
3216
+ die(_("unable to get type of object %s"),
3217
+ oid_to_hex(&entry->idx.oid));
3218
+ } else if (oe_type(entry) < 0) {
3219
+ /*
3220
+ * This object is not found, but we
3221
+ * don't have to include it anyway.
3222
+ */
3223
+ return 0;
3224
+ }
3225
+
3226
+ return 1;
3227
+}
3228
+
3229
static void prepare_pack(int window, int depth)
3230
{
3231
struct object_entry **delta_list;
@@ -3226,33 +3256,11 @@ static void prepare_pack(int window, int depth)
3256
for (i = 0; i < to_pack.nr_objects; i++) {
3257
struct object_entry *entry = to_pack.objects + i;
3258
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))
3259
+ if (!should_attempt_deltas(entry))
3260
continue;
3261
3239
- if (entry->no_try_delta)
3240
- continue;
3241
-
3242
- if (!entry->preferred_base) {
3262
+ if (!entry->preferred_base)
3263
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
- }
3264
3265
delta_list[n++] = entry;
3266
}