@matheusbsbs / matheus-bagliano / commits / 403994e83d
Fork 0

fmt-merge-msg: refactor merge title formatting

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed May 11, 2010 at 01:17 UTC 403994e83dd3ad2424f0b3084c8dc4fd1ca6374a
1 file changed +36 -29
builtin/fmt-merge-msg.c
+36 -29
@@ -202,36 +202,10 @@ static void shortlog(const char *name, unsigned char *sha1,
202 string_list_clear(&subjects, 0);
203 }
204
205 -static int do_fmt_merge_msg(int merge_summary, struct strbuf *in,
206 - struct strbuf *out) {
207 - int limit = 20, i = 0, pos = 0;
205 +static void do_fmt_merge_msg_title(struct strbuf *out,
206 + const char *current_branch) {
207 + int i = 0;
208 char *sep = "";
209 - unsigned char head_sha1[20];
210 - const char *current_branch;
211 -
212 - /* get current branch */
213 - current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
214 - if (!current_branch)
215 - die("No current branch");
216 - if (!prefixcmp(current_branch, "refs/heads/"))
217 - current_branch += 11;
218 -
219 - /* get a line */
220 - while (pos < in->len) {
221 - int len;
222 - char *newline, *p = in->buf + pos;
223 -
224 - newline = strchr(p, '\n');
225 - len = newline ? newline - p : strlen(p);
226 - pos += len + !!newline;
227 - i++;
228 - p[len] = 0;
229 - if (handle_line(p))
230 - die ("Error in line %d: %.*s", i, len, p);
231 - }
232 -
233 - if (!srcs.nr)
234 - return 0;
209
210 strbuf_addstr(out, "Merge ");
211 for (i = 0; i < srcs.nr; i++) {
@@ -279,6 +253,39 @@ static int do_fmt_merge_msg(int merge_summary, struct strbuf *in,
253 strbuf_addch(out, '\n');
254 else
255 strbuf_addf(out, " into %s\n", current_branch);
256 +}
257 +
258 +static int do_fmt_merge_msg(int merge_summary, struct strbuf *in,
259 + struct strbuf *out) {
260 + int limit = 20, i = 0, pos = 0;
261 + unsigned char head_sha1[20];
262 + const char *current_branch;
263 +
264 + /* get current branch */
265 + current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
266 + if (!current_branch)
267 + die("No current branch");
268 + if (!prefixcmp(current_branch, "refs/heads/"))
269 + current_branch += 11;
270 +
271 + /* get a line */
272 + while (pos < in->len) {
273 + int len;
274 + char *newline, *p = in->buf + pos;
275 +
276 + newline = strchr(p, '\n');
277 + len = newline ? newline - p : strlen(p);
278 + pos += len + !!newline;
279 + i++;
280 + p[len] = 0;
281 + if (handle_line(p))
282 + die ("Error in line %d: %.*s", i, len, p);
283 + }
284 +
285 + if (!srcs.nr)
286 + return 0;
287 +
288 + do_fmt_merge_msg_title(out, current_branch);
289
290 if (merge_summary) {
291 struct commit *head;