@@ -129,7 +129,17 @@ static void read_from_stdin(struct shortlog *log)
129
129
static const char * committer_match [2 ] = { "Commit: " , "committer " };
130
130
const char * * match ;
131
131
132
- match = log -> committer ? committer_match : author_match ;
132
+ switch (log -> group ) {
133
+ case SHORTLOG_GROUP_AUTHOR :
134
+ match = author_match ;
135
+ break ;
136
+ case SHORTLOG_GROUP_COMMITTER :
137
+ match = committer_match ;
138
+ break ;
139
+ default :
140
+ BUG ("unhandled shortlog group" );
141
+ }
142
+
133
143
while (strbuf_getline_lf (& ident , stdin ) != EOF ) {
134
144
const char * v ;
135
145
if (!skip_prefix (ident .buf , match [0 ], & v ) &&
@@ -158,27 +168,36 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
158
168
struct strbuf ident = STRBUF_INIT ;
159
169
struct strbuf oneline = STRBUF_INIT ;
160
170
struct pretty_print_context ctx = {0 };
161
- const char * fmt ;
171
+ const char * oneline_str ;
162
172
163
173
ctx .fmt = CMIT_FMT_USERFORMAT ;
164
174
ctx .abbrev = log -> abbrev ;
165
175
ctx .print_email_subject = 1 ;
166
176
ctx .date_mode .type = DATE_NORMAL ;
167
177
ctx .output_encoding = get_log_output_encoding ();
168
178
169
- fmt = log -> committer ?
170
- (log -> email ? "%cN <%cE>" : "%cN" ) :
171
- (log -> email ? "%aN <%aE>" : "%aN" );
172
-
173
- format_commit_message (commit , fmt , & ident , & ctx );
174
179
if (!log -> summary ) {
175
180
if (log -> user_format )
176
181
pretty_print_commit (& ctx , commit , & oneline );
177
182
else
178
183
format_commit_message (commit , "%s" , & oneline , & ctx );
179
184
}
180
-
181
- insert_one_record (log , ident .buf , oneline .len ? oneline .buf : "<none>" );
185
+ oneline_str = oneline .len ? oneline .buf : "<none>" ;
186
+
187
+ switch (log -> group ) {
188
+ case SHORTLOG_GROUP_AUTHOR :
189
+ format_commit_message (commit ,
190
+ log -> email ? "%aN <%aE>" : "%aN" ,
191
+ & ident , & ctx );
192
+ insert_one_record (log , ident .buf , oneline_str );
193
+ break ;
194
+ case SHORTLOG_GROUP_COMMITTER :
195
+ format_commit_message (commit ,
196
+ log -> email ? "%cN <%cE>" : "%cN" ,
197
+ & ident , & ctx );
198
+ insert_one_record (log , ident .buf , oneline_str );
199
+ break ;
200
+ }
182
201
183
202
strbuf_release (& ident );
184
203
strbuf_release (& oneline );
@@ -241,6 +260,21 @@ static int parse_wrap_args(const struct option *opt, const char *arg, int unset)
241
260
return 0 ;
242
261
}
243
262
263
+ static int parse_group_option (const struct option * opt , const char * arg , int unset )
264
+ {
265
+ struct shortlog * log = opt -> value ;
266
+
267
+ if (unset || !strcasecmp (arg , "author" ))
268
+ log -> group = SHORTLOG_GROUP_AUTHOR ;
269
+ else if (!strcasecmp (arg , "committer" ))
270
+ log -> group = SHORTLOG_GROUP_COMMITTER ;
271
+ else
272
+ return error (_ ("unknown group type: %s" ), arg );
273
+
274
+ return 0 ;
275
+ }
276
+
277
+
244
278
void shortlog_init (struct shortlog * log )
245
279
{
246
280
memset (log , 0 , sizeof (* log ));
@@ -260,8 +294,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
260
294
int nongit = !startup_info -> have_repository ;
261
295
262
296
const struct option options [] = {
263
- OPT_BOOL ('c' , "committer" , & log .committer ,
264
- N_ ("Group by committer rather than author" )),
297
+ OPT_SET_INT ('c' , "committer" , & log .group ,
298
+ N_ ("Group by committer rather than author" ),
299
+ SHORTLOG_GROUP_COMMITTER ),
265
300
OPT_BOOL ('n' , "numbered" , & log .sort_by_number ,
266
301
N_ ("sort output according to the number of commits per author" )),
267
302
OPT_BOOL ('s' , "summary" , & log .summary ,
@@ -271,6 +306,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
271
306
OPT_CALLBACK_F ('w' , NULL , & log , N_ ("<w>[,<i1>[,<i2>]]" ),
272
307
N_ ("Linewrap output" ), PARSE_OPT_OPTARG ,
273
308
& parse_wrap_args ),
309
+ OPT_CALLBACK (0 , "group" , & log , N_ ("field" ),
310
+ N_ ("Group by field" ), parse_group_option ),
274
311
OPT_END (),
275
312
};
276
313
0 commit comments