@@ -2079,6 +2079,18 @@ const char *todo_item_get_arg(struct todo_list *todo_list,
2079
2079
return todo_list -> buf .buf + item -> arg_offset ;
2080
2080
}
2081
2081
2082
+ static int is_command (enum todo_command command , const char * * bol )
2083
+ {
2084
+ const char * str = todo_command_info [command ].str ;
2085
+ const char nick = todo_command_info [command ].c ;
2086
+ const char * p = * bol + 1 ;
2087
+
2088
+ return skip_prefix (* bol , str , bol ) ||
2089
+ ((nick && * * bol == nick ) &&
2090
+ (* p == ' ' || * p == '\t' || * p == '\n' || * p == '\r' || !* p ) &&
2091
+ (* bol = p ));
2092
+ }
2093
+
2082
2094
static int parse_insn_line (struct repository * r , struct todo_item * item ,
2083
2095
const char * buf , const char * bol , char * eol )
2084
2096
{
@@ -2100,12 +2112,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2100
2112
}
2101
2113
2102
2114
for (i = 0 ; i < TODO_COMMENT ; i ++ )
2103
- if (skip_prefix (bol , todo_command_info [i ].str , & bol )) {
2104
- item -> command = i ;
2105
- break ;
2106
- } else if ((bol + 1 == eol || bol [1 ] == ' ' ) &&
2107
- * bol == todo_command_info [i ].c ) {
2108
- bol ++ ;
2115
+ if (is_command (i , & bol )) {
2109
2116
item -> command = i ;
2110
2117
break ;
2111
2118
}
@@ -2173,34 +2180,26 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2173
2180
2174
2181
int sequencer_get_last_command (struct repository * r , enum replay_action * action )
2175
2182
{
2176
- struct todo_item item ;
2177
- char * eol ;
2178
- const char * todo_file ;
2183
+ const char * todo_file , * bol ;
2179
2184
struct strbuf buf = STRBUF_INIT ;
2180
- int ret = -1 ;
2185
+ int ret = 0 ;
2181
2186
2182
2187
todo_file = git_path_todo_file ();
2183
2188
if (strbuf_read_file (& buf , todo_file , 0 ) < 0 ) {
2184
- if (errno == ENOENT )
2189
+ if (errno == ENOENT || errno == ENOTDIR )
2185
2190
return -1 ;
2186
2191
else
2187
2192
return error_errno ("unable to open '%s'" , todo_file );
2188
2193
}
2189
- eol = strchrnul (buf .buf , '\n' );
2190
- if (buf .buf != eol && eol [-1 ] == '\r' )
2191
- eol -- ; /* strip Carriage Return */
2192
- if (parse_insn_line (r , & item , buf .buf , buf .buf , eol ))
2193
- goto fail ;
2194
- if (item .command == TODO_PICK )
2194
+ bol = buf .buf + strspn (buf .buf , " \t\r\n" );
2195
+ if (is_command (TODO_PICK , & bol ) && (* bol == ' ' || * bol == '\t' ))
2195
2196
* action = REPLAY_PICK ;
2196
- else if (item .command == TODO_REVERT )
2197
+ else if (is_command (TODO_REVERT , & bol ) &&
2198
+ (* bol == ' ' || * bol == '\t' ))
2197
2199
* action = REPLAY_REVERT ;
2198
2200
else
2199
- goto fail ;
2200
-
2201
- ret = 0 ;
2201
+ ret = -1 ;
2202
2202
2203
- fail :
2204
2203
strbuf_release (& buf );
2205
2204
2206
2205
return ret ;
0 commit comments