Skip to content

Commit fdfec7a

Browse files
committed
Merge branch 'nd/shallow-fixup' into maint
Code cleanup in shallow boundary computation. * nd/shallow-fixup: shallow.c: remove useless code shallow.c: bit manipulation tweaks shallow.c: avoid theoretical pointer wrap-around shallow.c: make paint_alloc slightly more robust shallow.c: stop abusing COMMIT_SLAB_SIZE for paint_info's memory pools shallow.c: rename fields in paint_info to better express their purposes
2 parents 7902b72 + 649b0c3 commit fdfec7a

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

shallow.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -431,25 +431,30 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
431431

432432
define_commit_slab(ref_bitmap, uint32_t *);
433433

434+
#define POOL_SIZE (512 * 1024)
435+
434436
struct paint_info {
435437
struct ref_bitmap ref_bitmap;
436438
unsigned nr_bits;
437-
char **slab;
439+
char **pools;
438440
char *free, *end;
439-
unsigned slab_count;
441+
unsigned pool_count;
440442
};
441443

442444
static uint32_t *paint_alloc(struct paint_info *info)
443445
{
444446
unsigned nr = (info->nr_bits + 31) / 32;
445447
unsigned size = nr * sizeof(uint32_t);
446448
void *p;
447-
if (!info->slab_count || info->free + size > info->end) {
448-
info->slab_count++;
449-
REALLOC_ARRAY(info->slab, info->slab_count);
450-
info->free = xmalloc(COMMIT_SLAB_SIZE);
451-
info->slab[info->slab_count - 1] = info->free;
452-
info->end = info->free + COMMIT_SLAB_SIZE;
449+
if (!info->pool_count || size > info->end - info->free) {
450+
if (size > POOL_SIZE)
451+
die("BUG: pool size too small for %d in paint_alloc()",
452+
size);
453+
info->pool_count++;
454+
REALLOC_ARRAY(info->pools, info->pool_count);
455+
info->free = xmalloc(POOL_SIZE);
456+
info->pools[info->pool_count - 1] = info->free;
457+
info->end = info->free + POOL_SIZE;
453458
}
454459
p = info->free;
455460
info->free += size;
@@ -462,7 +467,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
462467
* all walked commits.
463468
*/
464469
static void paint_down(struct paint_info *info, const unsigned char *sha1,
465-
int id)
470+
unsigned int id)
466471
{
467472
unsigned int i, nr;
468473
struct commit_list *head = NULL;
@@ -474,7 +479,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
474479
if (!c)
475480
return;
476481
memset(bitmap, 0, bitmap_size);
477-
bitmap[id / 32] |= (1 << (id % 32));
482+
bitmap[id / 32] |= (1U << (id % 32));
478483
commit_list_insert(c, &head);
479484
while (head) {
480485
struct commit_list *p;
@@ -507,12 +512,8 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
507512
oid_to_hex(&c->object.oid));
508513

509514
for (p = c->parents; p; p = p->next) {
510-
uint32_t **p_refs = ref_bitmap_at(&info->ref_bitmap,
511-
p->item);
512515
if (p->item->object.flags & SEEN)
513516
continue;
514-
if (*p_refs == NULL || *p_refs == *refs)
515-
*p_refs = *refs;
516517
commit_list_insert(p->item, &head);
517518
}
518519
}
@@ -624,9 +625,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
624625
post_assign_shallow(info, &pi.ref_bitmap, ref_status);
625626

626627
clear_ref_bitmap(&pi.ref_bitmap);
627-
for (i = 0; i < pi.slab_count; i++)
628-
free(pi.slab[i]);
629-
free(pi.slab);
628+
for (i = 0; i < pi.pool_count; i++)
629+
free(pi.pools[i]);
630+
free(pi.pools);
630631
free(shallow);
631632
}
632633

@@ -648,11 +649,11 @@ static int add_ref(const char *refname, const struct object_id *oid,
648649

649650
static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap)
650651
{
651-
int i;
652+
unsigned int i;
652653
if (!ref_status)
653654
return;
654655
for (i = 0; i < nr; i++)
655-
if (bitmap[i / 32] & (1 << (i % 32)))
656+
if (bitmap[i / 32] & (1U << (i % 32)))
656657
ref_status[i]++;
657658
}
658659

0 commit comments

Comments
 (0)