@@ -270,8 +270,11 @@ static int parse_key_value_squoted(char *buf, struct string_list *list)
270
270
struct string_list_item * item ;
271
271
char * np ;
272
272
char * cp = strchr (buf , '=' );
273
- if (!cp )
274
- return -1 ;
273
+ if (!cp ) {
274
+ np = strchrnul (buf , '\n' );
275
+ return error (_ ("unable to parse '%.*s'" ),
276
+ (int ) (np - buf ), buf );
277
+ }
275
278
np = strchrnul (cp , '\n' );
276
279
* cp ++ = '\0' ;
277
280
item = string_list_append (list , buf );
@@ -280,7 +283,8 @@ static int parse_key_value_squoted(char *buf, struct string_list *list)
280
283
* np = '\0' ;
281
284
cp = sq_dequote (cp );
282
285
if (!cp )
283
- return -1 ;
286
+ return error (_ ("unable to dequote value of '%s'" ),
287
+ item -> string );
284
288
item -> util = xstrdup (cp );
285
289
}
286
290
return 0 ;
@@ -308,6 +312,7 @@ static int read_author_script(struct am_state *state)
308
312
struct strbuf buf = STRBUF_INIT ;
309
313
struct string_list kv = STRING_LIST_INIT_DUP ;
310
314
int retval = -1 ; /* assume failure */
315
+ int i , name_i = -2 , email_i = -2 , date_i = -2 , err = 0 ;
311
316
int fd ;
312
317
313
318
assert (!state -> author_name );
@@ -326,14 +331,38 @@ static int read_author_script(struct am_state *state)
326
331
if (parse_key_value_squoted (buf .buf , & kv ))
327
332
goto finish ;
328
333
329
- if (kv .nr != 3 ||
330
- strcmp (kv .items [0 ].string , "GIT_AUTHOR_NAME" ) ||
331
- strcmp (kv .items [1 ].string , "GIT_AUTHOR_EMAIL" ) ||
332
- strcmp (kv .items [2 ].string , "GIT_AUTHOR_DATE" ))
334
+ for (i = 0 ; i < kv .nr ; i ++ ) {
335
+ if (!strcmp (kv .items [i ].string , "GIT_AUTHOR_NAME" )) {
336
+ if (name_i != -2 )
337
+ name_i = error (_ ("'GIT_AUTHOR_NAME' already given" ));
338
+ else
339
+ name_i = i ;
340
+ } else if (!strcmp (kv .items [i ].string , "GIT_AUTHOR_EMAIL" )) {
341
+ if (email_i != -2 )
342
+ email_i = error (_ ("'GIT_AUTHOR_EMAIL' already given" ));
343
+ else
344
+ email_i = i ;
345
+ } else if (!strcmp (kv .items [i ].string , "GIT_AUTHOR_DATE" )) {
346
+ if (date_i != -2 )
347
+ date_i = error (_ ("'GIT_AUTHOR_DATE' already given" ));
348
+ else
349
+ date_i = i ;
350
+ } else {
351
+ err = error (_ ("unknown variable '%s'" ),
352
+ kv .items [i ].string );
353
+ }
354
+ }
355
+ if (name_i == -2 )
356
+ error (_ ("missing 'GIT_AUTHOR_NAME'" ));
357
+ if (email_i == -2 )
358
+ error (_ ("missing 'GIT_AUTHOR_EMAIL'" ));
359
+ if (date_i == -2 )
360
+ error (_ ("missing 'GIT_AUTHOR_DATE'" ));
361
+ if (date_i < 0 || email_i < 0 || date_i < 0 || err )
333
362
goto finish ;
334
- state -> author_name = kv .items [0 ].util ;
335
- state -> author_email = kv .items [1 ].util ;
336
- state -> author_date = kv .items [2 ].util ;
363
+ state -> author_name = kv .items [name_i ].util ;
364
+ state -> author_email = kv .items [email_i ].util ;
365
+ state -> author_date = kv .items [date_i ].util ;
337
366
retval = 0 ;
338
367
finish :
339
368
string_list_clear (& kv , !!retval );
0 commit comments