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

[PATCH] Teach the git wrapper about --name-rev and --name-rev-by-tags

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 28, 2006, 11:12 UTC
Message-ID
<Pine.LNX.4.63.0607281308280.29667@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7v4px4osjv.fsf@assigned-by-dhcp.cox.net>
Now you can say
	git --name-rev log
instead of
	git log | git name-rev --stdin | less
with the benefit that diff.color=auto still works.

There is also a shortcut "-n" for --name-rev. The option --name-rev-by-tags (or -t) tries to name the revs by tags instead of all refs, which is nicer when talking to other people, since their heads may be different from yours (I feel like talking to Zaphod ;-).

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	On Wed, 26 Jul 2006, Junio C Hamano wrote:
	>  * Passing the standard error from "fetch-pack -v" to "name-rev
	>    --stdin" makes it a bit more pleasant to see what is going on.
	This patch makes it even easier.
 Documentation/git.txt |   12 ++++++++++--
 cache.h               |    1 +
 git.c                 |    9 +++++++--
 pager.c               |   41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 7310a2b..eae930f 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -9,7 +9,8 @@ git - the stupid content tracker
 SYNOPSIS
 --------
 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate]
-	[--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]
+	[-n|--name-rev] [-t|--name-rev-by-tags] [--bare]
+	[--git-dir=GIT_DIR] [--help] COMMAND [ARGS]
 
 DESCRIPTION
 -----------
@@ -45,12 +46,19 @@ OPTIONS
 -p|--paginate::
 	Pipe all output into 'less' (or if set, $PAGER).
 
+-n|--name-rev:
+	Try naming all SHA1s, and page the result (see
+	link:git-name-rev[1] for a detailed explanation).
+
+-t|--name-rev-by-tags:
+	Same as '--name-rev', but try to name the SHA1s by tags.
+
 --git-dir=<path>::
 	Set the path to the repository. This can also be controlled by
 	setting the GIT_DIR environment variable.
 
 --bare::
-	Same as --git-dir=`pwd`.
+	Same as  '--git-dir=`pwd`'.
 
 FURTHER DOCUMENTATION
 ---------------------
diff --git a/cache.h b/cache.h
index 8891073..d6c5edb 100644
--- a/cache.h
+++ b/cache.h
@@ -391,6 +391,7 @@ extern int receive_keep_pack(int fd[2], 
 
 /* pager.c */
 extern void setup_pager(void);
+extern void setup_name_rev_pager(int by_tags);
 extern int pager_in_use;
 
 /* base85 */
diff --git a/git.c b/git.c
index 4ea5efb..4206b43 100644
--- a/git.c
+++ b/git.c
@@ -63,9 +63,14 @@ static int handle_options(const char*** 
 				puts(git_exec_path());
 				exit(0);
 			}
-		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
+		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate"))
 			setup_pager();
-		} else if (!strcmp(cmd, "--git-dir")) {
+		else if (!strcmp(cmd, "-n") || !strcmp(cmd, "--name-rev"))
+			setup_name_rev_pager(0);
+		else if (!strcmp(cmd, "-t") ||
+				!strcmp(cmd, "--name-rev-by-tags"))
+			setup_name_rev_pager(1);
+		else if (!strcmp(cmd, "--git-dir")) {
 			if (*argc < 1)
 				return -1;
 			setenv("GIT_DIR", (*argv)[1], 1);
diff --git a/pager.c b/pager.c
index 280f57f..48b2467 100644
--- a/pager.c
+++ b/pager.c
@@ -53,3 +53,44 @@ void setup_pager(void)
 	die("unable to execute pager '%s'", pager);
 	exit(255);
 }
+
+void setup_name_rev_pager(int by_tags)
+{
+	pid_t pid;
+	int fd[2];
+
+	if (!isatty(1))
+		return;
+
+	pager_in_use = 1; /* means we are emitting to terminal */
+
+	if (pipe(fd) < 0)
+		return;
+	pid = fork();
+	if (pid < 0) {
+		close(fd[0]);
+		close(fd[1]);
+		return;
+	}
+
+	/* return in the child */
+	if (!pid) {
+		dup2(fd[1], 1);
+		close(fd[0]);
+		close(fd[1]);
+		return;
+	}
+
+	/* The original process turns into paging name-rev */
+	dup2(fd[0], 0);
+	close(fd[0]);
+	close(fd[1]);
+
+	setup_pager();
+	if (by_tags)
+		execl("git", "git", "name-rev", "--tags", "--stdin", NULL);
+	else
+		execl("git", "git", "name-rev", "--stdin", NULL);
+	die("unable to execute git-name-rev");
+	exit(255);
+}
-- 
1.4.2.rc2.g61d8
Previous: Johannes SchindelinNext: Junio C Hamano
Message 14 of 23 in “Slow fetches of tags”
  1. Ralf BaechleMay 24, 2006
  2. Linus TorvaldsMay 24, 2006
  3. Linus TorvaldsMay 24, 2006
  4. Junio C HamanoMay 24, 2006
  5. Linus TorvaldsMay 24, 2006
  6. Linus TorvaldsMay 24, 2006
  7. Junio C HamanoMay 25, 2006
  8. Junio C HamanoMay 25, 2006
  9. Ralf BaechleMay 26, 2006
  10. upload-pack: stop "ack continue" when we know common commits for wanted refsJunio C Hamano, May 27, 2006
  11. Ralf BaechleMay 25, 2006
  12. Junio C HamanoJul 26, 2006
  13. Johannes SchindelinJul 28, 2006
  14. Teach the git wrapper about --name-rev and --name-rev-by-tagsJohannes Schindelin, Jul 28, 2006
  15. Junio C HamanoJul 28, 2006
  16. Linus TorvaldsJul 28, 2006
  17. Johannes SchindelinJul 28, 2006
  18. Nguyễn Thái Ngọc DuyJul 29, 2006
  19. Johannes SchindelinJul 29, 2006
  20. Junio C HamanoMay 24, 2006
  21. Ralf BaechleMay 24, 2006
  22. Junio C HamanoMay 24, 2006
  23. Ralf BaechleMay 25, 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.