shortlog: fix "-n"
Since it is now a builtin optionally taking a range, we have to parse the options before the rev machinery, to be able to shadow the short hand "-n" for "--max-count". Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Nov 21, 2006 at 21:12 UTC
6d6ab6104a5055b9f66cc9a80d55d2ef59d0763c
1 file changed
+9
-6
builtin-shortlog.c
+9
-6
@@ -15,11 +15,11 @@ static int compare_by_number(const void *a1, const void *a2)
15
const struct path_list *l1 = i1->util, *l2 = i2->util;
16
17
if (l1->nr < l2->nr)
18
- return -1;
18
+ return 1;
19
else if (l1->nr == l2->nr)
20
return 0;
21
else
22
- return +1;
22
+ return -1;
23
}
24
25
static struct path_list mailmap = {NULL, 0, 0, 0};
@@ -251,8 +251,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
251
struct path_list list = { NULL, 0, 0, 1 };
252
int i, j, sort_by_number = 0, summary = 0;
253
254
- init_revisions(&rev, prefix);
255
- argc = setup_revisions(argc, argv, &rev, NULL);
254
+ /* since -n is a shadowed rev argument, parse our args first */
255
while (argc > 1) {
256
if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "--numbered"))
257
sort_by_number = 1;
@@ -262,10 +261,14 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
261
else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
262
usage(shortlog_usage);
263
else
265
- die ("unrecognized argument: %s", argv[1]);
264
+ break;
265
argv++;
266
argc--;
267
}
268
+ init_revisions(&rev, prefix);
269
+ argc = setup_revisions(argc, argv, &rev, NULL);
270
+ if (argc > 1)
271
+ die ("unrecognized argument: %s", argv[1]);
272
273
if (!access(".mailmap", R_OK))
274
read_mailmap(".mailmap");
@@ -278,7 +281,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
281
get_from_rev(&rev, &list);
282
283
if (sort_by_number)
281
- qsort(list.items, sizeof(struct path_list_item), list.nr,
284
+ qsort(list.items, list.nr, sizeof(struct path_list_item),
285
compare_by_number);
286
287
for (i = 0; i < list.nr; i++) {