Skip to content

Commit 15cb500

Browse files
bebarinogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d6f6e6 commit 15cb500

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

builtin/fmt-merge-msg.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static void shortlog(const char *name, unsigned char *sha1,
185185
struct object *branch;
186186
struct list subjects = { NULL, NULL, 0, 0 };
187187
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
188+
struct strbuf sb = STRBUF_INIT;
188189

189190
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
190191
if (!branch || branch->type != OBJ_COMMIT)
@@ -198,7 +199,7 @@ static void shortlog(const char *name, unsigned char *sha1,
198199
if (prepare_revision_walk(rev))
199200
die("revision walk setup failed");
200201
while ((commit = get_revision(rev)) != NULL) {
201-
char *oneline, *bol, *eol;
202+
struct pretty_print_context ctx = {0};
202203

203204
/* ignore merges */
204205
if (commit->parents && commit->parents->next)
@@ -208,30 +209,16 @@ static void shortlog(const char *name, unsigned char *sha1,
208209
if (subjects.nr > limit)
209210
continue;
210211

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);
220214

221-
if (!bol) {
215+
if (!sb.len)
222216
append_to_list(&subjects, xstrdup(sha1_to_hex(
223217
commit->object.sha1)),
224218
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);
235222
}
236223

237224
if (count > limit)

0 commit comments

Comments
 (0)