@@ -80,6 +80,9 @@ struct am_state {
80
80
81
81
/* number of digits in patch filename */
82
82
int prec ;
83
+
84
+ /* various operating modes and command line options */
85
+ int quiet ;
83
86
};
84
87
85
88
/**
@@ -116,6 +119,22 @@ static inline const char *am_path(const struct am_state *state, const char *path
116
119
return mkpath ("%s/%s" , state -> dir , path );
117
120
}
118
121
122
+ /**
123
+ * If state->quiet is false, calls fprintf(fp, fmt, ...), and appends a newline
124
+ * at the end.
125
+ */
126
+ static void say (const struct am_state * state , FILE * fp , const char * fmt , ...)
127
+ {
128
+ va_list ap ;
129
+
130
+ va_start (ap , fmt );
131
+ if (!state -> quiet ) {
132
+ vfprintf (fp , fmt , ap );
133
+ putc ('\n' , fp );
134
+ }
135
+ va_end (ap );
136
+ }
137
+
119
138
/**
120
139
* Returns 1 if there is an am session in progress, 0 otherwise.
121
140
*/
@@ -330,6 +349,9 @@ static void am_load(struct am_state *state)
330
349
331
350
read_commit_msg (state );
332
351
352
+ read_state_file (& sb , state , "quiet" , 1 );
353
+ state -> quiet = !strcmp (sb .buf , "t" );
354
+
333
355
strbuf_release (& sb );
334
356
}
335
357
@@ -508,6 +530,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
508
530
die (_ ("Failed to split patches." ));
509
531
}
510
532
533
+ write_file (am_path (state , "quiet" ), 1 , state -> quiet ? "t" : "f" );
534
+
511
535
if (!get_sha1 ("HEAD" , curr_head )) {
512
536
write_file (am_path (state , "abort-safety" ), 1 , "%s" , sha1_to_hex (curr_head ));
513
537
update_ref ("am" , "ORIG_HEAD" , curr_head , NULL , 0 , UPDATE_REFS_DIE_ON_ERR );
@@ -756,7 +780,7 @@ static void do_commit(const struct am_state *state)
756
780
commit_list_insert (lookup_commit (parent ), & parents );
757
781
} else {
758
782
ptr = NULL ;
759
- fprintf_ln ( stderr , _ ("applying to an empty history" ));
783
+ say ( state , stderr , _ ("applying to an empty history" ));
760
784
}
761
785
762
786
author = fmt_ident (state -> author_name , state -> author_email ,
@@ -833,7 +857,7 @@ static void am_run(struct am_state *state, int resume)
833
857
write_commit_msg (state );
834
858
}
835
859
836
- printf_ln ( _ ("Applying: %.*s" ), linelen (state -> msg ), state -> msg );
860
+ say ( state , stdout , _ ("Applying: %.*s" ), linelen (state -> msg ), state -> msg );
837
861
838
862
if (run_apply (state ) < 0 ) {
839
863
int advice_amworkdir = 1 ;
@@ -869,7 +893,7 @@ static void am_resolve(struct am_state *state)
869
893
{
870
894
validate_resume_state (state );
871
895
872
- printf_ln ( _ ("Applying: %.*s" ), linelen (state -> msg ), state -> msg );
896
+ say ( state , stdout , _ ("Applying: %.*s" ), linelen (state -> msg ), state -> msg );
873
897
874
898
if (!index_has_changes (NULL )) {
875
899
printf_ln (_ ("No changes - did you forget to use 'git add'?\n"
@@ -1105,6 +1129,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1105
1129
};
1106
1130
1107
1131
struct option options [] = {
1132
+ OPT__QUIET (& state .quiet , N_ ("be quiet" )),
1108
1133
OPT_CALLBACK (0 , "patch-format" , & patch_format , N_ ("format" ),
1109
1134
N_ ("format the patch(es) are in" ),
1110
1135
parse_opt_patchformat ),
0 commit comments