@@ -81,6 +81,11 @@ enum signoff_type {
8181 SIGNOFF_EXPLICIT /* --signoff was set on the command-line */
8282};
8383
84+ enum show_patch_type {
85+ SHOW_PATCH_RAW = 0 ,
86+ SHOW_PATCH_DIFF = 1 ,
87+ };
88+
8489struct am_state {
8590 /* state directory path */
8691 char * dir ;
@@ -1763,7 +1768,7 @@ static void am_run(struct am_state *state, int resume)
17631768 linelen (state -> msg ), state -> msg );
17641769
17651770 if (advice_amworkdir )
1766- advise (_ ("Use 'git am --show-current-patch' to see the failed patch" ));
1771+ advise (_ ("Use 'git am --show-current-patch=diff ' to see the failed patch" ));
17671772
17681773 die_user_resolve (state );
17691774 }
@@ -2061,7 +2066,7 @@ static void am_abort(struct am_state *state)
20612066 am_destroy (state );
20622067}
20632068
2064- static int show_patch (struct am_state * state )
2069+ static int show_patch (struct am_state * state , enum show_patch_type sub_mode )
20652070{
20662071 struct strbuf sb = STRBUF_INIT ;
20672072 const char * patch_path ;
@@ -2078,7 +2083,17 @@ static int show_patch(struct am_state *state)
20782083 return ret ;
20792084 }
20802085
2081- patch_path = am_path (state , msgnum (state ));
2086+ switch (sub_mode ) {
2087+ case SHOW_PATCH_RAW :
2088+ patch_path = am_path (state , msgnum (state ));
2089+ break ;
2090+ case SHOW_PATCH_DIFF :
2091+ patch_path = am_path (state , "patch" );
2092+ break ;
2093+ default :
2094+ BUG ("invalid mode for --show-current-patch" );
2095+ }
2096+
20822097 len = strbuf_read_file (& sb , patch_path , 0 );
20832098 if (len < 0 )
20842099 die_errno (_ ("failed to read '%s'" ), patch_path );
@@ -2118,7 +2133,7 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
21182133 return 0 ;
21192134}
21202135
2121- enum resume_mode {
2136+ enum resume_type {
21222137 RESUME_FALSE = 0 ,
21232138 RESUME_APPLY ,
21242139 RESUME_RESOLVED ,
@@ -2128,6 +2143,45 @@ enum resume_mode {
21282143 RESUME_SHOW_PATCH
21292144};
21302145
2146+ struct resume_mode {
2147+ enum resume_type mode ;
2148+ enum show_patch_type sub_mode ;
2149+ };
2150+
2151+ static int parse_opt_show_current_patch (const struct option * opt , const char * arg , int unset )
2152+ {
2153+ int * opt_value = opt -> value ;
2154+ struct resume_mode * resume = container_of (opt_value , struct resume_mode , mode );
2155+
2156+ /*
2157+ * Please update $__git_showcurrentpatch in git-completion.bash
2158+ * when you add new options
2159+ */
2160+ const char * valid_modes [] = {
2161+ [SHOW_PATCH_DIFF ] = "diff" ,
2162+ [SHOW_PATCH_RAW ] = "raw"
2163+ };
2164+ int new_value = SHOW_PATCH_RAW ;
2165+
2166+ if (arg ) {
2167+ for (new_value = 0 ; new_value < ARRAY_SIZE (valid_modes ); new_value ++ ) {
2168+ if (!strcmp (arg , valid_modes [new_value ]))
2169+ break ;
2170+ }
2171+ if (new_value >= ARRAY_SIZE (valid_modes ))
2172+ return error (_ ("Invalid value for --show-current-patch: %s" ), arg );
2173+ }
2174+
2175+ if (resume -> mode == RESUME_SHOW_PATCH && new_value != resume -> sub_mode )
2176+ return error (_ ("--show-current-patch=%s is incompatible with "
2177+ "--show-current-patch=%s" ),
2178+ arg , valid_modes [resume -> sub_mode ]);
2179+
2180+ resume -> mode = RESUME_SHOW_PATCH ;
2181+ resume -> sub_mode = new_value ;
2182+ return 0 ;
2183+ }
2184+
21312185static int git_am_config (const char * k , const char * v , void * cb )
21322186{
21332187 int status ;
@@ -2145,7 +2199,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
21452199 int binary = -1 ;
21462200 int keep_cr = -1 ;
21472201 int patch_format = PATCH_FORMAT_UNKNOWN ;
2148- enum resume_mode resume = RESUME_FALSE ;
2202+ struct resume_mode resume = { . mode = RESUME_FALSE } ;
21492203 int in_progress ;
21502204 int ret = 0 ;
21512205
@@ -2214,24 +2268,26 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22142268 PARSE_OPT_NOARG ),
22152269 OPT_STRING (0 , "resolvemsg" , & state .resolvemsg , NULL ,
22162270 N_ ("override error message when patch failure occurs" )),
2217- OPT_CMDMODE (0 , "continue" , & resume ,
2271+ OPT_CMDMODE (0 , "continue" , & resume . mode ,
22182272 N_ ("continue applying patches after resolving a conflict" ),
22192273 RESUME_RESOLVED ),
2220- OPT_CMDMODE ('r' , "resolved" , & resume ,
2274+ OPT_CMDMODE ('r' , "resolved" , & resume . mode ,
22212275 N_ ("synonyms for --continue" ),
22222276 RESUME_RESOLVED ),
2223- OPT_CMDMODE (0 , "skip" , & resume ,
2277+ OPT_CMDMODE (0 , "skip" , & resume . mode ,
22242278 N_ ("skip the current patch" ),
22252279 RESUME_SKIP ),
2226- OPT_CMDMODE (0 , "abort" , & resume ,
2280+ OPT_CMDMODE (0 , "abort" , & resume . mode ,
22272281 N_ ("restore the original branch and abort the patching operation." ),
22282282 RESUME_ABORT ),
2229- OPT_CMDMODE (0 , "quit" , & resume ,
2283+ OPT_CMDMODE (0 , "quit" , & resume . mode ,
22302284 N_ ("abort the patching operation but keep HEAD where it is." ),
22312285 RESUME_QUIT ),
2232- OPT_CMDMODE (0 , "show-current-patch" , & resume ,
2233- N_ ("show the patch being applied." ),
2234- RESUME_SHOW_PATCH ),
2286+ { OPTION_CALLBACK , 0 , "show-current-patch" , & resume .mode ,
2287+ "(diff|raw)" ,
2288+ N_ ("show the patch being applied" ),
2289+ PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP ,
2290+ parse_opt_show_current_patch , RESUME_SHOW_PATCH },
22352291 OPT_BOOL (0 , "committer-date-is-author-date" ,
22362292 & state .committer_date_is_author_date ,
22372293 N_ ("lie about committer date" )),
@@ -2281,12 +2337,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22812337 * intend to feed us a patch but wanted to continue
22822338 * unattended.
22832339 */
2284- if (argc || (resume == RESUME_FALSE && !isatty (0 )))
2340+ if (argc || (resume . mode == RESUME_FALSE && !isatty (0 )))
22852341 die (_ ("previous rebase directory %s still exists but mbox given." ),
22862342 state .dir );
22872343
2288- if (resume == RESUME_FALSE )
2289- resume = RESUME_APPLY ;
2344+ if (resume . mode == RESUME_FALSE )
2345+ resume . mode = RESUME_APPLY ;
22902346
22912347 if (state .signoff == SIGNOFF_EXPLICIT )
22922348 am_append_signoff (& state );
@@ -2300,7 +2356,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23002356 * stray directories.
23012357 */
23022358 if (file_exists (state .dir ) && !state .rebasing ) {
2303- if (resume == RESUME_ABORT || resume == RESUME_QUIT ) {
2359+ if (resume . mode == RESUME_ABORT || resume . mode == RESUME_QUIT ) {
23042360 am_destroy (& state );
23052361 am_state_release (& state );
23062362 return 0 ;
@@ -2311,7 +2367,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23112367 state .dir );
23122368 }
23132369
2314- if (resume )
2370+ if (resume . mode )
23152371 die (_ ("Resolve operation not in progress, we are not resuming." ));
23162372
23172373 for (i = 0 ; i < argc ; i ++ ) {
@@ -2329,7 +2385,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23292385 argv_array_clear (& paths );
23302386 }
23312387
2332- switch (resume ) {
2388+ switch (resume . mode ) {
23332389 case RESUME_FALSE :
23342390 am_run (& state , 0 );
23352391 break ;
@@ -2350,7 +2406,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23502406 am_destroy (& state );
23512407 break ;
23522408 case RESUME_SHOW_PATCH :
2353- ret = show_patch (& state );
2409+ ret = show_patch (& state , resume . sub_mode );
23542410 break ;
23552411 default :
23562412 BUG ("invalid resume value" );
0 commit comments