2828#include "worktree.h"
2929#include "write-or-die.h"
3030
31- static char * separator = "\n" ;
31+ static const char * separator = "\n" ;
3232static const char * const git_notes_usage [] = {
3333 N_ ("git notes [--ref <notes-ref>] [list [<object>]]" ),
34- N_ ("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--separator=<paragraph-break>] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]" ),
34+ N_ ("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-] separator|--separator =<paragraph-break>] [--[no-]stripspace ] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]" ),
3535 N_ ("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>" ),
36- N_ ("git notes [--ref <notes-ref>] append [--allow-empty] [--separator=<paragraph-break>] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]" ),
36+ N_ ("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-] separator|--separator =<paragraph-break>] [--[no-]stripspace ] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]" ),
3737 N_ ("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]" ),
3838 N_ ("git notes [--ref <notes-ref>] show [<object>]" ),
3939 N_ ("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>" ),
@@ -239,8 +239,11 @@ static void write_note_data(struct note_data *d, struct object_id *oid)
239239
240240static void append_separator (struct strbuf * message )
241241{
242- size_t sep_len = strlen (separator );
243- if (sep_len && separator [sep_len - 1 ] == '\n' )
242+ size_t sep_len = 0 ;
243+
244+ if (!separator )
245+ return ;
246+ else if ((sep_len = strlen (separator )) && separator [sep_len - 1 ] == '\n' )
244247 strbuf_addstr (message , separator );
245248 else
246249 strbuf_addf (message , "%s%s" , separator , "\n" );
@@ -249,8 +252,8 @@ static void append_separator(struct strbuf *message)
249252static void concat_messages (struct note_data * d )
250253{
251254 struct strbuf msg = STRBUF_INIT ;
252-
253255 size_t i ;
256+
254257 for (i = 0 ; i < d -> msg_nr ; i ++ ) {
255258 if (d -> buf .len )
256259 append_separator (& d -> buf );
@@ -341,6 +344,16 @@ static int parse_reedit_arg(const struct option *opt, const char *arg, int unset
341344 return parse_reuse_arg (opt , arg , unset );
342345}
343346
347+ static int parse_separator_arg (const struct option * opt , const char * arg ,
348+ int unset )
349+ {
350+ if (unset )
351+ * (const char * * )opt -> value = NULL ;
352+ else
353+ * (const char * * )opt -> value = arg ? arg : "\n" ;
354+ return 0 ;
355+ }
356+
344357static int notes_copy_from_stdin (int force , const char * rewrite_cmd )
345358{
346359 struct strbuf buf = STRBUF_INIT ;
@@ -481,8 +494,10 @@ static int add(int argc, const char **argv, const char *prefix)
481494 OPT_BOOL (0 , "allow-empty" , & allow_empty ,
482495 N_ ("allow storing empty note" )),
483496 OPT__FORCE (& force , N_ ("replace existing notes" ), PARSE_OPT_NOCOMPLETE ),
484- OPT_STRING (0 , "separator" , & separator , N_ ("separator" ),
485- N_ ("insert <paragraph-break> between paragraphs" )),
497+ OPT_CALLBACK_F (0 , "separator" , & separator ,
498+ N_ ("<paragraph-break>" ),
499+ N_ ("insert <paragraph-break> between paragraphs" ),
500+ PARSE_OPT_OPTARG , parse_separator_arg ),
486501 OPT_BOOL (0 , "stripspace" , & d .stripspace ,
487502 N_ ("remove unnecessary whitespace" )),
488503 OPT_END ()
@@ -654,8 +669,10 @@ static int append_edit(int argc, const char **argv, const char *prefix)
654669 parse_reuse_arg ),
655670 OPT_BOOL (0 , "allow-empty" , & allow_empty ,
656671 N_ ("allow storing empty note" )),
657- OPT_STRING (0 , "separator" , & separator , N_ ("separator" ),
658- N_ ("insert <paragraph-break> between paragraphs" )),
672+ OPT_CALLBACK_F (0 , "separator" , & separator ,
673+ N_ ("<paragraph-break>" ),
674+ N_ ("insert <paragraph-break> between paragraphs" ),
675+ PARSE_OPT_OPTARG , parse_separator_arg ),
659676 OPT_BOOL (0 , "stripspace" , & d .stripspace ,
660677 N_ ("remove unnecessary whitespace" )),
661678 OPT_END ()
0 commit comments