Skip to content

Commit 64bc6e3

Browse files
author
Junio C Hamano
committed
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 <[email protected]>
1 parent 7ae0b0c commit 64bc6e3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

git.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,7 @@ static int cmd_log(int argc, char **argv, char **envp)
264264
argc = setup_revisions(argc, argv, &rev, "HEAD");
265265
while (1 < argc) {
266266
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)) {
281268
commit_format = get_commit_format(arg + 8);
282269
if (commit_format == CMIT_FMT_ONELINE)
283270
commit_prefix = "";

revision.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
482482
revs->max_count = atoi(arg + 12);
483483
continue;
484484
}
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+
}
485500
if (!strncmp(arg, "--max-age=", 10)) {
486501
revs->max_age = atoi(arg + 10);
487502
revs->limited = 1;

0 commit comments

Comments
 (0)