setup_revisions(): handle -n<n> and -<n> internally.
This moves the handling of max-count shorthand from the internal implementation of "git log" to setup_revisions() so other users of setup_revisions() can use it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 2, 2006 at 15:24 UTC
64bc6e3db54ef9e2accfdb8e6c8168f789946fcb
2 files changed
+16
-14
git.c
+1
-14
@@ -264,20 +264,7 @@ static int cmd_log(int argc, char **argv, char **envp)
264
argc = setup_revisions(argc, argv, &rev, "HEAD");
265
while (1 < argc) {
266
char *arg = argv[1];
267
- /* accept -<digit>, like traditilnal "head" */
268
- if ((*arg == '-') && isdigit(arg[1])) {
269
- rev.max_count = atoi(arg + 1);
270
- }
271
- else if (!strcmp(arg, "-n")) {
272
- if (argc < 2)
273
- die("-n requires an argument");
274
- rev.max_count = atoi(argv[2]);
275
- argc--; argv++;
276
- }
277
- else if (!strncmp(arg,"-n",2)) {
278
- rev.max_count = atoi(arg + 2);
279
- }
280
- else if (!strncmp(arg, "--pretty", 8)) {
267
+ if (!strncmp(arg, "--pretty", 8)) {
268
commit_format = get_commit_format(arg + 8);
269
if (commit_format == CMIT_FMT_ONELINE)
270
commit_prefix = "";
revision.c
+15
@@ -482,6 +482,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
482
revs->max_count = atoi(arg + 12);
483
continue;
484
}
485
+ /* accept -<digit>, like traditilnal "head" */
486
+ if ((*arg == '-') && isdigit(arg[1])) {
487
+ revs->max_count = atoi(arg + 1);
488
+ continue;
489
+ }
490
+ if (!strcmp(arg, "-n")) {
491
+ if (argc <= i + 1)
492
+ die("-n requires an argument");
493
+ revs->max_count = atoi(argv[++i]);
494
+ continue;
495
+ }
496
+ if (!strncmp(arg,"-n",2)) {
497
+ revs->max_count = atoi(arg + 2);
498
+ continue;
499
+ }
500
if (!strncmp(arg, "--max-age=", 10)) {
501
revs->max_age = atoi(arg + 10);
502
revs->limited = 1;