@@ -1999,8 +1999,14 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
1999
1999
return todo_list -> items + todo_list -> nr ++ ;
2000
2000
}
2001
2001
2002
+ const char * todo_item_get_arg (struct todo_list * todo_list ,
2003
+ struct todo_item * item )
2004
+ {
2005
+ return todo_list -> buf .buf + item -> arg_offset ;
2006
+ }
2007
+
2002
2008
static int parse_insn_line (struct repository * r , struct todo_item * item ,
2003
- const char * bol , char * eol )
2009
+ const char * buf , const char * bol , char * eol )
2004
2010
{
2005
2011
struct object_id commit_oid ;
2006
2012
char * end_of_object_name ;
@@ -2014,7 +2020,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2014
2020
if (bol == eol || * bol == '\r' || * bol == comment_line_char ) {
2015
2021
item -> command = TODO_COMMENT ;
2016
2022
item -> commit = NULL ;
2017
- item -> arg = bol ;
2023
+ item -> arg_offset = bol - buf ;
2018
2024
item -> arg_len = eol - bol ;
2019
2025
return 0 ;
2020
2026
}
@@ -2041,7 +2047,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2041
2047
return error (_ ("%s does not accept arguments: '%s'" ),
2042
2048
command_to_string (item -> command ), bol );
2043
2049
item -> commit = NULL ;
2044
- item -> arg = bol ;
2050
+ item -> arg_offset = bol - buf ;
2045
2051
item -> arg_len = eol - bol ;
2046
2052
return 0 ;
2047
2053
}
@@ -2053,7 +2059,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2053
2059
if (item -> command == TODO_EXEC || item -> command == TODO_LABEL ||
2054
2060
item -> command == TODO_RESET ) {
2055
2061
item -> commit = NULL ;
2056
- item -> arg = bol ;
2062
+ item -> arg_offset = bol - buf ;
2057
2063
item -> arg_len = (int )(eol - bol );
2058
2064
return 0 ;
2059
2065
}
@@ -2067,7 +2073,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2067
2073
} else {
2068
2074
item -> flags |= TODO_EDIT_MERGE_MSG ;
2069
2075
item -> commit = NULL ;
2070
- item -> arg = bol ;
2076
+ item -> arg_offset = bol - buf ;
2071
2077
item -> arg_len = (int )(eol - bol );
2072
2078
return 0 ;
2073
2079
}
@@ -2079,8 +2085,9 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2079
2085
status = get_oid (bol , & commit_oid );
2080
2086
* end_of_object_name = saved ;
2081
2087
2082
- item -> arg = end_of_object_name + strspn (end_of_object_name , " \t" );
2083
- item -> arg_len = (int )(eol - item -> arg );
2088
+ bol = end_of_object_name + strspn (end_of_object_name , " \t" );
2089
+ item -> arg_offset = bol - buf ;
2090
+ item -> arg_len = (int )(eol - bol );
2084
2091
2085
2092
if (status < 0 )
2086
2093
return -1 ;
@@ -2108,11 +2115,11 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
2108
2115
2109
2116
item = append_new_todo (todo_list );
2110
2117
item -> offset_in_buf = p - todo_list -> buf .buf ;
2111
- if (parse_insn_line (r , item , p , eol )) {
2118
+ if (parse_insn_line (r , item , buf , p , eol )) {
2112
2119
res = error (_ ("invalid line %d: %.*s" ),
2113
2120
i , (int )(eol - p ), p );
2114
2121
item -> command = TODO_COMMENT + 1 ;
2115
- item -> arg = p ;
2122
+ item -> arg_offset = p - buf ;
2116
2123
item -> arg_len = (int )(eol - p );
2117
2124
item -> commit = NULL ;
2118
2125
}
@@ -2452,7 +2459,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
2452
2459
2453
2460
item -> command = command ;
2454
2461
item -> commit = commit ;
2455
- item -> arg = NULL ;
2462
+ item -> arg_offset = 0 ;
2456
2463
item -> arg_len = 0 ;
2457
2464
item -> offset_in_buf = todo_list -> buf .len ;
2458
2465
subject_len = find_commit_subject (commit_buffer , & subject );
@@ -3491,6 +3498,8 @@ static int pick_commits(struct repository *r,
3491
3498
3492
3499
while (todo_list -> current < todo_list -> nr ) {
3493
3500
struct todo_item * item = todo_list -> items + todo_list -> current ;
3501
+ const char * arg = todo_item_get_arg (todo_list , item );
3502
+
3494
3503
if (save_todo (todo_list , opts ))
3495
3504
return -1 ;
3496
3505
if (is_rebase_i (opts )) {
@@ -3542,10 +3551,9 @@ static int pick_commits(struct repository *r,
3542
3551
fprintf (stderr ,
3543
3552
_ ("Stopped at %s... %.*s\n" ),
3544
3553
short_commit_name (commit ),
3545
- item -> arg_len , item -> arg );
3554
+ item -> arg_len , arg );
3546
3555
return error_with_patch (r , commit ,
3547
- item -> arg , item -> arg_len , opts , res ,
3548
- !res );
3556
+ arg , item -> arg_len , opts , res , !res );
3549
3557
}
3550
3558
if (is_rebase_i (opts ) && !res )
3551
3559
record_in_rewritten (& item -> commit -> object .oid ,
@@ -3554,7 +3562,7 @@ static int pick_commits(struct repository *r,
3554
3562
if (res == 1 )
3555
3563
intend_to_amend ();
3556
3564
return error_failed_squash (r , item -> commit , opts ,
3557
- item -> arg_len , item -> arg );
3565
+ item -> arg_len , arg );
3558
3566
} else if (res && is_rebase_i (opts ) && item -> commit ) {
3559
3567
int to_amend = 0 ;
3560
3568
struct object_id oid ;
@@ -3573,16 +3581,16 @@ static int pick_commits(struct repository *r,
3573
3581
to_amend = 1 ;
3574
3582
3575
3583
return res | error_with_patch (r , item -> commit ,
3576
- item -> arg , item -> arg_len , opts ,
3584
+ arg , item -> arg_len , opts ,
3577
3585
res , to_amend );
3578
3586
}
3579
3587
} else if (item -> command == TODO_EXEC ) {
3580
- char * end_of_arg = (char * )(item -> arg + item -> arg_len );
3588
+ char * end_of_arg = (char * )(arg + item -> arg_len );
3581
3589
int saved = * end_of_arg ;
3582
3590
struct stat st ;
3583
3591
3584
3592
* end_of_arg = '\0' ;
3585
- res = do_exec (r , item -> arg );
3593
+ res = do_exec (r , arg );
3586
3594
* end_of_arg = saved ;
3587
3595
3588
3596
/* Reread the todo file if it has changed. */
@@ -3599,14 +3607,14 @@ static int pick_commits(struct repository *r,
3599
3607
todo_list -> current = -1 ;
3600
3608
}
3601
3609
} else if (item -> command == TODO_LABEL ) {
3602
- if ((res = do_label (r , item -> arg , item -> arg_len )))
3610
+ if ((res = do_label (r , arg , item -> arg_len )))
3603
3611
reschedule = 1 ;
3604
3612
} else if (item -> command == TODO_RESET ) {
3605
- if ((res = do_reset (r , item -> arg , item -> arg_len , opts )))
3613
+ if ((res = do_reset (r , arg , item -> arg_len , opts )))
3606
3614
reschedule = 1 ;
3607
3615
} else if (item -> command == TODO_MERGE ) {
3608
3616
if ((res = do_merge (r , item -> commit ,
3609
- item -> arg , item -> arg_len ,
3617
+ arg , item -> arg_len ,
3610
3618
item -> flags , opts )) < 0 )
3611
3619
reschedule = 1 ;
3612
3620
else if (item -> commit )
@@ -3615,9 +3623,8 @@ static int pick_commits(struct repository *r,
3615
3623
if (res > 0 )
3616
3624
/* failed with merge conflicts */
3617
3625
return error_with_patch (r , item -> commit ,
3618
- item -> arg ,
3619
- item -> arg_len , opts ,
3620
- res , 0 );
3626
+ arg , item -> arg_len ,
3627
+ opts , res , 0 );
3621
3628
} else if (!is_noop (item -> command ))
3622
3629
return error (_ ("unknown command %d" ), item -> command );
3623
3630
@@ -3632,9 +3639,8 @@ static int pick_commits(struct repository *r,
3632
3639
if (item -> commit )
3633
3640
return error_with_patch (r ,
3634
3641
item -> commit ,
3635
- item -> arg ,
3636
- item -> arg_len , opts ,
3637
- res , 0 );
3642
+ arg , item -> arg_len ,
3643
+ opts , res , 0 );
3638
3644
}
3639
3645
3640
3646
todo_list -> current ++ ;
@@ -4575,7 +4581,8 @@ int transform_todos(struct repository *r, unsigned flags)
4575
4581
for (item = todo_list .items , i = 0 ; i < todo_list .nr ; i ++ , item ++ ) {
4576
4582
/* if the item is not a command write it and continue */
4577
4583
if (item -> command >= TODO_COMMENT ) {
4578
- strbuf_addf (& buf , "%.*s\n" , item -> arg_len , item -> arg );
4584
+ strbuf_addf (& buf , "%.*s\n" , item -> arg_len ,
4585
+ todo_item_get_arg (& todo_list , item ));
4579
4586
continue ;
4580
4587
}
4581
4588
@@ -4605,7 +4612,8 @@ int transform_todos(struct repository *r, unsigned flags)
4605
4612
if (!item -> arg_len )
4606
4613
strbuf_addch (& buf , '\n' );
4607
4614
else
4608
- strbuf_addf (& buf , " %.*s\n" , item -> arg_len , item -> arg );
4615
+ strbuf_addf (& buf , " %.*s\n" , item -> arg_len ,
4616
+ todo_item_get_arg (& todo_list , item ));
4609
4617
}
4610
4618
4611
4619
i = write_message (buf .buf , buf .len , todo_file , 0 );
@@ -4681,7 +4689,8 @@ int check_todo_list(struct repository *r)
4681
4689
if (commit && !* commit_seen_at (& commit_seen , commit )) {
4682
4690
strbuf_addf (& missing , " - %s %.*s\n" ,
4683
4691
short_commit_name (commit ),
4684
- item -> arg_len , item -> arg );
4692
+ item -> arg_len ,
4693
+ todo_item_get_arg (& todo_list , item ));
4685
4694
* commit_seen_at (& commit_seen , commit ) = 1 ;
4686
4695
}
4687
4696
}
0 commit comments