@@ -202,35 +202,10 @@ static void shortlog(const char *name, unsigned char *sha1,
202202 string_list_clear (& subjects , 0 );
203203}
204204
205- int fmt_merge_msg (int merge_summary , struct strbuf * in , struct strbuf * out ) {
206- 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 ;
207208 char * sep = "" ;
208- unsigned char head_sha1 [20 ];
209- const char * current_branch ;
210-
211- /* get current branch */
212- current_branch = resolve_ref ("HEAD" , head_sha1 , 1 , NULL );
213- if (!current_branch )
214- die ("No current branch" );
215- if (!prefixcmp (current_branch , "refs/heads/" ))
216- current_branch += 11 ;
217-
218- /* get a line */
219- while (pos < in -> len ) {
220- int len ;
221- char * newline , * p = in -> buf + pos ;
222-
223- newline = strchr (p , '\n' );
224- len = newline ? newline - p : strlen (p );
225- pos += len + !!newline ;
226- i ++ ;
227- p [len ] = 0 ;
228- if (handle_line (p ))
229- die ("Error in line %d: %.*s" , i , len , p );
230- }
231-
232- if (!srcs .nr )
233- return 0 ;
234209
235210 strbuf_addstr (out , "Merge " );
236211 for (i = 0 ; i < srcs .nr ; i ++ ) {
@@ -278,6 +253,40 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
278253 strbuf_addch (out , '\n' );
279254 else
280255 strbuf_addf (out , " into %s\n" , current_branch );
256+ }
257+
258+ static int do_fmt_merge_msg (int merge_title , int merge_summary ,
259+ struct strbuf * in , 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+ if (merge_title )
289+ do_fmt_merge_msg_title (out , current_branch );
281290
282291 if (merge_summary ) {
283292 struct commit * head ;
@@ -289,13 +298,24 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
289298 rev .ignore_merges = 1 ;
290299 rev .limited = 1 ;
291300
301+ if (suffixcmp (out -> buf , "\n" ))
302+ strbuf_addch (out , '\n' );
303+
292304 for (i = 0 ; i < origins .nr ; i ++ )
293305 shortlog (origins .items [i ].string , origins .items [i ].util ,
294306 head , & rev , limit , out );
295307 }
296308 return 0 ;
297309}
298310
311+ int fmt_merge_msg (int merge_summary , struct strbuf * in , struct strbuf * out ) {
312+ return do_fmt_merge_msg (1 , merge_summary , in , out );
313+ }
314+
315+ int fmt_merge_msg_shortlog (struct strbuf * in , struct strbuf * out ) {
316+ return do_fmt_merge_msg (0 , 1 , in , out );
317+ }
318+
299319int cmd_fmt_merge_msg (int argc , const char * * argv , const char * prefix )
300320{
301321 const char * inpath = NULL ;
0 commit comments