@@ -151,7 +151,7 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info,
151
151
152
152
static void determine_replay_mode (struct rev_cmdline_info * cmd_info ,
153
153
const char * onto_name ,
154
- const char * * advance_name ,
154
+ char * * advance_name ,
155
155
struct commit * * onto ,
156
156
struct strset * * update_refs )
157
157
{
@@ -174,6 +174,7 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
174
174
* onto = peel_committish (* advance_name );
175
175
if (repo_dwim_ref (the_repository , * advance_name , strlen (* advance_name ),
176
176
& oid , & fullname , 0 ) == 1 ) {
177
+ free (* advance_name );
177
178
* advance_name = fullname ;
178
179
} else {
179
180
die (_ ("argument to --advance must be a reference" ));
@@ -197,6 +198,7 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
197
198
if (negative_refs_complete ) {
198
199
struct hashmap_iter iter ;
199
200
struct strmap_entry * entry ;
201
+ const char * last_key = NULL ;
200
202
201
203
if (rinfo .negative_refexprs == 0 )
202
204
die (_ ("all positive revisions given must be references" ));
@@ -208,8 +210,11 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info,
208
210
/* Only one entry, but we have to loop to get it */
209
211
strset_for_each_entry (& rinfo .negative_refs ,
210
212
& iter , entry ) {
211
- * advance_name = entry -> key ;
213
+ last_key = entry -> key ;
212
214
}
215
+
216
+ free (* advance_name );
217
+ * advance_name = xstrdup_or_null (last_key );
213
218
} else { /* positive_refs_complete */
214
219
if (rinfo .negative_refexprs > 1 )
215
220
die (_ ("cannot implicitly determine correct base for --onto" ));
@@ -271,7 +276,8 @@ static struct commit *pick_regular_commit(struct commit *pickme,
271
276
272
277
int cmd_replay (int argc , const char * * argv , const char * prefix )
273
278
{
274
- const char * advance_name = NULL ;
279
+ const char * advance_name_opt = NULL ;
280
+ char * advance_name = NULL ;
275
281
struct commit * onto = NULL ;
276
282
const char * onto_name = NULL ;
277
283
int contained = 0 ;
@@ -292,7 +298,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
292
298
NULL
293
299
};
294
300
struct option replay_options [] = {
295
- OPT_STRING (0 , "advance" , & advance_name ,
301
+ OPT_STRING (0 , "advance" , & advance_name_opt ,
296
302
N_ ("branch" ),
297
303
N_ ("make replay advance given branch" )),
298
304
OPT_STRING (0 , "onto" , & onto_name ,
@@ -306,14 +312,15 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
306
312
argc = parse_options (argc , argv , prefix , replay_options , replay_usage ,
307
313
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT );
308
314
309
- if (!onto_name && !advance_name ) {
315
+ if (!onto_name && !advance_name_opt ) {
310
316
error (_ ("option --onto or --advance is mandatory" ));
311
317
usage_with_options (replay_usage , replay_options );
312
318
}
313
319
314
- if (advance_name && contained )
320
+ if (advance_name_opt && contained )
315
321
die (_ ("options '%s' and '%s' cannot be used together" ),
316
322
"--advance" , "--contained" );
323
+ advance_name = xstrdup_or_null (advance_name_opt );
317
324
318
325
repo_init_revisions (the_repository , & revs , prefix );
319
326
@@ -441,6 +448,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
441
448
442
449
cleanup :
443
450
release_revisions (& revs );
451
+ free (advance_name );
444
452
445
453
/* Return */
446
454
if (ret < 0 )
0 commit comments