92
};
93
94
static 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";
96
97
struct msg_arg {
98
int given;
126
{"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
127
struct child_process show;
128
struct strbuf buf = STRBUF_INIT;
132
- FILE *show_out;
129
+ struct strbuf cbuf = STRBUF_INIT;
130
131
/* Invoke "git show --stat --no-notes $object" */
132
memset(&show, 0, sizeof(show));
139
die(_("unable to start 'show' for object '%s'"),
140
sha1_to_hex(object));
141
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);
146
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);
148
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
+
150
if (finish_command(&show))
151
die(_("failed to finish 'show' for object '%s'"),
152
sha1_to_hex(object));
160
161
if (msg->use_editor || !msg->given) {
162
int fd;
163
+ struct strbuf buf = STRBUF_INIT;
164
165
/* write the template message before editing: */
166
path = git_pathdup("NOTES_EDITMSG");
172
write_or_die(fd, msg->buf.buf, msg->buf.len);
173
else if (prev && !append_only)
174
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);
180
181
write_commented_object(fd, object);
182
183
close(fd);
184
+ strbuf_release(&buf);
185
strbuf_reset(&(msg->buf));
186
187
if (launch_editor(path, &(msg->buf), NULL)) {