git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Lederhofer <matled@gmx.net>
To: git@vger.kernel.org
Subject: [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set
Date: Mon, 12 Mar 2007 12:53:50 +0100	[thread overview]
Message-ID: <20070312115350.GA15179@moooo.ath.cx> (raw)
In-Reply-To: <20070311043250.GA21331@moooo.ath.cx>

git-init will always put an absolute path in
GIT_DIR/workdir, relative paths are resolved from the
directory git-init was called from.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
I found this static char path[PATH_MAX] even though path is neither
reused nor returned.  If there is any reason to have this as a static
buffer please change this back to 'static char'
---
 builtin-init-db.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4df9fd0..f0b4444 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -176,12 +176,13 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
 static int create_default_files(const char *git_dir, const char *template_path)
 {
 	unsigned len = strlen(git_dir);
-	static char path[PATH_MAX];
+	char path[PATH_MAX], workdir[PATH_MAX];
 	unsigned char sha1[20];
 	struct stat st1;
 	char repo_version_string[10];
 	int reinit;
 	int filemode;
+	const char *gitwd = getenv(GIT_WORKING_DIR_ENVIRONMENT);
 
 	if (len > sizeof(path)-50)
 		die("insane git directory %s", git_dir);
@@ -252,7 +253,42 @@ static int create_default_files(const char *git_dir, const char *template_path)
 	}
 	git_config_set("core.filemode", filemode ? "true" : "false");
 
-	if (is_bare_repository()) {
+	/* make gitwd an absolute path */
+	if (gitwd && gitwd[0] != '/') {
+		char cwd[PATH_MAX];
+
+		if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
+			die("Unable to read current working directory");
+		if (chdir(gitwd)) {
+			fprintf(stderr, "warning: chdir to specified relative "
+				"working directory failed, ignoring\n");
+			gitwd = NULL;
+		}
+		else if (!getcwd(workdir, sizeof(workdir)) || workdir[0] != '/')
+			die("Unable to read current working directory");
+		else {
+			gitwd = workdir;
+			if (chdir(cwd))
+				die("Cannot come back to cwd");
+		}
+	}
+
+	if (gitwd) {
+		FILE *fp = NULL;
+
+		path[len] = 0;
+		strcpy(path + len, "workdir");
+		if (!(fp = fopen(path, "w")))
+			die("Cannot open GIT_DIR/workdir");
+		fprintf(fp, "%s\n", gitwd);
+		fclose(fp);
+
+		git_config_set("core.bare", "false");
+		/* allow template config file to override the default */
+		if (log_all_ref_updates == -1)
+		    git_config_set("core.logallrefupdates", "true");
+	}
+	else if (is_bare_repository()) {
 		git_config_set("core.bare", "true");
 	}
 	else {
-- 
1.5.0.3.1006.gd633

  parent reply	other threads:[~2007-03-12 11:54 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-11  4:32 [RFC] introduce GIT_WORK_DIR environment variable Matthias Lederhofer
2007-03-11  5:34 ` Junio C Hamano
2007-03-11  8:26   ` Andy Parkins
2007-03-11 16:22   ` Matthias Lederhofer
2007-03-11 20:10     ` Junio C Hamano
2007-03-11 21:43       ` Johannes Schindelin
2007-03-11 20:37   ` Linus Torvalds
2007-03-11 21:04     ` Junio C Hamano
2007-03-11 21:13       ` Linus Torvalds
2007-03-12  8:08       ` A.J. Rossini
2007-04-01  7:42       ` Andy Parkins
2007-03-11 12:42 ` Nguyen Thai Ngoc Duy
2007-03-11 13:33   ` Matthias Lederhofer
2007-03-11 13:46     ` Nguyen Thai Ngoc Duy
2007-03-11 14:05       ` Matthias Lederhofer
2007-03-11 14:18         ` Nguyen Thai Ngoc Duy
2007-03-11 15:56   ` [PATCH(amend)] " Matthias Lederhofer
2007-03-11 16:25     ` Nguyen Thai Ngoc Duy
2007-03-11 21:29     ` [PATCH] use $GIT_DIR/workdir as working directory with $GIT_DIR Matthias Lederhofer
2007-03-13 23:10       ` [PATCH] core.workdir config variable Matthias Lederhofer
2007-03-13 23:57         ` [PATCH(amend)] " Matthias Lederhofer
2007-03-14  6:01           ` Shawn O. Pearce
2007-03-14  7:48             ` Junio C Hamano
2007-03-14 14:20               ` Shawn O. Pearce
2007-03-11 13:27 ` [RFC] introduce GIT_WORK_DIR environment variable Nguyen Thai Ngoc Duy
2007-03-11 15:05   ` [PATCH] rev-parse: --is-bare-repository option Matthias Lederhofer
2007-03-12 11:53 ` Matthias Lederhofer [this message]
2007-03-12 12:12   ` [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set Joshua N Pritikin
2007-03-12 12:52     ` Matthias Lederhofer
2007-03-12 13:12     ` Matthias Lederhofer
2007-03-12 13:36       ` Nguyen Thai Ngoc Duy
2007-03-12 14:08         ` Matthias Lederhofer
2007-03-12 17:31           ` Junio C Hamano
2007-03-12 18:08             ` Matthias Lederhofer
2007-03-12 19:18               ` [PATCH] always interpret GIT_WORK_DIR relative to $GIT_DIR Matthias Lederhofer
2007-03-12 19:53                 ` [PATCH] GIT_WORK_DIR: documentation for relative path Matthias Lederhofer
2007-03-12 20:05               ` [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set Junio C Hamano
2007-03-12 20:40                 ` Matthias Lederhofer
2007-03-12 19:23   ` [PATCH(amend)] " Matthias Lederhofer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070312115350.GA15179@moooo.ath.cx \
    --to=matled@gmx.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).