提交 fdfec7af 编写于 作者: J Junio C Hamano

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
...@@ -431,12 +431,14 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info) ...@@ -431,12 +431,14 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
define_commit_slab(ref_bitmap, uint32_t *); define_commit_slab(ref_bitmap, uint32_t *);
#define POOL_SIZE (512 * 1024)
struct paint_info { struct paint_info {
struct ref_bitmap ref_bitmap; struct ref_bitmap ref_bitmap;
unsigned nr_bits; unsigned nr_bits;
char **slab; char **pools;
char *free, *end; char *free, *end;
unsigned slab_count; unsigned pool_count;
}; };
static uint32_t *paint_alloc(struct paint_info *info) static uint32_t *paint_alloc(struct paint_info *info)
...@@ -444,12 +446,15 @@ static uint32_t *paint_alloc(struct paint_info *info) ...@@ -444,12 +446,15 @@ static uint32_t *paint_alloc(struct paint_info *info)
unsigned nr = (info->nr_bits + 31) / 32; unsigned nr = (info->nr_bits + 31) / 32;
unsigned size = nr * sizeof(uint32_t); unsigned size = nr * sizeof(uint32_t);
void *p; void *p;
if (!info->slab_count || info->free + size > info->end) { if (!info->pool_count || size > info->end - info->free) {
info->slab_count++; if (size > POOL_SIZE)
REALLOC_ARRAY(info->slab, info->slab_count); die("BUG: pool size too small for %d in paint_alloc()",
info->free = xmalloc(COMMIT_SLAB_SIZE); size);
info->slab[info->slab_count - 1] = info->free; info->pool_count++;
info->end = info->free + COMMIT_SLAB_SIZE; REALLOC_ARRAY(info->pools, info->pool_count);
info->free = xmalloc(POOL_SIZE);
info->pools[info->pool_count - 1] = info->free;
info->end = info->free + POOL_SIZE;
} }
p = info->free; p = info->free;
info->free += size; info->free += size;
...@@ -462,7 +467,7 @@ static uint32_t *paint_alloc(struct paint_info *info) ...@@ -462,7 +467,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
* all walked commits. * all walked commits.
*/ */
static void paint_down(struct paint_info *info, const unsigned char *sha1, static void paint_down(struct paint_info *info, const unsigned char *sha1,
int id) unsigned int id)
{ {
unsigned int i, nr; unsigned int i, nr;
struct commit_list *head = NULL; struct commit_list *head = NULL;
...@@ -474,7 +479,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, ...@@ -474,7 +479,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
if (!c) if (!c)
return; return;
memset(bitmap, 0, bitmap_size); memset(bitmap, 0, bitmap_size);
bitmap[id / 32] |= (1 << (id % 32)); bitmap[id / 32] |= (1U << (id % 32));
commit_list_insert(c, &head); commit_list_insert(c, &head);
while (head) { while (head) {
struct commit_list *p; struct commit_list *p;
...@@ -507,12 +512,8 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, ...@@ -507,12 +512,8 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
oid_to_hex(&c->object.oid)); oid_to_hex(&c->object.oid));
for (p = c->parents; p; p = p->next) { for (p = c->parents; p; p = p->next) {
uint32_t **p_refs = ref_bitmap_at(&info->ref_bitmap,
p->item);
if (p->item->object.flags & SEEN) if (p->item->object.flags & SEEN)
continue; continue;
if (*p_refs == NULL || *p_refs == *refs)
*p_refs = *refs;
commit_list_insert(p->item, &head); commit_list_insert(p->item, &head);
} }
} }
...@@ -624,9 +625,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, ...@@ -624,9 +625,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
post_assign_shallow(info, &pi.ref_bitmap, ref_status); post_assign_shallow(info, &pi.ref_bitmap, ref_status);
clear_ref_bitmap(&pi.ref_bitmap); clear_ref_bitmap(&pi.ref_bitmap);
for (i = 0; i < pi.slab_count; i++) for (i = 0; i < pi.pool_count; i++)
free(pi.slab[i]); free(pi.pools[i]);
free(pi.slab); free(pi.pools);
free(shallow); free(shallow);
} }
...@@ -648,11 +649,11 @@ static int add_ref(const char *refname, const struct object_id *oid, ...@@ -648,11 +649,11 @@ static int add_ref(const char *refname, const struct object_id *oid,
static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap) static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap)
{ {
int i; unsigned int i;
if (!ref_status) if (!ref_status)
return; return;
for (i = 0; i < nr; i++) for (i = 0; i < nr; i++)
if (bitmap[i / 32] & (1 << (i % 32))) if (bitmap[i / 32] & (1U << (i % 32)))
ref_status[i]++; ref_status[i]++;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册