index-pack: a miniscule refactor
Introduce a helper function that takes the type of an object and tell if it is a delta, as we seem to use this check in many places. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 3, 2011 at 15:32 UTC
4f8ec74efa9fc69aa3b0bd52affe31ca09f2fdd3
1 file changed
+8
-3
builtin/index-pack.c
+8
-3
@@ -498,12 +498,17 @@ static void sha1_object(const void *data, unsigned long size,
498
}
499
}
500
501
+static int is_delta_type(enum object_type type)
502
+{
503
+ return (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA);
504
+}
505
+
506
static void *get_base_data(struct base_data *c)
507
{
508
if (!c->data) {
509
struct object_entry *obj = c->obj;
510
506
- if (obj->type == OBJ_REF_DELTA || obj->type == OBJ_OFS_DELTA) {
511
+ if (is_delta_type(obj->type)) {
512
void *base = get_base_data(c->base);
513
void *raw = get_data_from_pack(obj);
514
c->data = patch_delta(
@@ -629,7 +634,7 @@ static void parse_pack_objects(unsigned char *sha1)
634
struct object_entry *obj = &objects[i];
635
void *data = unpack_raw_entry(obj, &delta->base);
636
obj->real_type = obj->type;
632
- if (obj->type == OBJ_REF_DELTA || obj->type == OBJ_OFS_DELTA) {
637
+ if (is_delta_type(obj->type)) {
638
nr_deltas++;
639
delta->obj_no = i;
640
delta++;
@@ -676,7 +681,7 @@ static void parse_pack_objects(unsigned char *sha1)
681
struct object_entry *obj = &objects[i];
682
struct base_data base_obj;
683
679
- if (obj->type == OBJ_REF_DELTA || obj->type == OBJ_OFS_DELTA)
684
+ if (is_delta_type(obj->type))
685
continue;
686
base_obj.obj = obj;
687
base_obj.data = NULL;