Skip to content
Permalink
Browse files
Merge pull request #2831 from dscho/prepare-for-v2.29.0-rc0
Prepare for v2.29.0-rc0
  • Loading branch information
dscho committed Sep 23, 2020
2 parents 568c2f1 + edc387f commit 87c86a26dea4a3ea72e9ba3b499878e36dbacbfa
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 120 deletions.
@@ -166,7 +166,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
is_nonbare_repository_dir(path)) {
if (!quiet) {
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
quoted.buf);
}
@@ -178,7 +178,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
if (is_mount_point(path)) {
#ifndef CAN_UNLINK_MOUNT_POINTS
if (!quiet) {
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
printf(dry_run ?
_(msg_would_skip_mount_point) :
_(msg_skip_mount_point), quoted.buf);
@@ -187,7 +187,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
#else
if (!dry_run && unlink(path->buf)) {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
@@ -204,7 +204,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
res = dry_run ? 0 : rmdir(path->buf);
if (res) {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
@@ -229,19 +229,19 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
ret = 1;
if (gone) {
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
string_list_append(&dels, quoted.buf);
} else
*dir_gone = 0;
continue;
} else {
res = dry_run ? 0 : unlink(path->buf);
if (!res) {
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
string_list_append(&dels, quoted.buf);
} else {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
@@ -265,7 +265,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
*dir_gone = 1;
else {
int saved_errno = errno;
quote_path_relative(path->buf, prefix, &quoted);
quote_path(path->buf, prefix, &quoted, 0);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), quoted.buf);
*dir_gone = 0;
@@ -293,7 +293,7 @@ static void pretty_print_dels(void)
struct column_options copts;

for_each_string_list_item(item, &del_list) {
qname = quote_path_relative(item->string, NULL, &buf);
qname = quote_path(item->string, NULL, &buf, 0);
string_list_append(&list, qname);
}

@@ -780,7 +780,7 @@ static int ask_each_cmd(void)
for_each_string_list_item(item, &del_list) {
/* Ctrl-D should stop removing files */
if (!eof) {
qname = quote_path_relative(item->string, NULL, &buf);
qname = quote_path(item->string, NULL, &buf, 0);
/* TRANSLATORS: Make sure to keep [y/N] as is */
printf(_("Remove %s [y/N]? "), qname);
if (git_read_line_interactively(&confirm) == EOF) {
@@ -1079,19 +1079,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone))
errors++;
if (gone && !quiet) {
qname = quote_path_relative(item->string, NULL, &buf);
qname = quote_path(item->string, NULL, &buf, 0);
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
}
} else {
res = dry_run ? 0 : unlink(abs_path.buf);
if (res) {
int saved_errno = errno;
qname = quote_path_relative(item->string, NULL, &buf);
qname = quote_path(item->string, NULL, &buf, 0);
errno = saved_errno;
warning_errno(_(msg_warn_remove_failed), qname);
errors++;
} else if (!quiet) {
qname = quote_path_relative(item->string, NULL, &buf);
qname = quote_path(item->string, NULL, &buf, 0);
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
}
}
@@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
}

if (opt->relative && opt->prefix_length)
quote_path_relative(filename + tree_name_len, opt->prefix, out);
quote_path(filename + tree_name_len, opt->prefix, out, 0);
else
quote_c_style(filename + tree_name_len, out, NULL, 0);

@@ -19,7 +19,7 @@ CRITICAL_SECTION fscache_cs;
struct fscache {
volatile long enabled;
struct hashmap map;
struct mem_pool *mem_pool;
struct mem_pool mem_pool;
unsigned int lstat_requests;
unsigned int opendir_requests;
unsigned int fscache_requests;
@@ -132,7 +132,7 @@ static struct fsentry *fsentry_alloc(struct fscache *cache, struct fsentry *list
{
/* overallocate fsentry and copy the name to the end */
struct fsentry *fse =
mem_pool_alloc(cache->mem_pool, sizeof(*fse) + len + 1);
mem_pool_alloc(&cache->mem_pool, sizeof(*fse) + len + 1);
/* init the rest of the structure */
fsentry_init(fse, list, name, len);
fse->next = NULL;
@@ -355,8 +355,7 @@ static void fscache_add(struct fscache *cache, struct fsentry *fse)
*/
static void fscache_clear(struct fscache *cache)
{
mem_pool_discard(cache->mem_pool, 0);
cache->mem_pool = NULL;
mem_pool_discard(&cache->mem_pool, 0);
mem_pool_init(&cache->mem_pool, 0);
hashmap_free(&cache->map);
hashmap_init(&cache->map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
@@ -534,7 +533,7 @@ void fscache_disable(void)
"total requests/misses %u/%u\n",
cache->lstat_requests, cache->opendir_requests,
cache->fscache_requests, cache->fscache_misses);
mem_pool_discard(cache->mem_pool, 0);
mem_pool_discard(&cache->mem_pool, 0);
hashmap_free(&cache->map);
free(cache);
}
@@ -766,7 +765,7 @@ void fscache_merge(struct fscache *dest)
while ((e = hashmap_iter_next(&iter)))
hashmap_add(&dest->map, e);

mem_pool_combine(dest->mem_pool, cache->mem_pool);
mem_pool_combine(&dest->mem_pool, &cache->mem_pool);

dest->lstat_requests += cache->lstat_requests;
dest->opendir_requests += cache->opendir_requests;
8 diff.c
@@ -482,14 +482,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)

static char *quote_two(const char *one, const char *two)
{
int need_one = quote_c_style(one, NULL, NULL, 1);
int need_two = quote_c_style(two, NULL, NULL, 1);
int need_one = quote_c_style(one, NULL, NULL, CQUOTE_NODQ);
int need_two = quote_c_style(two, NULL, NULL, CQUOTE_NODQ);
struct strbuf res = STRBUF_INIT;

if (need_one + need_two) {
strbuf_addch(&res, '"');
quote_c_style(one, &res, NULL, 1);
quote_c_style(two, &res, NULL, 1);
quote_c_style(one, &res, NULL, CQUOTE_NODQ);
quote_c_style(two, &res, NULL, CQUOTE_NODQ);
strbuf_addch(&res, '"');
} else {
strbuf_addstr(&res, one);
@@ -526,14 +526,6 @@ static unsigned int hc_str(const char *s, size_t len)
return r;
}

static char *pool_strdup(const char *s)
{
size_t len = strlen(s) + 1;
char *r = mem_pool_alloc(&fi_mem_pool, len);
memcpy(r, s, len);
return r;
}

static void insert_mark(struct mark_set *s, uintmax_t idnum, struct object_entry *oe)
{
while ((idnum >> s->shift) >= 1024) {
@@ -615,7 +607,7 @@ static struct branch *new_branch(const char *name)
die("Branch name doesn't conform to GIT standards: %s", name);

b = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct branch));
b->name = pool_strdup(name);
b->name = mem_pool_strdup(&fi_mem_pool, name);
b->table_next_branch = branch_table[hc];
b->branch_tree.versions[0].mode = S_IFDIR;
b->branch_tree.versions[1].mode = S_IFDIR;
@@ -2806,7 +2798,7 @@ static void parse_new_tag(const char *arg)

t = mem_pool_alloc(&fi_mem_pool, sizeof(struct tag));
memset(t, 0, sizeof(struct tag));
t->name = pool_strdup(arg);
t->name = mem_pool_strdup(&fi_mem_pool, arg);
if (last_tag)
last_tag->next_tag = t;
else
@@ -13,11 +13,13 @@ static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);
* `insert_after`. If `insert_after` is NULL, then insert block at the
* head of the linked list.
*/
static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc, struct mp_block *insert_after)
static struct mp_block *mem_pool_alloc_block(struct mem_pool *pool,
size_t block_alloc,
struct mp_block *insert_after)
{
struct mp_block *p;

mem_pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
p = xmalloc(st_add(sizeof(struct mp_block), block_alloc));

p->next_free = (char *)p->space;
@@ -27,39 +29,32 @@ static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t b
p->next_block = insert_after->next_block;
insert_after->next_block = p;
} else {
p->next_block = mem_pool->mp_block;
mem_pool->mp_block = p;
p->next_block = pool->mp_block;
pool->mp_block = p;
}

return p;
}

void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)
void mem_pool_init(struct mem_pool *pool, size_t initial_size)
{
struct mem_pool *pool;

if (*mem_pool)
return;

pool = xcalloc(1, sizeof(*pool));

memset(pool, 0, sizeof(*pool));
pool->block_alloc = BLOCK_GROWTH_SIZE;

if (initial_size > 0)
mem_pool_alloc_block(pool, initial_size, NULL);

*mem_pool = pool;
trace_printf_key(&trace_mem_pool, "mem_pool (%p): init (%"PRIuMAX") initial size\n",
pool, (uintmax_t)initial_size);
}

void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
void mem_pool_discard(struct mem_pool *pool, int invalidate_memory)
{
struct mp_block *block, *block_to_free;

trace_printf_key(&trace_mem_pool, "mem_pool (%p): discard (%"PRIuMAX") unused\n",
mem_pool, (uintmax_t)(mem_pool->mp_block->end - mem_pool->mp_block->next_free));
block = mem_pool->mp_block;
pool, (uintmax_t)(pool->mp_block->end - pool->mp_block->next_free));
block = pool->mp_block;
while (block)
{
block_to_free = block;
@@ -71,10 +66,11 @@ void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
free(block_to_free);
}

free(mem_pool);
pool->mp_block = NULL;
pool->pool_alloc = 0;
}

void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
void *mem_pool_alloc(struct mem_pool *pool, size_t len)
{
struct mp_block *p = NULL;
void *r;
@@ -83,36 +79,54 @@ void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
if (len & (sizeof(uintmax_t) - 1))
len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));

if (mem_pool->mp_block &&
mem_pool->mp_block->end - mem_pool->mp_block->next_free >= len)
p = mem_pool->mp_block;
if (pool->mp_block &&
pool->mp_block->end - pool->mp_block->next_free >= len)
p = pool->mp_block;

if (!p) {
if (len >= (mem_pool->block_alloc / 2))
return mem_pool_alloc_block(mem_pool, len, mem_pool->mp_block);
if (len >= (pool->block_alloc / 2))
return mem_pool_alloc_block(pool, len, pool->mp_block);

p = mem_pool_alloc_block(mem_pool, mem_pool->block_alloc, NULL);
p = mem_pool_alloc_block(pool, pool->block_alloc, NULL);
}

r = p->next_free;
p->next_free += len;
return r;
}

void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size)
void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size)
{
size_t len = st_mult(count, size);
void *r = mem_pool_alloc(mem_pool, len);
void *r = mem_pool_alloc(pool, len);
memset(r, 0, len);
return r;
}

int mem_pool_contains(struct mem_pool *mem_pool, void *mem)
char *mem_pool_strdup(struct mem_pool *pool, const char *str)
{
size_t len = strlen(str) + 1;
char *ret = mem_pool_alloc(pool, len);

return memcpy(ret, str, len);
}

char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len)
{
char *p = memchr(str, '\0', len);
size_t actual_len = (p ? p - str : len);
char *ret = mem_pool_alloc(pool, actual_len+1);

ret[actual_len] = '\0';
return memcpy(ret, str, actual_len);
}

int mem_pool_contains(struct mem_pool *pool, void *mem)
{
struct mp_block *p;

/* Check if memory is allocated in a block */
for (p = mem_pool->mp_block; p; p = p->next_block)
for (p = pool->mp_block; p; p = p->next_block)
if ((mem >= ((void *)p->space)) &&
(mem < ((void *)p->end)))
return 1;
@@ -24,12 +24,12 @@ struct mem_pool {
/*
* Initialize mem_pool with specified initial size.
*/
void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
void mem_pool_init(struct mem_pool *pool, size_t initial_size);

/*
* Discard a memory pool and free all the memory it is responsible for.
* Discard all the memory the memory pool is responsible for.
*/
void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory);
void mem_pool_discard(struct mem_pool *pool, int invalidate_memory);

/*
* Alloc memory from the mem_pool.
@@ -41,6 +41,12 @@ void *mem_pool_alloc(struct mem_pool *pool, size_t len);
*/
void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size);

/*
* Allocate memory from the memory pool and copy str into it.
*/
char *mem_pool_strdup(struct mem_pool *pool, const char *str);
char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len);

/*
* Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
* pool will be empty and not contain any memory. It still needs to be free'd
@@ -52,6 +58,6 @@ void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src);
* Check if a memory pointed at by 'mem' is part of the range of
* memory managed by the specified mem_pool.
*/
int mem_pool_contains(struct mem_pool *mem_pool, void *mem);
int mem_pool_contains(struct mem_pool *pool, void *mem);

#endif

0 comments on commit 87c86a2

Please sign in to comment.