git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] rev-{list,parse}: allow -<n> as shorthand for --max-count=<n>

From
EWEric Wong <normalperson@yhbt.net>
Date
Jan 30, 2006, 00:28 UTC
Message-ID
<20060130002802.GD15482@Muzzle>
In-Reply-To
<7v64o2kcym.fsf@assigned-by-dhcp.cox.net>

This will be enabled unless POSIXLY_CORRECT or POSIX_ME_HARDER is set in the environment.

Some versions of head(1) and tail(1) allow their line limits to be parsed this way. I find --max-count to be a commonly used option, and also similar in spirit to head/tail, so I decided to make life easier on my worn out (and lazy :) fingers with this patch.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 git-compat-util.h |    8 ++++++++
 rev-list.c        |    5 +++++
 rev-parse.c       |    4 ++++
 3 files changed, 17 insertions(+), 0 deletions(-)
7a8d6dda7dacadc90377fc56d28d5d03493199c4
diff --git a/git-compat-util.h b/git-compat-util.h
index f982b8e..b2512ba 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -154,4 +154,12 @@ static inline int sane_case(int x, int h
 #ifndef MAXPATHLEN
 #define MAXPATHLEN 256
 #endif
+
+static inline int posixly_correct(void)
+{
+	if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER"))
+		return 1;
+	return 0;
+}
+
 #endif
diff --git a/rev-list.c b/rev-list.c
index 4565755..f29d32a 100644
--- a/rev-list.c
+++ b/rev-list.c
@@ -749,6 +749,11 @@ int main(int argc, const char **argv)
 		struct commit *commit;
 		unsigned char sha1[20];
 
+		/* accept, -<digit>, like some versions of head/tail  */
+		if (!posixly_correct() && (*arg == '-') && isdigit(arg[1])) {
+			max_count = atoi(arg + 1);
+			continue;
+		}
 		if (!strcmp(arg, "-n")) {
 			if (++i >= argc)
 				die("-n requires an argument");
diff --git a/rev-parse.c b/rev-parse.c
index 3c99a79..2966a33 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -53,6 +53,10 @@ static int is_rev_argument(const char *a
 	};
 	const char **p = rev_args;
 
+	/* accept, -<digit>, like some versions of head/tail  */
+	if (!posixly_correct() && (*arg == '-') && isdigit(arg[1]))
+		return 1;
+
 	for (;;) {
 		const char *str = *p++;
 		int len;
-- 
1.1.5.ga7f5-dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 11 in “rev-{list,parse}: allow -<n> as shorthand for --max-count=<n>”
  1. rev-{list,parse}: allow -<n> as shorthand for --max-count=<n>Eric Wong, Jan 24, 2006
  2. Junio C HamanoJan 24, 2006
  3. Eric WongJan 25, 2006
  4. Junio C HamanoJan 25, 2006
  5. rev-{list,parse}: allow -n<n> as shorthand for --max-count=<n>Eric Wong, Jan 29, 2006
  6. rev-{list,parse}: optionally allow -<n> as shorthand for --max-count=<n>Eric Wong, Jan 29, 2006
  7. Junio C HamanoJan 29, 2006
  8. rev-{list,parse}: allow -<n> as shorthand for --max-count=<n>Eric Wong, Jan 30, 2006
  9. Junio C HamanoJan 29, 2006
  10. Eric WongJan 30, 2006
  11. rev-{list,parse}: allow -n<n> as shorthand for --max-count=<n>Eric Wong, Jan 30, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.