| 2919 | } |
| 2920 | |
| 2921 | char *git_config_prepare_comment_string(const char *comment) |
| 2922 | { |
| 2923 | size_t leading_blanks; |
| 2924 | char *prepared; |
| 2925 | |
| 2926 | if (!comment) |
| 2927 | return NULL; |
| 2928 | |
| 2929 | if (strchr(comment, '\n')) |
| 2930 | die(_("no multi-line comment allowed: '%s'"), comment); |
| 2931 | |
| 2932 | /* |
| 2933 | * If it begins with one or more leading whitespace characters |
| 2934 | * followed by '#", the comment string is used as-is. |
| 2935 | * |
| 2936 | * If it begins with '#', a SP is inserted between the comment |
| 2937 | * and the value the comment is about. |
| 2938 | * |
| 2939 | * Otherwise, the value is followed by a SP followed by '#' |
| 2940 | * followed by SP and then the comment string comes. |
| 2941 | */ |
| 2942 | |
| 2943 | leading_blanks = strspn(comment, " \t"); |
| 2944 | if (leading_blanks && comment[leading_blanks] == '#') |
| 2945 | prepared = xstrdup(comment); /* use it as-is */ |
| 2946 | else if (comment[0] == '#') |
| 2947 | prepared = xstrfmt(" %s", comment); |
| 2948 | else |
| 2949 | prepared = xstrfmt(" # %s", comment); |
| 2950 | |
| 2951 | return prepared; |
| 2952 | } |
| 2953 | |
| 2954 | static void validate_comment_string(const char *comment) |
| 2955 | { |
no test coverage detected