5
5
#include "revision.h"
6
6
#include "tag.h"
7
7
#include "string-list.h"
8
+ #include "branch.h"
9
+ #include "fmt-merge-msg.h"
8
10
9
11
static const char * const fmt_merge_msg_usage [] = {
10
12
"git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]" ,
11
13
NULL
12
14
};
13
15
14
- static int shortlog_len ;
16
+ static int use_branch_desc ;
15
17
16
- static int fmt_merge_msg_config (const char * key , const char * value , void * cb )
18
+ int fmt_merge_msg_config (const char * key , const char * value , void * cb )
17
19
{
18
20
if (!strcmp (key , "merge.log" ) || !strcmp (key , "merge.summary" )) {
19
21
int is_bool ;
20
- shortlog_len = git_config_bool_or_int (key , value , & is_bool );
21
- if (!is_bool && shortlog_len < 0 )
22
+ merge_log_config = git_config_bool_or_int (key , value , & is_bool );
23
+ if (!is_bool && merge_log_config < 0 )
22
24
return error ("%s: negative length %s" , key , value );
23
- if (is_bool && shortlog_len )
24
- shortlog_len = DEFAULT_MERGE_LOG_LEN ;
25
+ if (is_bool && merge_log_config )
26
+ merge_log_config = DEFAULT_MERGE_LOG_LEN ;
27
+ } else if (!strcmp (key , "merge.branchdesc" )) {
28
+ use_branch_desc = git_config_bool (key , value );
25
29
}
26
30
return 0 ;
27
31
}
@@ -31,6 +35,11 @@ struct src_data {
31
35
int head_status ;
32
36
};
33
37
38
+ struct origin_data {
39
+ unsigned char sha1 [20 ];
40
+ int is_local_branch :1 ;
41
+ };
42
+
34
43
static void init_src_data (struct src_data * data )
35
44
{
36
45
data -> branch .strdup_strings = 1 ;
@@ -45,7 +54,7 @@ static struct string_list origins = STRING_LIST_INIT_DUP;
45
54
static int handle_line (char * line )
46
55
{
47
56
int i , len = strlen (line );
48
- unsigned char * sha1 ;
57
+ struct origin_data * origin_data ;
49
58
char * src , * origin ;
50
59
struct src_data * src_data ;
51
60
struct string_list_item * item ;
@@ -61,11 +70,13 @@ static int handle_line(char *line)
61
70
return 2 ;
62
71
63
72
line [40 ] = 0 ;
64
- sha1 = xmalloc ( 20 );
65
- i = get_sha1 (line , sha1 );
73
+ origin_data = xcalloc ( 1 , sizeof ( struct origin_data ) );
74
+ i = get_sha1 (line , origin_data -> sha1 );
66
75
line [40 ] = '\t' ;
67
- if (i )
76
+ if (i ) {
77
+ free (origin_data );
68
78
return 3 ;
79
+ }
69
80
70
81
if (line [len - 1 ] == '\n' )
71
82
line [len - 1 ] = 0 ;
@@ -93,6 +104,7 @@ static int handle_line(char *line)
93
104
origin = src ;
94
105
src_data -> head_status |= 1 ;
95
106
} else if (!prefixcmp (line , "branch " )) {
107
+ origin_data -> is_local_branch = 1 ;
96
108
origin = line + 7 ;
97
109
string_list_append (& src_data -> branch , origin );
98
110
src_data -> head_status |= 2 ;
@@ -119,7 +131,9 @@ static int handle_line(char *line)
119
131
sprintf (new_origin , "%s of %s" , origin , src );
120
132
origin = new_origin ;
121
133
}
122
- string_list_append (& origins , origin )-> util = sha1 ;
134
+ if (strcmp ("." , src ))
135
+ origin_data -> is_local_branch = 0 ;
136
+ string_list_append (& origins , origin )-> util = origin_data ;
123
137
return 0 ;
124
138
}
125
139
@@ -140,16 +154,38 @@ static void print_joined(const char *singular, const char *plural,
140
154
}
141
155
}
142
156
143
- static void shortlog (const char * name , unsigned char * sha1 ,
144
- struct commit * head , struct rev_info * rev , int limit ,
145
- struct strbuf * out )
157
+ static void add_branch_desc (struct strbuf * out , const char * name )
158
+ {
159
+ struct strbuf desc = STRBUF_INIT ;
160
+
161
+ if (!read_branch_desc (& desc , name )) {
162
+ const char * bp = desc .buf ;
163
+ while (* bp ) {
164
+ const char * ep = strchrnul (bp , '\n' );
165
+ if (* ep )
166
+ ep ++ ;
167
+ strbuf_addf (out , " : %.*s" , (int )(ep - bp ), bp );
168
+ bp = ep ;
169
+ }
170
+ if (out -> buf [out -> len - 1 ] != '\n' )
171
+ strbuf_addch (out , '\n' );
172
+ }
173
+ strbuf_release (& desc );
174
+ }
175
+
176
+ static void shortlog (const char * name ,
177
+ struct origin_data * origin_data ,
178
+ struct commit * head ,
179
+ struct rev_info * rev , int limit ,
180
+ struct strbuf * out )
146
181
{
147
182
int i , count = 0 ;
148
183
struct commit * commit ;
149
184
struct object * branch ;
150
185
struct string_list subjects = STRING_LIST_INIT_DUP ;
151
186
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED ;
152
187
struct strbuf sb = STRBUF_INIT ;
188
+ const unsigned char * sha1 = origin_data -> sha1 ;
153
189
154
190
branch = deref_tag (parse_object (sha1 ), sha1_to_hex (sha1 ), 40 );
155
191
if (!branch || branch -> type != OBJ_COMMIT )
@@ -188,6 +224,9 @@ static void shortlog(const char *name, unsigned char *sha1,
188
224
else
189
225
strbuf_addf (out , "\n* %s:\n" , name );
190
226
227
+ if (origin_data -> is_local_branch && use_branch_desc )
228
+ add_branch_desc (out , name );
229
+
191
230
for (i = 0 ; i < subjects .nr ; i ++ )
192
231
if (i >= limit )
193
232
strbuf_addf (out , " ...\n" );
@@ -303,8 +342,9 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
303
342
strbuf_addch (out , '\n' );
304
343
305
344
for (i = 0 ; i < origins .nr ; i ++ )
306
- shortlog (origins .items [i ].string , origins .items [i ].util ,
307
- head , & rev , shortlog_len , out );
345
+ shortlog (origins .items [i ].string ,
346
+ origins .items [i ].util ,
347
+ head , & rev , shortlog_len , out );
308
348
}
309
349
return 0 ;
310
350
}
@@ -318,6 +358,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
318
358
{
319
359
const char * inpath = NULL ;
320
360
const char * message = NULL ;
361
+ int shortlog_len = -1 ;
321
362
struct option options [] = {
322
363
{ OPTION_INTEGER , 0 , "log" , & shortlog_len , "n" ,
323
364
"populate log with at most <n> entries from shortlog" ,
@@ -341,6 +382,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
341
382
0 );
342
383
if (argc > 0 )
343
384
usage_with_options (fmt_merge_msg_usage , options );
385
+ if (shortlog_len < 0 )
386
+ shortlog_len = (merge_log_config > 0 ) ? merge_log_config : 0 ;
344
387
if (message && !shortlog_len ) {
345
388
char nl = '\n' ;
346
389
write_in_full (STDOUT_FILENO , message , strlen (message ));
0 commit comments