@@ -92,10 +92,7 @@ static const char * const git_notes_get_ref_usage[] = {
9292};
9393
9494static const char note_template [] =
95- "\n"
96- "#\n"
97- "# Write/edit the notes for the following object:\n"
98- "#\n" ;
95+ "\nWrite/edit the notes for the following object:\n" ;
9996
10097struct msg_arg {
10198 int given ;
@@ -129,7 +126,7 @@ static void write_commented_object(int fd, const unsigned char *object)
129126 {"show" , "--stat" , "--no-notes" , sha1_to_hex (object ), NULL };
130127 struct child_process show ;
131128 struct strbuf buf = STRBUF_INIT ;
132- FILE * show_out ;
129+ struct strbuf cbuf = STRBUF_INIT ;
133130
134131 /* Invoke "git show --stat --no-notes $object" */
135132 memset (& show , 0 , sizeof (show ));
@@ -142,21 +139,14 @@ static void write_commented_object(int fd, const unsigned char *object)
142139 die (_ ("unable to start 'show' for object '%s'" ),
143140 sha1_to_hex (object ));
144141
145- /* Open the output as FILE* so strbuf_getline() can be used. */
146- show_out = xfdopen ( show . out , "r" );
147- if ( show_out == NULL )
148- die_errno ( _ ( "can't fdopen 'show' output fd" ) );
142+ if ( strbuf_read ( & buf , show . out , 0 ) < 0 )
143+ die_errno ( _ ( "could not read ' show' output" ) );
144+ strbuf_add_commented_lines ( & cbuf , buf . buf , buf . len );
145+ write_or_die ( fd , cbuf . buf , cbuf . len );
149146
150- /* Prepend "# " to each output line and write result to 'fd' */
151- while (strbuf_getline (& buf , show_out , '\n' ) != EOF ) {
152- write_or_die (fd , "# " , 2 );
153- write_or_die (fd , buf .buf , buf .len );
154- write_or_die (fd , "\n" , 1 );
155- }
147+ strbuf_release (& cbuf );
156148 strbuf_release (& buf );
157- if (fclose (show_out ))
158- die_errno (_ ("failed to close pipe to 'show' for object '%s'" ),
159- sha1_to_hex (object ));
149+
160150 if (finish_command (& show ))
161151 die (_ ("failed to finish 'show' for object '%s'" ),
162152 sha1_to_hex (object ));
@@ -170,6 +160,7 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
170160
171161 if (msg -> use_editor || !msg -> given ) {
172162 int fd ;
163+ struct strbuf buf = STRBUF_INIT ;
173164
174165 /* write the template message before editing: */
175166 path = git_pathdup ("NOTES_EDITMSG" );
@@ -181,11 +172,16 @@ static void create_note(const unsigned char *object, struct msg_arg *msg,
181172 write_or_die (fd , msg -> buf .buf , msg -> buf .len );
182173 else if (prev && !append_only )
183174 write_note_data (fd , prev );
184- write_or_die (fd , note_template , strlen (note_template ));
175+
176+ strbuf_addch (& buf , '\n' );
177+ strbuf_add_commented_lines (& buf , note_template , strlen (note_template ));
178+ strbuf_addch (& buf , '\n' );
179+ write_or_die (fd , buf .buf , buf .len );
185180
186181 write_commented_object (fd , object );
187182
188183 close (fd );
184+ strbuf_release (& buf );
189185 strbuf_reset (& (msg -> buf ));
190186
191187 if (launch_editor (path , & (msg -> buf ), NULL )) {
0 commit comments