Git fork

gpg-interface: refactor 'enum sign_mode' parsing

The definition of 'enum sign_mode' as well as its parsing code are in
"builtin/fast-export.c". This was fine because `git fast-export` was the
only command with '--signed-tags=<mode>' or '--signed-commits=<mode>'
options.

In a following commit, we are going to add a similar option to `git
fast-import`, which will be simpler, easier and cleaner if we can reuse
the 'enum sign_mode' defintion and parsing code.

So let's move that definition and parsing code from
"builtin/fast-export.c" to "gpg-interface.{c,h}".

While at it, let's fix a small indentation issue with the arguments of
parse_opt_sign_mode().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Christian Couder and committed by
Junio C Hamano
2f8fd208 4975ec34

+37 -14
+5 -14
builtin/fast-export.c
··· 37 37 NULL 38 38 }; 39 39 40 - enum sign_mode { SIGN_ABORT, SIGN_VERBATIM, SIGN_STRIP, SIGN_WARN_VERBATIM, SIGN_WARN_STRIP }; 41 - 42 40 static int progress; 43 41 static enum sign_mode signed_tag_mode = SIGN_ABORT; 44 42 static enum sign_mode signed_commit_mode = SIGN_STRIP; ··· 59 57 static struct revision_sources revision_sources; 60 58 61 59 static int parse_opt_sign_mode(const struct option *opt, 62 - const char *arg, int unset) 60 + const char *arg, int unset) 63 61 { 64 62 enum sign_mode *val = opt->value; 63 + 65 64 if (unset) 66 65 return 0; 67 - else if (!strcmp(arg, "abort")) 68 - *val = SIGN_ABORT; 69 - else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore")) 70 - *val = SIGN_VERBATIM; 71 - else if (!strcmp(arg, "warn-verbatim") || !strcmp(arg, "warn")) 72 - *val = SIGN_WARN_VERBATIM; 73 - else if (!strcmp(arg, "warn-strip")) 74 - *val = SIGN_WARN_STRIP; 75 - else if (!strcmp(arg, "strip")) 76 - *val = SIGN_STRIP; 77 - else 66 + 67 + if (parse_sign_mode(arg, val)) 78 68 return error("Unknown %s mode: %s", opt->long_name, arg); 69 + 79 70 return 0; 80 71 } 81 72
+17
gpg-interface.c
··· 1125 1125 FREE_AND_NULL(ssh_signing_key_file); 1126 1126 return ret; 1127 1127 } 1128 + 1129 + int parse_sign_mode(const char *arg, enum sign_mode *mode) 1130 + { 1131 + if (!strcmp(arg, "abort")) 1132 + *mode = SIGN_ABORT; 1133 + else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore")) 1134 + *mode = SIGN_VERBATIM; 1135 + else if (!strcmp(arg, "warn-verbatim") || !strcmp(arg, "warn")) 1136 + *mode = SIGN_WARN_VERBATIM; 1137 + else if (!strcmp(arg, "warn-strip")) 1138 + *mode = SIGN_WARN_STRIP; 1139 + else if (!strcmp(arg, "strip")) 1140 + *mode = SIGN_STRIP; 1141 + else 1142 + return -1; 1143 + return 0; 1144 + }
+15
gpg-interface.h
··· 104 104 void print_signature_buffer(const struct signature_check *sigc, 105 105 unsigned flags); 106 106 107 + /* Modes for --signed-tags=<mode> and --signed-commits=<mode> options. */ 108 + enum sign_mode { 109 + SIGN_ABORT, 110 + SIGN_WARN_VERBATIM, 111 + SIGN_VERBATIM, 112 + SIGN_WARN_STRIP, 113 + SIGN_STRIP, 114 + }; 115 + 116 + /* 117 + * Return 0 if `arg` can be parsed into an `enum sign_mode`. Return -1 118 + * otherwise. 119 + */ 120 + int parse_sign_mode(const char *arg, enum sign_mode *mode); 121 + 107 122 #endif