pack-bitmap: factor out 'add_commit_to_bitmap()'
'find_objects()' currently needs to interact with the bitmaps khash pretty closely. To make 'find_objects()' read a little more straightforwardly, remove some of the khash-level details into a new function that describes what it does: 'add_commit_to_bitmap()'. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Dec 8, 2020 at 17:05 UTC
83578051a9c4eca4e6bcd44687e84915e1064bba
1 file changed
+21
-15
pack-bitmap.c
+21
-15
@@ -521,6 +521,23 @@ static int should_include(struct commit *commit, void *_data)
521
return 1;
522
}
523
524
+static int add_commit_to_bitmap(struct bitmap_index *bitmap_git,
525
+ struct bitmap **base,
526
+ struct commit *commit)
527
+{
528
+ struct ewah_bitmap *or_with = bitmap_for_commit(bitmap_git, commit);
529
+
530
+ if (!or_with)
531
+ return 0;
532
+
533
+ if (*base == NULL)
534
+ *base = ewah_to_bitmap(or_with);
535
+ else
536
+ bitmap_or_ewah(*base, or_with);
537
+
538
+ return 1;
539
+}
540
+
541
static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
542
struct rev_info *revs,
543
struct object_list *roots,
@@ -544,21 +561,10 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
561
struct object *object = roots->item;
562
roots = roots->next;
563
547
- if (object->type == OBJ_COMMIT) {
548
- khiter_t pos = kh_get_oid_map(bitmap_git->bitmaps, object->oid);
549
-
550
- if (pos < kh_end(bitmap_git->bitmaps)) {
551
- struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
552
- struct ewah_bitmap *or_with = lookup_stored_bitmap(st);
553
-
554
- if (base == NULL)
555
- base = ewah_to_bitmap(or_with);
556
- else
557
- bitmap_or_ewah(base, or_with);
558
-
559
- object->flags |= SEEN;
560
- continue;
561
- }
564
+ if (object->type == OBJ_COMMIT &&
565
+ add_commit_to_bitmap(bitmap_git, &base, (struct commit *)object)) {
566
+ object->flags |= SEEN;
567
+ continue;
568
}
569
570
object_list_insert(object, ¬_mapped);