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

Re: [Funky] "git -p cmd" inside a bare repository

From
Jeff King <peff@peff.net>
Date
Dec 14, 2007, 05:12 UTC
Message-ID
<20071214051223.GD10169@sigill.intra.peff.net>
In-Reply-To
<7vmysexdvw.fsf@gitster.siamese.dyndns.org>
On Thu, Dec 13, 2007 at 05:29:23PM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> I _think_ what is happening is that setup_pager() tries to run
> git_config(), which runs setup(), and then RUN_SETUP set for "ls-tree"
> (or "show") internal command runs setup again.  HEAD is given to
> resolve_ref() and git_path("%s", ref) makes it to ".git/HEAD", even
> though in a bare repository git_dir should be set to ".", and of course
> we cannot find such a path in the git directory.

I think that there is perhaps a larger bug here, which is that running setup twice gives bad results, and should either be fixed or have its own "don't run me twice" guard.

But it makes sense to always spawn the pager at the same time for consistency. As a bonus, this makes "git -p bogus" a little more friendly by not spawning the pager until we verify the command name.

-- >8 -- delay "git -p" page spawning until command runtime

This makes the timing consistent with those commands that always spawn a pager. It also avoids a funny interaction related to calling setup_pager() before setup().

---
diff --git a/git.c b/git.c
index c8b7e74..21d204f 100644
--- a/git.c
+++ b/git.c
@@ -6,6 +6,8 @@
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
 
+static int user_asked_for_pager;
+
 static int handle_options(const char*** argv, int* argc, int* envchanged)
 {
 	int handled = 0;
@@ -35,7 +37,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 				exit(0);
 			}
 		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
-			setup_pager();
+			user_asked_for_pager = 1;
 		} else if (!strcmp(cmd, "--no-pager")) {
 			setenv("GIT_PAGER", "cat", 1);
 			if (envchanged)
@@ -256,7 +258,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
 	prefix = NULL;
 	if (p->option & RUN_SETUP)
 		prefix = setup_git_directory();
-	if (p->option & USE_PAGER)
+	if (p->option & USE_PAGER || user_asked_for_pager)
 		setup_pager();
 	if (p->option & NEED_WORK_TREE)
 		setup_work_tree();
Previous: Junio C HamanoNext: Jeff King
Message 4 of 10 in “Do check_repository_format() early”
  1. Do check_repository_format() earlyNguyễn Thái Ngọc Duy, Nov 29, 2007
  2. [Funky] "git -p cmd" inside a bare repositoryJunio C Hamano, Dec 14, 2007
  3. make git start-up sequence a bit more robustJunio C Hamano, Dec 14, 2007
  4. Jeff KingDec 14, 2007
  5. Jeff KingDec 14, 2007
  6. Junio C HamanoDec 14, 2007
  7. Nguyen Thai Ngoc DuyDec 14, 2007
  8. Johannes SchindelinDec 14, 2007
  9. Junio C HamanoDec 14, 2007
  10. Johannes SchindelinDec 14, 2007

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.