@@ -92,7 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
92
92
static const char note_template [] =
93
93
"\nWrite/edit the notes for the following object:\n" ;
94
94
95
- struct msg_arg {
95
+ struct note_data {
96
96
int given ;
97
97
int use_editor ;
98
98
struct strbuf buf ;
@@ -106,7 +106,7 @@ static int list_each_note(const unsigned char *object_sha1,
106
106
return 0 ;
107
107
}
108
108
109
- static void write_note_data (int fd , const unsigned char * sha1 )
109
+ static void copy_obj_to_fd (int fd , const unsigned char * sha1 )
110
110
{
111
111
unsigned long size ;
112
112
enum object_type type ;
@@ -149,13 +149,13 @@ static void write_commented_object(int fd, const unsigned char *object)
149
149
sha1_to_hex (object ));
150
150
}
151
151
152
- static void create_note (const unsigned char * object , struct msg_arg * msg ,
152
+ static void create_note (const unsigned char * object , struct note_data * d ,
153
153
int append_only , const unsigned char * prev ,
154
154
unsigned char * result )
155
155
{
156
156
char * path = NULL ;
157
157
158
- if (msg -> use_editor || !msg -> given ) {
158
+ if (d -> use_editor || !d -> given ) {
159
159
int fd ;
160
160
struct strbuf buf = STRBUF_INIT ;
161
161
@@ -165,10 +165,10 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
165
165
if (fd < 0 )
166
166
die_errno (_ ("could not create file '%s'" ), path );
167
167
168
- if (msg -> given )
169
- write_or_die (fd , msg -> buf .buf , msg -> buf .len );
168
+ if (d -> given )
169
+ write_or_die (fd , d -> buf .buf , d -> buf .len );
170
170
else if (prev && !append_only )
171
- write_note_data (fd , prev );
171
+ copy_obj_to_fd (fd , prev );
172
172
173
173
strbuf_addch (& buf , '\n' );
174
174
strbuf_add_commented_lines (& buf , note_template , strlen (note_template ));
@@ -179,13 +179,12 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
179
179
180
180
close (fd );
181
181
strbuf_release (& buf );
182
- strbuf_reset (& ( msg -> buf ) );
182
+ strbuf_reset (& d -> buf );
183
183
184
- if (launch_editor (path , & (msg -> buf ), NULL )) {
185
- die (_ ("Please supply the note contents using either -m" \
186
- " or -F option" ));
184
+ if (launch_editor (path , & d -> buf , NULL )) {
185
+ die (_ ("Please supply the note contents using either -m or -F option" ));
187
186
}
188
- stripspace (& ( msg -> buf ) , 1 );
187
+ stripspace (& d -> buf , 1 );
189
188
}
190
189
191
190
if (prev && append_only ) {
@@ -194,20 +193,20 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
194
193
enum object_type type ;
195
194
char * prev_buf = read_sha1_file (prev , & type , & size );
196
195
197
- strbuf_grow (& ( msg -> buf ) , size + 1 );
198
- if (msg -> buf .len && prev_buf && size )
199
- strbuf_insert (& ( msg -> buf ) , 0 , "\n" , 1 );
196
+ strbuf_grow (& d -> buf , size + 1 );
197
+ if (d -> buf .len && prev_buf && size )
198
+ strbuf_insert (& d -> buf , 0 , "\n" , 1 );
200
199
if (prev_buf && size )
201
- strbuf_insert (& ( msg -> buf ) , 0 , prev_buf , size );
200
+ strbuf_insert (& d -> buf , 0 , prev_buf , size );
202
201
free (prev_buf );
203
202
}
204
203
205
- if (!msg -> buf .len ) {
204
+ if (!d -> buf .len ) {
206
205
fprintf (stderr , _ ("Removing note for object %s\n" ),
207
206
sha1_to_hex (object ));
208
207
hashclr (result );
209
208
} else {
210
- if (write_sha1_file (msg -> buf .buf , msg -> buf .len , blob_type , result )) {
209
+ if (write_sha1_file (d -> buf .buf , d -> buf .len , blob_type , result )) {
211
210
error (_ ("unable to write note object" ));
212
211
if (path )
213
212
error (_ ("The note contents have been left in %s" ),
@@ -224,45 +223,45 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
224
223
225
224
static int parse_msg_arg (const struct option * opt , const char * arg , int unset )
226
225
{
227
- struct msg_arg * msg = opt -> value ;
226
+ struct note_data * d = opt -> value ;
228
227
229
- strbuf_grow (& ( msg -> buf ) , strlen (arg ) + 2 );
230
- if (msg -> buf .len )
231
- strbuf_addch (& ( msg -> buf ) , '\n' );
232
- strbuf_addstr (& ( msg -> buf ) , arg );
233
- stripspace (& ( msg -> buf ) , 0 );
228
+ strbuf_grow (& d -> buf , strlen (arg ) + 2 );
229
+ if (d -> buf .len )
230
+ strbuf_addch (& d -> buf , '\n' );
231
+ strbuf_addstr (& d -> buf , arg );
232
+ stripspace (& d -> buf , 0 );
234
233
235
- msg -> given = 1 ;
234
+ d -> given = 1 ;
236
235
return 0 ;
237
236
}
238
237
239
238
static int parse_file_arg (const struct option * opt , const char * arg , int unset )
240
239
{
241
- struct msg_arg * msg = opt -> value ;
240
+ struct note_data * d = opt -> value ;
242
241
243
- if (msg -> buf .len )
244
- strbuf_addch (& ( msg -> buf ) , '\n' );
242
+ if (d -> buf .len )
243
+ strbuf_addch (& d -> buf , '\n' );
245
244
if (!strcmp (arg , "-" )) {
246
- if (strbuf_read (& ( msg -> buf ) , 0 , 1024 ) < 0 )
245
+ if (strbuf_read (& d -> buf , 0 , 1024 ) < 0 )
247
246
die_errno (_ ("cannot read '%s'" ), arg );
248
- } else if (strbuf_read_file (& ( msg -> buf ) , arg , 1024 ) < 0 )
247
+ } else if (strbuf_read_file (& d -> buf , arg , 1024 ) < 0 )
249
248
die_errno (_ ("could not open or read '%s'" ), arg );
250
- stripspace (& ( msg -> buf ) , 0 );
249
+ stripspace (& d -> buf , 0 );
251
250
252
- msg -> given = 1 ;
251
+ d -> given = 1 ;
253
252
return 0 ;
254
253
}
255
254
256
255
static int parse_reuse_arg (const struct option * opt , const char * arg , int unset )
257
256
{
258
- struct msg_arg * msg = opt -> value ;
257
+ struct note_data * d = opt -> value ;
259
258
char * buf ;
260
259
unsigned char object [20 ];
261
260
enum object_type type ;
262
261
unsigned long len ;
263
262
264
- if (msg -> buf .len )
265
- strbuf_addch (& ( msg -> buf ) , '\n' );
263
+ if (d -> buf .len )
264
+ strbuf_addch (& d -> buf , '\n' );
266
265
267
266
if (get_sha1 (arg , object ))
268
267
die (_ ("Failed to resolve '%s' as a valid ref." ), arg );
@@ -274,17 +273,17 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
274
273
free (buf );
275
274
die (_ ("Cannot read note data from non-blob object '%s'." ), arg );
276
275
}
277
- strbuf_add (& ( msg -> buf ) , buf , len );
276
+ strbuf_add (& d -> buf , buf , len );
278
277
free (buf );
279
278
280
- msg -> given = 1 ;
279
+ d -> given = 1 ;
281
280
return 0 ;
282
281
}
283
282
284
283
static int parse_reedit_arg (const struct option * opt , const char * arg , int unset )
285
284
{
286
- struct msg_arg * msg = opt -> value ;
287
- msg -> use_editor = 1 ;
285
+ struct note_data * d = opt -> value ;
286
+ d -> use_editor = 1 ;
288
287
return parse_reuse_arg (opt , arg , unset );
289
288
}
290
289
@@ -403,18 +402,18 @@ static int add(int argc, const char **argv, const char *prefix)
403
402
unsigned char object [20 ], new_note [20 ];
404
403
char logmsg [100 ];
405
404
const unsigned char * note ;
406
- struct msg_arg msg = { 0 , 0 , STRBUF_INIT };
405
+ struct note_data d = { 0 , 0 , STRBUF_INIT };
407
406
struct option options [] = {
408
- { OPTION_CALLBACK , 'm' , "message" , & msg , N_ ("message" ),
407
+ { OPTION_CALLBACK , 'm' , "message" , & d , N_ ("message" ),
409
408
N_ ("note contents as a string" ), PARSE_OPT_NONEG ,
410
409
parse_msg_arg },
411
- { OPTION_CALLBACK , 'F' , "file" , & msg , N_ ("file" ),
410
+ { OPTION_CALLBACK , 'F' , "file" , & d , N_ ("file" ),
412
411
N_ ("note contents in a file" ), PARSE_OPT_NONEG ,
413
412
parse_file_arg },
414
- { OPTION_CALLBACK , 'c' , "reedit-message" , & msg , N_ ("object" ),
413
+ { OPTION_CALLBACK , 'c' , "reedit-message" , & d , N_ ("object" ),
415
414
N_ ("reuse and edit specified note object" ), PARSE_OPT_NONEG ,
416
415
parse_reedit_arg },
417
- { OPTION_CALLBACK , 'C' , "reuse-message" , & msg , N_ ("object" ),
416
+ { OPTION_CALLBACK , 'C' , "reuse-message" , & d , N_ ("object" ),
418
417
N_ ("reuse specified note object" ), PARSE_OPT_NONEG ,
419
418
parse_reuse_arg },
420
419
OPT__FORCE (& force , N_ ("replace existing notes" )),
@@ -439,7 +438,7 @@ static int add(int argc, const char **argv, const char *prefix)
439
438
440
439
if (note ) {
441
440
if (!force ) {
442
- if (!msg .given ) {
441
+ if (!d .given ) {
443
442
/*
444
443
* Redirect to "edit" subcommand.
445
444
*
@@ -460,7 +459,7 @@ static int add(int argc, const char **argv, const char *prefix)
460
459
sha1_to_hex (object ));
461
460
}
462
461
463
- create_note (object , & msg , 0 , note , new_note );
462
+ create_note (object , & d , 0 , note , new_note );
464
463
465
464
if (is_null_sha1 (new_note ))
466
465
remove_note (t , object );
@@ -472,7 +471,7 @@ static int add(int argc, const char **argv, const char *prefix)
472
471
commit_notes (t , logmsg );
473
472
out :
474
473
free_notes (t );
475
- strbuf_release (& ( msg .buf ) );
474
+ strbuf_release (& d .buf );
476
475
return retval ;
477
476
}
478
477
@@ -560,18 +559,18 @@ static int append_edit(int argc, const char **argv, const char *prefix)
560
559
const unsigned char * note ;
561
560
char logmsg [100 ];
562
561
const char * const * usage ;
563
- struct msg_arg msg = { 0 , 0 , STRBUF_INIT };
562
+ struct note_data d = { 0 , 0 , STRBUF_INIT };
564
563
struct option options [] = {
565
- { OPTION_CALLBACK , 'm' , "message" , & msg , N_ ("message" ),
564
+ { OPTION_CALLBACK , 'm' , "message" , & d , N_ ("message" ),
566
565
N_ ("note contents as a string" ), PARSE_OPT_NONEG ,
567
566
parse_msg_arg },
568
- { OPTION_CALLBACK , 'F' , "file" , & msg , N_ ("file" ),
567
+ { OPTION_CALLBACK , 'F' , "file" , & d , N_ ("file" ),
569
568
N_ ("note contents in a file" ), PARSE_OPT_NONEG ,
570
569
parse_file_arg },
571
- { OPTION_CALLBACK , 'c' , "reedit-message" , & msg , N_ ("object" ),
570
+ { OPTION_CALLBACK , 'c' , "reedit-message" , & d , N_ ("object" ),
572
571
N_ ("reuse and edit specified note object" ), PARSE_OPT_NONEG ,
573
572
parse_reedit_arg },
574
- { OPTION_CALLBACK , 'C' , "reuse-message" , & msg , N_ ("object" ),
573
+ { OPTION_CALLBACK , 'C' , "reuse-message" , & d , N_ ("object" ),
575
574
N_ ("reuse specified note object" ), PARSE_OPT_NONEG ,
576
575
parse_reuse_arg },
577
576
OPT_END ()
@@ -587,7 +586,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
587
586
usage_with_options (usage , options );
588
587
}
589
588
590
- if (msg .given && edit )
589
+ if (d .given && edit )
591
590
fprintf (stderr , _ ("The -m/-F/-c/-C options have been deprecated "
592
591
"for the 'edit' subcommand.\n"
593
592
"Please use 'git notes add -f -m/-F/-c/-C' instead.\n" ));
@@ -600,7 +599,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
600
599
t = init_notes_check (argv [0 ]);
601
600
note = get_note (t , object );
602
601
603
- create_note (object , & msg , !edit , note , new_note );
602
+ create_note (object , & d , !edit , note , new_note );
604
603
605
604
if (is_null_sha1 (new_note ))
606
605
remove_note (t , object );
@@ -611,7 +610,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
611
610
is_null_sha1 (new_note ) ? "removed" : "added" , argv [0 ]);
612
611
commit_notes (t , logmsg );
613
612
free_notes (t );
614
- strbuf_release (& ( msg .buf ) );
613
+ strbuf_release (& d .buf );
615
614
return 0 ;
616
615
}
617
616
0 commit comments