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

[PATCH 2/6] setup: set startup_info->have_repository more reliably

From
Jeff King <peff@peff.net>
Date
Mar 5, 2016, 22:11 UTC
Message-ID
<20160305221134.GB31508@sigill.intra.peff.net>
In-Reply-To
<20160305220829.GA31316@sigill.intra.peff.net>

When setup_git_directory() is called, we set a flag in startup_info to indicate we have a repository. But there are a few other mechanisms by which we might set up a repo:

  1. When creating a new repository via init_db(), we
     transition from no-repo to being in a repo. We should
     tweak this flag at that moment.
  2. In enter_repo(), a stricter form of
     setup_git_directory() used by server-side programs, we
     check the repository format config. After doing so, we
     know we're in a repository, and can set the flag.

With these changes, library code can now reliably tell whether we are in a repository and act accordingly. We'll leave the "prefix" field as NULL, which is what happens when setup_git_directory() finds there is no prefix.

Signed-off-by: Jeff King <peff@peff.net>
---
I did these patches directly on master.  When applied on top of the
other check_repository_format series I posted a few days ago, this one
will have a minor textual conflict (that other series dropped the
pointless return from this function).
 builtin/init-db.c | 1 +
 setup.c           | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 6223b7d..da531f6 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -322,6 +322,7 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
 		set_git_dir(real_path(git_dir));
 		git_link = NULL;
 	}
+	startup_info->have_repository = 1;
 	return 0;
 }
 
diff --git a/setup.c b/setup.c
index fa7a306..3439ec6 100644
--- a/setup.c
+++ b/setup.c
@@ -986,7 +986,9 @@ int check_repository_format_version(const char *var, const char *value, void *cb
 
 int check_repository_format(void)
 {
-	return check_repository_format_gently(get_git_dir(), NULL);
+	check_repository_format_gently(get_git_dir(), NULL);
+	startup_info->have_repository = 1;
+	return 0;
 }
 
 /*
-- 
2.8.0.rc1.318.g2193183
Previous: Jeff KingNext: Jeff King
Message 3 of 10 in “avoid touching ref code in non-repositories”
  1. 0/6 avoid touching ref code in non-repositoriesJeff King, Mar 5, 2016
  2. 1/6 setup: make startup_info available everywhereJeff King, Mar 5, 2016
  3. 2/6 setup: set startup_info->have_repository more reliablyJeff King, Mar 5, 2016
  4. 3/6 remote: don't resolve HEAD in non-repositoryJeff King, Mar 5, 2016
  5. 4/6 mailmap: do not resolve blobs in a non-repositoryJeff King, Mar 5, 2016
  6. 5/6 grep: turn off gitlink detection for --no-indexJeff King, Mar 5, 2016
  7. Junio C HamanoMar 7, 2016
  8. 5/6 grep: turn off gitlink detection for --no-indexJeff King, Mar 7, 2016
  9. 6/6 use setup_git_directory() in test-* programsJeff King, Mar 5, 2016
  10. Junio C HamanoMar 7, 2016

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.