fmt-merge-msg: use pretty.c routines
This command duplicates functionality of the '%s' pretty format. Simplify the code a bit by using the pretty printing routine instead of open-coding it here. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Mar 24, 2010 at 00:16 UTC
15cb500786c3bc618dafa3c6bc9535236e7bfdcd
1 file changed
+8
-21
builtin/fmt-merge-msg.c
+8
-21
@@ -185,6 +185,7 @@ static void shortlog(const char *name, unsigned char *sha1,
185
struct object *branch;
186
struct list subjects = { NULL, NULL, 0, 0 };
187
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
188
+ struct strbuf sb = STRBUF_INIT;
189
190
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
191
if (!branch || branch->type != OBJ_COMMIT)
@@ -198,7 +199,7 @@ static void shortlog(const char *name, unsigned char *sha1,
199
if (prepare_revision_walk(rev))
200
die("revision walk setup failed");
201
while ((commit = get_revision(rev)) != NULL) {
201
- char *oneline, *bol, *eol;
202
+ struct pretty_print_context ctx = {0};
203
204
/* ignore merges */
205
if (commit->parents && commit->parents->next)
@@ -208,30 +209,16 @@ static void shortlog(const char *name, unsigned char *sha1,
209
if (subjects.nr > limit)
210
continue;
211
211
- bol = strstr(commit->buffer, "\n\n");
212
- if (bol) {
213
- unsigned char c;
214
- do {
215
- c = *++bol;
216
- } while (isspace(c));
217
- if (!c)
218
- bol = NULL;
219
- }
212
+ format_commit_message(commit, "%s", &sb, &ctx);
213
+ strbuf_ltrim(&sb);
214
221
- if (!bol) {
215
+ if (!sb.len)
216
append_to_list(&subjects, xstrdup(sha1_to_hex(
217
commit->object.sha1)),
218
NULL);
225
- continue;
226
- }
227
-
228
- eol = strchr(bol, '\n');
229
- if (eol) {
230
- oneline = xmemdupz(bol, eol - bol);
231
- } else {
232
- oneline = xstrdup(bol);
233
- }
234
- append_to_list(&subjects, oneline, NULL);
219
+ else
220
+ append_to_list(&subjects, strbuf_detach(&sb, NULL),
221
+ NULL);
222
}
223
224
if (count > limit)