28
28
#include "worktree.h"
29
29
#include "write-or-die.h"
30
30
31
- static char * separator = "\n" ;
31
+ static const char * separator = "\n" ;
32
32
static const char * const git_notes_usage [] = {
33
33
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>]" ),
35
35
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>]" ),
37
37
N_ ("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]" ),
38
38
N_ ("git notes [--ref <notes-ref>] show [<object>]" ),
39
39
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)
239
239
240
240
static void append_separator (struct strbuf * message )
241
241
{
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' )
244
247
strbuf_addstr (message , separator );
245
248
else
246
249
strbuf_addf (message , "%s%s" , separator , "\n" );
@@ -249,8 +252,8 @@ static void append_separator(struct strbuf *message)
249
252
static void concat_messages (struct note_data * d )
250
253
{
251
254
struct strbuf msg = STRBUF_INIT ;
252
-
253
255
size_t i ;
256
+
254
257
for (i = 0 ; i < d -> msg_nr ; i ++ ) {
255
258
if (d -> buf .len )
256
259
append_separator (& d -> buf );
@@ -341,6 +344,16 @@ static int parse_reedit_arg(const struct option *opt, const char *arg, int unset
341
344
return parse_reuse_arg (opt , arg , unset );
342
345
}
343
346
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
+
344
357
static int notes_copy_from_stdin (int force , const char * rewrite_cmd )
345
358
{
346
359
struct strbuf buf = STRBUF_INIT ;
@@ -481,8 +494,10 @@ static int add(int argc, const char **argv, const char *prefix)
481
494
OPT_BOOL (0 , "allow-empty" , & allow_empty ,
482
495
N_ ("allow storing empty note" )),
483
496
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 ),
486
501
OPT_BOOL (0 , "stripspace" , & d .stripspace ,
487
502
N_ ("remove unnecessary whitespace" )),
488
503
OPT_END ()
@@ -654,8 +669,10 @@ static int append_edit(int argc, const char **argv, const char *prefix)
654
669
parse_reuse_arg ),
655
670
OPT_BOOL (0 , "allow-empty" , & allow_empty ,
656
671
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 ),
659
676
OPT_BOOL (0 , "stripspace" , & d .stripspace ,
660
677
N_ ("remove unnecessary whitespace" )),
661
678
OPT_END ()
0 commit comments