Skip to content

Commit 87c86a2

Browse files
authored
Merge pull request #2831 from dscho/prepare-for-v2.29.0-rc0
Prepare for v2.29.0-rc0
2 parents 568c2f1 + edc387f commit 87c86a2

File tree

13 files changed

+172
-120
lines changed

13 files changed

+172
-120
lines changed

builtin/clean.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
166166
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
167167
is_nonbare_repository_dir(path)) {
168168
if (!quiet) {
169-
quote_path_relative(path->buf, prefix, &quoted);
169+
quote_path(path->buf, prefix, &quoted, 0);
170170
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
171171
quoted.buf);
172172
}
@@ -178,7 +178,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
178178
if (is_mount_point(path)) {
179179
#ifndef CAN_UNLINK_MOUNT_POINTS
180180
if (!quiet) {
181-
quote_path_relative(path->buf, prefix, &quoted);
181+
quote_path(path->buf, prefix, &quoted, 0);
182182
printf(dry_run ?
183183
_(msg_would_skip_mount_point) :
184184
_(msg_skip_mount_point), quoted.buf);
@@ -187,7 +187,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
187187
#else
188188
if (!dry_run && unlink(path->buf)) {
189189
int saved_errno = errno;
190-
quote_path_relative(path->buf, prefix, &quoted);
190+
quote_path(path->buf, prefix, &quoted, 0);
191191
errno = saved_errno;
192192
warning_errno(_(msg_warn_remove_failed), quoted.buf);
193193
*dir_gone = 0;
@@ -204,7 +204,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
204204
res = dry_run ? 0 : rmdir(path->buf);
205205
if (res) {
206206
int saved_errno = errno;
207-
quote_path_relative(path->buf, prefix, &quoted);
207+
quote_path(path->buf, prefix, &quoted, 0);
208208
errno = saved_errno;
209209
warning_errno(_(msg_warn_remove_failed), quoted.buf);
210210
*dir_gone = 0;
@@ -229,19 +229,19 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
229229
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
230230
ret = 1;
231231
if (gone) {
232-
quote_path_relative(path->buf, prefix, &quoted);
232+
quote_path(path->buf, prefix, &quoted, 0);
233233
string_list_append(&dels, quoted.buf);
234234
} else
235235
*dir_gone = 0;
236236
continue;
237237
} else {
238238
res = dry_run ? 0 : unlink(path->buf);
239239
if (!res) {
240-
quote_path_relative(path->buf, prefix, &quoted);
240+
quote_path(path->buf, prefix, &quoted, 0);
241241
string_list_append(&dels, quoted.buf);
242242
} else {
243243
int saved_errno = errno;
244-
quote_path_relative(path->buf, prefix, &quoted);
244+
quote_path(path->buf, prefix, &quoted, 0);
245245
errno = saved_errno;
246246
warning_errno(_(msg_warn_remove_failed), quoted.buf);
247247
*dir_gone = 0;
@@ -265,7 +265,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
265265
*dir_gone = 1;
266266
else {
267267
int saved_errno = errno;
268-
quote_path_relative(path->buf, prefix, &quoted);
268+
quote_path(path->buf, prefix, &quoted, 0);
269269
errno = saved_errno;
270270
warning_errno(_(msg_warn_remove_failed), quoted.buf);
271271
*dir_gone = 0;
@@ -293,7 +293,7 @@ static void pretty_print_dels(void)
293293
struct column_options copts;
294294

295295
for_each_string_list_item(item, &del_list) {
296-
qname = quote_path_relative(item->string, NULL, &buf);
296+
qname = quote_path(item->string, NULL, &buf, 0);
297297
string_list_append(&list, qname);
298298
}
299299

@@ -780,7 +780,7 @@ static int ask_each_cmd(void)
780780
for_each_string_list_item(item, &del_list) {
781781
/* Ctrl-D should stop removing files */
782782
if (!eof) {
783-
qname = quote_path_relative(item->string, NULL, &buf);
783+
qname = quote_path(item->string, NULL, &buf, 0);
784784
/* TRANSLATORS: Make sure to keep [y/N] as is */
785785
printf(_("Remove %s [y/N]? "), qname);
786786
if (git_read_line_interactively(&confirm) == EOF) {
@@ -1079,19 +1079,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10791079
if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone))
10801080
errors++;
10811081
if (gone && !quiet) {
1082-
qname = quote_path_relative(item->string, NULL, &buf);
1082+
qname = quote_path(item->string, NULL, &buf, 0);
10831083
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10841084
}
10851085
} else {
10861086
res = dry_run ? 0 : unlink(abs_path.buf);
10871087
if (res) {
10881088
int saved_errno = errno;
1089-
qname = quote_path_relative(item->string, NULL, &buf);
1089+
qname = quote_path(item->string, NULL, &buf, 0);
10901090
errno = saved_errno;
10911091
warning_errno(_(msg_warn_remove_failed), qname);
10921092
errors++;
10931093
} else if (!quiet) {
1094-
qname = quote_path_relative(item->string, NULL, &buf);
1094+
qname = quote_path(item->string, NULL, &buf, 0);
10951095
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10961096
}
10971097
}

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
319319
}
320320

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

compat/win32/fscache.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CRITICAL_SECTION fscache_cs;
1919
struct fscache {
2020
volatile long enabled;
2121
struct hashmap map;
22-
struct mem_pool *mem_pool;
22+
struct mem_pool mem_pool;
2323
unsigned int lstat_requests;
2424
unsigned int opendir_requests;
2525
unsigned int fscache_requests;
@@ -132,7 +132,7 @@ static struct fsentry *fsentry_alloc(struct fscache *cache, struct fsentry *list
132132
{
133133
/* overallocate fsentry and copy the name to the end */
134134
struct fsentry *fse =
135-
mem_pool_alloc(cache->mem_pool, sizeof(*fse) + len + 1);
135+
mem_pool_alloc(&cache->mem_pool, sizeof(*fse) + len + 1);
136136
/* init the rest of the structure */
137137
fsentry_init(fse, list, name, len);
138138
fse->next = NULL;
@@ -355,8 +355,7 @@ static void fscache_add(struct fscache *cache, struct fsentry *fse)
355355
*/
356356
static void fscache_clear(struct fscache *cache)
357357
{
358-
mem_pool_discard(cache->mem_pool, 0);
359-
cache->mem_pool = NULL;
358+
mem_pool_discard(&cache->mem_pool, 0);
360359
mem_pool_init(&cache->mem_pool, 0);
361360
hashmap_free(&cache->map);
362361
hashmap_init(&cache->map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
@@ -534,7 +533,7 @@ void fscache_disable(void)
534533
"total requests/misses %u/%u\n",
535534
cache->lstat_requests, cache->opendir_requests,
536535
cache->fscache_requests, cache->fscache_misses);
537-
mem_pool_discard(cache->mem_pool, 0);
536+
mem_pool_discard(&cache->mem_pool, 0);
538537
hashmap_free(&cache->map);
539538
free(cache);
540539
}
@@ -766,7 +765,7 @@ void fscache_merge(struct fscache *dest)
766765
while ((e = hashmap_iter_next(&iter)))
767766
hashmap_add(&dest->map, e);
768767

769-
mem_pool_combine(dest->mem_pool, cache->mem_pool);
768+
mem_pool_combine(&dest->mem_pool, &cache->mem_pool);
770769

771770
dest->lstat_requests += cache->lstat_requests;
772771
dest->opendir_requests += cache->opendir_requests;

diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,14 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
482482

483483
static char *quote_two(const char *one, const char *two)
484484
{
485-
int need_one = quote_c_style(one, NULL, NULL, 1);
486-
int need_two = quote_c_style(two, NULL, NULL, 1);
485+
int need_one = quote_c_style(one, NULL, NULL, CQUOTE_NODQ);
486+
int need_two = quote_c_style(two, NULL, NULL, CQUOTE_NODQ);
487487
struct strbuf res = STRBUF_INIT;
488488

489489
if (need_one + need_two) {
490490
strbuf_addch(&res, '"');
491-
quote_c_style(one, &res, NULL, 1);
492-
quote_c_style(two, &res, NULL, 1);
491+
quote_c_style(one, &res, NULL, CQUOTE_NODQ);
492+
quote_c_style(two, &res, NULL, CQUOTE_NODQ);
493493
strbuf_addch(&res, '"');
494494
} else {
495495
strbuf_addstr(&res, one);

fast-import.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,6 @@ static unsigned int hc_str(const char *s, size_t len)
526526
return r;
527527
}
528528

529-
static char *pool_strdup(const char *s)
530-
{
531-
size_t len = strlen(s) + 1;
532-
char *r = mem_pool_alloc(&fi_mem_pool, len);
533-
memcpy(r, s, len);
534-
return r;
535-
}
536-
537529
static void insert_mark(struct mark_set *s, uintmax_t idnum, struct object_entry *oe)
538530
{
539531
while ((idnum >> s->shift) >= 1024) {
@@ -615,7 +607,7 @@ static struct branch *new_branch(const char *name)
615607
die("Branch name doesn't conform to GIT standards: %s", name);
616608

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

28072799
t = mem_pool_alloc(&fi_mem_pool, sizeof(struct tag));
28082800
memset(t, 0, sizeof(struct tag));
2809-
t->name = pool_strdup(arg);
2801+
t->name = mem_pool_strdup(&fi_mem_pool, arg);
28102802
if (last_tag)
28112803
last_tag->next_tag = t;
28122804
else

mem-pool.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);
1313
* `insert_after`. If `insert_after` is NULL, then insert block at the
1414
* head of the linked list.
1515
*/
16-
static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc, struct mp_block *insert_after)
16+
static struct mp_block *mem_pool_alloc_block(struct mem_pool *pool,
17+
size_t block_alloc,
18+
struct mp_block *insert_after)
1719
{
1820
struct mp_block *p;
1921

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

2325
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
2729
p->next_block = insert_after->next_block;
2830
insert_after->next_block = p;
2931
} else {
30-
p->next_block = mem_pool->mp_block;
31-
mem_pool->mp_block = p;
32+
p->next_block = pool->mp_block;
33+
pool->mp_block = p;
3234
}
3335

3436
return p;
3537
}
3638

37-
void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)
39+
void mem_pool_init(struct mem_pool *pool, size_t initial_size)
3840
{
39-
struct mem_pool *pool;
40-
41-
if (*mem_pool)
42-
return;
43-
44-
pool = xcalloc(1, sizeof(*pool));
45-
41+
memset(pool, 0, sizeof(*pool));
4642
pool->block_alloc = BLOCK_GROWTH_SIZE;
4743

4844
if (initial_size > 0)
4945
mem_pool_alloc_block(pool, initial_size, NULL);
5046

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

56-
void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
51+
void mem_pool_discard(struct mem_pool *pool, int invalidate_memory)
5752
{
5853
struct mp_block *block, *block_to_free;
5954

6055
trace_printf_key(&trace_mem_pool, "mem_pool (%p): discard (%"PRIuMAX") unused\n",
61-
mem_pool, (uintmax_t)(mem_pool->mp_block->end - mem_pool->mp_block->next_free));
62-
block = mem_pool->mp_block;
56+
pool, (uintmax_t)(pool->mp_block->end - pool->mp_block->next_free));
57+
block = pool->mp_block;
6358
while (block)
6459
{
6560
block_to_free = block;
@@ -71,10 +66,11 @@ void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
7166
free(block_to_free);
7267
}
7368

74-
free(mem_pool);
69+
pool->mp_block = NULL;
70+
pool->pool_alloc = 0;
7571
}
7672

77-
void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
73+
void *mem_pool_alloc(struct mem_pool *pool, size_t len)
7874
{
7975
struct mp_block *p = NULL;
8076
void *r;
@@ -83,36 +79,54 @@ void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
8379
if (len & (sizeof(uintmax_t) - 1))
8480
len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
8581

86-
if (mem_pool->mp_block &&
87-
mem_pool->mp_block->end - mem_pool->mp_block->next_free >= len)
88-
p = mem_pool->mp_block;
82+
if (pool->mp_block &&
83+
pool->mp_block->end - pool->mp_block->next_free >= len)
84+
p = pool->mp_block;
8985

9086
if (!p) {
91-
if (len >= (mem_pool->block_alloc / 2))
92-
return mem_pool_alloc_block(mem_pool, len, mem_pool->mp_block);
87+
if (len >= (pool->block_alloc / 2))
88+
return mem_pool_alloc_block(pool, len, pool->mp_block);
9389

94-
p = mem_pool_alloc_block(mem_pool, mem_pool->block_alloc, NULL);
90+
p = mem_pool_alloc_block(pool, pool->block_alloc, NULL);
9591
}
9692

9793
r = p->next_free;
9894
p->next_free += len;
9995
return r;
10096
}
10197

102-
void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size)
98+
void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size)
10399
{
104100
size_t len = st_mult(count, size);
105-
void *r = mem_pool_alloc(mem_pool, len);
101+
void *r = mem_pool_alloc(pool, len);
106102
memset(r, 0, len);
107103
return r;
108104
}
109105

110-
int mem_pool_contains(struct mem_pool *mem_pool, void *mem)
106+
char *mem_pool_strdup(struct mem_pool *pool, const char *str)
107+
{
108+
size_t len = strlen(str) + 1;
109+
char *ret = mem_pool_alloc(pool, len);
110+
111+
return memcpy(ret, str, len);
112+
}
113+
114+
char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len)
115+
{
116+
char *p = memchr(str, '\0', len);
117+
size_t actual_len = (p ? p - str : len);
118+
char *ret = mem_pool_alloc(pool, actual_len+1);
119+
120+
ret[actual_len] = '\0';
121+
return memcpy(ret, str, actual_len);
122+
}
123+
124+
int mem_pool_contains(struct mem_pool *pool, void *mem)
111125
{
112126
struct mp_block *p;
113127

114128
/* Check if memory is allocated in a block */
115-
for (p = mem_pool->mp_block; p; p = p->next_block)
129+
for (p = pool->mp_block; p; p = p->next_block)
116130
if ((mem >= ((void *)p->space)) &&
117131
(mem < ((void *)p->end)))
118132
return 1;

mem-pool.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ struct mem_pool {
2424
/*
2525
* Initialize mem_pool with specified initial size.
2626
*/
27-
void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
27+
void mem_pool_init(struct mem_pool *pool, size_t initial_size);
2828

2929
/*
30-
* Discard a memory pool and free all the memory it is responsible for.
30+
* Discard all the memory the memory pool is responsible for.
3131
*/
32-
void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory);
32+
void mem_pool_discard(struct mem_pool *pool, int invalidate_memory);
3333

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

44+
/*
45+
* Allocate memory from the memory pool and copy str into it.
46+
*/
47+
char *mem_pool_strdup(struct mem_pool *pool, const char *str);
48+
char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len);
49+
4450
/*
4551
* Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
4652
* 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);
5258
* Check if a memory pointed at by 'mem' is part of the range of
5359
* memory managed by the specified mem_pool.
5460
*/
55-
int mem_pool_contains(struct mem_pool *mem_pool, void *mem);
61+
int mem_pool_contains(struct mem_pool *pool, void *mem);
5662

5763
#endif

0 commit comments

Comments
 (0)