@@ -38,6 +38,7 @@ static const char * const cherry_pick_usage[] = {
38
38
static int edit , no_replay , no_commit , mainline , signoff ;
39
39
static enum { REVERT , CHERRY_PICK } action ;
40
40
static struct commit * commit ;
41
+ static const char * commit_name ;
41
42
static int allow_rerere_auto ;
42
43
43
44
static const char * me ;
@@ -49,7 +50,6 @@ static void parse_args(int argc, const char **argv)
49
50
const char * const * usage_str =
50
51
action == REVERT ? revert_usage : cherry_pick_usage ;
51
52
unsigned char sha1 [20 ];
52
- const char * arg ;
53
53
int noop ;
54
54
struct option options [] = {
55
55
OPT_BOOLEAN ('n' , "no-commit" , & no_commit , "don't automatically commit" ),
@@ -64,19 +64,13 @@ static void parse_args(int argc, const char **argv)
64
64
65
65
if (parse_options (argc , argv , NULL , options , usage_str , 0 ) != 1 )
66
66
usage_with_options (usage_str , options );
67
- arg = argv [0 ];
68
67
69
- if (get_sha1 (arg , sha1 ))
70
- die ("Cannot find '%s'" , arg );
71
- commit = (struct commit * )parse_object (sha1 );
68
+ commit_name = argv [0 ];
69
+ if (get_sha1 (commit_name , sha1 ))
70
+ die ("Cannot find '%s'" , commit_name );
71
+ commit = lookup_commit_reference (sha1 );
72
72
if (!commit )
73
- die ("Could not find %s" , sha1_to_hex (sha1 ));
74
- if (commit -> object .type == OBJ_TAG ) {
75
- commit = (struct commit * )
76
- deref_tag ((struct object * )commit , arg , strlen (arg ));
77
- }
78
- if (commit -> object .type != OBJ_COMMIT )
79
- die ("'%s' does not point to a commit" , arg );
73
+ exit (1 );
80
74
}
81
75
82
76
static char * get_oneline (const char * message )
@@ -204,25 +198,27 @@ static void set_author_ident_env(const char *message)
204
198
sha1_to_hex (commit -> object .sha1 ));
205
199
}
206
200
207
- static char * help_msg (const unsigned char * sha1 )
201
+ static char * help_msg (const char * name )
208
202
{
209
- static char helpbuf [ 1024 ] ;
203
+ struct strbuf helpbuf = STRBUF_INIT ;
210
204
char * msg = getenv ("GIT_CHERRY_PICK_HELP" );
211
205
212
206
if (msg )
213
207
return msg ;
214
208
215
- strcpy ( helpbuf , " After resolving the conflicts,\n"
216
- "mark the corrected paths with 'git add <paths>' "
217
- "or 'git rm <paths>' and commit the result. " );
209
+ strbuf_addstr ( & helpbuf , " After resolving the conflicts,\n"
210
+ "mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n "
211
+ " and commit the result" );
218
212
219
213
if (action == CHERRY_PICK ) {
220
- sprintf ( helpbuf + strlen ( helpbuf ),
221
- "\nWhen commiting, use the option "
222
- "'-c %s' to retain authorship and message. " ,
223
- find_unique_abbrev ( sha1 , DEFAULT_ABBREV ) );
214
+ strbuf_addf ( & helpbuf , " with: \n"
215
+ "\n "
216
+ " git commit -c %s\n " ,
217
+ name );
224
218
}
225
- return helpbuf ;
219
+ else
220
+ strbuf_addch (& helpbuf , '.' );
221
+ return strbuf_detach (& helpbuf , NULL );
226
222
}
227
223
228
224
static struct tree * empty_tree (void )
@@ -409,7 +405,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
409
405
if (commit_lock_file (& msg_file ) < 0 )
410
406
die ("Error wrapping up %s" , defmsg );
411
407
fprintf (stderr , "Automatic %s failed.%s\n" ,
412
- me , help_msg (commit -> object . sha1 ));
408
+ me , help_msg (commit_name ));
413
409
rerere (allow_rerere_auto );
414
410
exit (1 );
415
411
}
0 commit comments