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

[PATCH v7 09/11] initdb: make safe_create_dir public

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 9, 2015, 17:03 UTC
Message-ID
<3ca59b9ffc153e11361176249380ae605d73aafd.1447085798.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1447085798.git.mhagger@alum.mit.edu>
From: David Turner <dturner@twopensource.com>

Soon we will want to create initdb functions for ref backends, and code from initdb that calls this function needs to move into the files backend. So this function needs to be public.

Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/init-db.c | 12 ------------
 cache.h           |  8 ++++++++
 path.c            | 12 ++++++++++++
 3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index f59f407..07229d6 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -24,18 +24,6 @@ static int init_shared_repository = -1;
 static const char *init_db_template_dir;
 static const char *git_link;
 
-static void safe_create_dir(const char *dir, int share)
-{
-	if (mkdir(dir, 0777) < 0) {
-		if (errno != EEXIST) {
-			perror(dir);
-			exit(1);
-		}
-	}
-	else if (share && adjust_shared_perm(dir))
-		die(_("Could not make %s writable by group"), dir);
-}
-
 static void copy_templates_1(struct strbuf *path, struct strbuf *template,
 			     DIR *dir)
 {
diff --git a/cache.h b/cache.h
index 9a905a8..0f9808c 100644
--- a/cache.h
+++ b/cache.h
@@ -1737,4 +1737,12 @@ void stat_validity_update(struct stat_validity *sv, int fd);
 int versioncmp(const char *s1, const char *s2);
 void sleep_millisec(int millisec);
 
+/*
+ * Create a directory and (if share is nonzero) adjust its permissions
+ * according to the shared_repository setting. Only use this for
+ * directories under $GIT_DIR.  Don't use it for working tree
+ * directories.
+ */
+void safe_create_dir(const char *dir, int share);
+
 #endif /* CACHE_H */
diff --git a/path.c b/path.c
index 212695a..9e0283c 100644
--- a/path.c
+++ b/path.c
@@ -723,6 +723,18 @@ int adjust_shared_perm(const char *path)
 	return 0;
 }
 
+void safe_create_dir(const char *dir, int share)
+{
+	if (mkdir(dir, 0777) < 0) {
+		if (errno != EEXIST) {
+			perror(dir);
+			exit(1);
+		}
+	}
+	else if (share && adjust_shared_perm(dir))
+		die(_("Could not make %s writable by group"), dir);
+}
+
 static int have_same_root(const char *path1, const char *path2)
 {
 	int is_abs1, is_abs2;
-- 
2.6.2
Previous: Michael HaggertyNext: Michael Haggerty
Message 15 of 18 in “refs backend pre-vtable”
  1. 00/11 refs backend pre-vtableMichael Haggerty, Nov 9, 2015
  2. 01/11 refs: make is_branch publicMichael Haggerty, Nov 9, 2015
  3. Ramsay JonesNov 9, 2015
  4. David TurnerNov 9, 2015
  5. Michael HaggertyNov 10, 2015
  6. 02/11 verify_refname_available(): rename functionMichael Haggerty, Nov 9, 2015
  7. 03/11 verify_refname_available(): new functionMichael Haggerty, Nov 9, 2015
  8. 04/11 copy_msg(): rename to copy_reflog_msg()Michael Haggerty, Nov 9, 2015
  9. 05/11 pack_if_possible_fn(): use ref_type() instead of is_per_worktree_ref()Michael Haggerty, Nov 9, 2015
  10. 06/11 refname_is_safe(): improve docstringMichael Haggerty, Nov 9, 2015
  11. 07/11 refs/refs-internal.h: new header fileMichael Haggerty, Nov 9, 2015
  12. Ramsay JonesNov 9, 2015
  13. David TurnerNov 9, 2015
  14. Michael HaggertyNov 10, 2015
  15. 09/11 initdb: make safe_create_dir publicMichael Haggerty, Nov 9, 2015
  16. 10/11 files_log_ref_write: new functionMichael Haggerty, Nov 9, 2015
  17. 11/11 refs: break out ref conflict checksMichael Haggerty, Nov 9, 2015
  18. David TurnerNov 9, 2015

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.