@@ -188,6 +188,8 @@ static int global_argc;
188
188
static const char * * global_argv ;
189
189
static const char * global_prefix ;
190
190
191
+ static enum sign_mode signed_commit_mode = SIGN_VERBATIM ;
192
+
191
193
/* Memory pools */
192
194
static struct mem_pool fi_mem_pool = {
193
195
.block_alloc = 2 * 1024 * 1024 - sizeof (struct mp_block ),
@@ -2752,6 +2754,15 @@ static void parse_one_signature(struct signature_data *sig, const char *v)
2752
2754
parse_data (& sig -> data , 0 , NULL );
2753
2755
}
2754
2756
2757
+ static void discard_one_signature (void )
2758
+ {
2759
+ struct strbuf data = STRBUF_INIT ;
2760
+
2761
+ read_next_command ();
2762
+ parse_data (& data , 0 , NULL );
2763
+ strbuf_release (& data );
2764
+ }
2765
+
2755
2766
static void add_gpgsig_to_commit (struct strbuf * commit_data ,
2756
2767
const char * header ,
2757
2768
struct signature_data * sig )
@@ -2785,6 +2796,22 @@ static void store_signature(struct signature_data *stored_sig,
2785
2796
}
2786
2797
}
2787
2798
2799
+ static void import_one_signature (struct signature_data * sig_sha1 ,
2800
+ struct signature_data * sig_sha256 ,
2801
+ const char * v )
2802
+ {
2803
+ struct signature_data sig = { NULL , NULL , STRBUF_INIT };
2804
+
2805
+ parse_one_signature (& sig , v );
2806
+
2807
+ if (!strcmp (sig .hash_algo , "sha1" ))
2808
+ store_signature (sig_sha1 , & sig , "SHA-1" );
2809
+ else if (!strcmp (sig .hash_algo , "sha256" ))
2810
+ store_signature (sig_sha256 , & sig , "SHA-256" );
2811
+ else
2812
+ die (_ ("parse_one_signature() returned unknown hash algo" ));
2813
+ }
2814
+
2788
2815
static void parse_new_commit (const char * arg )
2789
2816
{
2790
2817
static struct strbuf msg = STRBUF_INIT ;
@@ -2817,19 +2844,32 @@ static void parse_new_commit(const char *arg)
2817
2844
if (!committer )
2818
2845
die ("Expected committer but didn't get one" );
2819
2846
2820
- /* Process signatures (up to 2: one "sha1" and one "sha256") */
2821
2847
while (skip_prefix (command_buf .buf , "gpgsig " , & v )) {
2822
- struct signature_data sig = { NULL , NULL , STRBUF_INIT };
2823
-
2824
- parse_one_signature (& sig , v );
2848
+ switch (signed_commit_mode ) {
2849
+
2850
+ /* First, modes that don't need the signature to be parsed */
2851
+ case SIGN_ABORT :
2852
+ die ("encountered signed commit; use "
2853
+ "--signed-commits=<mode> to handle it" );
2854
+ case SIGN_WARN_STRIP :
2855
+ warning (_ ("stripping a commit signature" ));
2856
+ /* fallthru */
2857
+ case SIGN_STRIP :
2858
+ discard_one_signature ();
2859
+ break ;
2825
2860
2826
- if (!strcmp (sig .hash_algo , "sha1" ))
2827
- store_signature (& sig_sha1 , & sig , "SHA-1" );
2828
- else if (!strcmp (sig .hash_algo , "sha256" ))
2829
- store_signature (& sig_sha256 , & sig , "SHA-256" );
2830
- else
2831
- BUG ("parse_one_signature() returned unknown hash algo" );
2861
+ /* Second, modes that parse the signature */
2862
+ case SIGN_WARN_VERBATIM :
2863
+ warning (_ ("importing a commit signature verbatim" ));
2864
+ /* fallthru */
2865
+ case SIGN_VERBATIM :
2866
+ import_one_signature (& sig_sha1 , & sig_sha256 , v );
2867
+ break ;
2832
2868
2869
+ /* Third, BUG */
2870
+ default :
2871
+ BUG ("invalid signed_commit_mode value %d" , signed_commit_mode );
2872
+ }
2833
2873
read_next_command ();
2834
2874
}
2835
2875
@@ -3501,6 +3541,9 @@ static int parse_one_option(const char *option)
3501
3541
option_active_branches (option );
3502
3542
} else if (skip_prefix (option , "export-pack-edges=" , & option )) {
3503
3543
option_export_pack_edges (option );
3544
+ } else if (skip_prefix (option , "signed-commits=" , & option )) {
3545
+ if (parse_sign_mode (option , & signed_commit_mode ))
3546
+ usagef (_ ("unknown --signed-commits mode '%s'" ), option );
3504
3547
} else if (!strcmp (option , "quiet" )) {
3505
3548
show_stats = 0 ;
3506
3549
quiet = 1 ;
0 commit comments