15
15
#include "commit-slab.h"
16
16
#include "commit-graph.h"
17
17
#include "wildmatch.h"
18
+ #include "mem-pool.h"
18
19
19
20
/*
20
21
* One day. See the 'name a rev shortly after epoch' test in t6120 when
@@ -155,30 +156,25 @@ static struct rev_name *create_or_update_name(struct commit *commit,
155
156
return name ;
156
157
}
157
158
158
- static char * get_parent_name (const struct rev_name * name , int parent_number )
159
+ static char * get_parent_name (const struct rev_name * name , int parent_number ,
160
+ struct mem_pool * string_pool )
159
161
{
160
- struct strbuf sb = STRBUF_INIT ;
161
162
size_t len ;
162
163
163
164
strip_suffix (name -> tip_name , "^0" , & len );
164
165
if (name -> generation > 0 ) {
165
- strbuf_grow (& sb , len +
166
- 1 + decimal_width (name -> generation ) +
167
- 1 + decimal_width (parent_number ));
168
- strbuf_addf (& sb , "%.*s~%d^%d" , (int )len , name -> tip_name ,
169
- name -> generation , parent_number );
166
+ return mem_pool_strfmt (string_pool , "%.*s~%d^%d" ,
167
+ (int )len , name -> tip_name ,
168
+ name -> generation , parent_number );
170
169
} else {
171
- strbuf_grow (& sb , len +
172
- 1 + decimal_width (parent_number ));
173
- strbuf_addf (& sb , "%.*s^%d" , (int )len , name -> tip_name ,
174
- parent_number );
170
+ return mem_pool_strfmt (string_pool , "%.*s^%d" ,
171
+ (int )len , name -> tip_name , parent_number );
175
172
}
176
- return strbuf_detach (& sb , NULL );
177
173
}
178
174
179
175
static void name_rev (struct commit * start_commit ,
180
176
const char * tip_name , timestamp_t taggerdate ,
181
- int from_tag , int deref )
177
+ int from_tag , int deref , struct mem_pool * string_pool )
182
178
{
183
179
struct prio_queue queue ;
184
180
struct commit * commit ;
@@ -195,9 +191,10 @@ static void name_rev(struct commit *start_commit,
195
191
if (!start_name )
196
192
return ;
197
193
if (deref )
198
- start_name -> tip_name = xstrfmt ("%s^0" , tip_name );
194
+ start_name -> tip_name = mem_pool_strfmt (string_pool , "%s^0" ,
195
+ tip_name );
199
196
else
200
- start_name -> tip_name = xstrdup ( tip_name );
197
+ start_name -> tip_name = mem_pool_strdup ( string_pool , tip_name );
201
198
202
199
memset (& queue , 0 , sizeof (queue )); /* Use the prio_queue as LIFO */
203
200
prio_queue_put (& queue , start_commit );
@@ -235,7 +232,8 @@ static void name_rev(struct commit *start_commit,
235
232
if (parent_number > 1 )
236
233
parent_name -> tip_name =
237
234
get_parent_name (name ,
238
- parent_number );
235
+ parent_number ,
236
+ string_pool );
239
237
else
240
238
parent_name -> tip_name = name -> tip_name ;
241
239
ALLOC_GROW (parents_to_queue ,
@@ -415,7 +413,7 @@ static int name_ref(const char *path, const struct object_id *oid,
415
413
return 0 ;
416
414
}
417
415
418
- static void name_tips (void )
416
+ static void name_tips (struct mem_pool * string_pool )
419
417
{
420
418
int i ;
421
419
@@ -428,7 +426,7 @@ static void name_tips(void)
428
426
struct tip_table_entry * e = & tip_table .table [i ];
429
427
if (e -> commit ) {
430
428
name_rev (e -> commit , e -> refname , e -> taggerdate ,
431
- e -> from_tag , e -> deref );
429
+ e -> from_tag , e -> deref , string_pool );
432
430
}
433
431
}
434
432
}
@@ -561,6 +559,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
561
559
562
560
int cmd_name_rev (int argc , const char * * argv , const char * prefix )
563
561
{
562
+ struct mem_pool string_pool ;
564
563
struct object_array revs = OBJECT_ARRAY_INIT ;
565
564
int all = 0 , annotate_stdin = 0 , transform_stdin = 0 , allow_undefined = 1 , always = 0 , peel_tag = 0 ;
566
565
struct name_ref_data data = { 0 , 0 , STRING_LIST_INIT_NODUP , STRING_LIST_INIT_NODUP };
@@ -587,6 +586,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
587
586
OPT_END (),
588
587
};
589
588
589
+ mem_pool_init (& string_pool , 0 );
590
590
init_commit_rev_name (& rev_names );
591
591
git_config (git_default_config , NULL );
592
592
argc = parse_options (argc , argv , prefix , opts , name_rev_usage , 0 );
@@ -648,7 +648,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
648
648
adjust_cutoff_timestamp_for_slop ();
649
649
650
650
for_each_ref (name_ref , & data );
651
- name_tips ();
651
+ name_tips (& string_pool );
652
652
653
653
if (annotate_stdin ) {
654
654
struct strbuf sb = STRBUF_INIT ;
@@ -676,6 +676,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
676
676
always , allow_undefined , data .name_only );
677
677
}
678
678
679
+ UNLEAK (string_pool );
679
680
UNLEAK (revs );
680
681
return 0 ;
681
682
}
0 commit comments