From: Matthias Lederhofer <matled@gmx.net>
To: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: [PATCH] core.workdir config variable
Date: Wed, 14 Mar 2007 00:10:04 +0100 [thread overview]
Message-ID: <20070313231004.GA15058@moooo.ath.cx> (raw)
In-Reply-To: <20070311212906.GA18208@moooo.ath.cx>
core.workdir is used as default value for $GIT_WORK_DIR
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
This one replaces the 'use $GIT_DIR/workdir as working directory with
$GIT_DIR' patch and uses core.workdir instead. This patch gets
core.workdir only for setup.c from the configuration file. Perhaps
this should be handled in git_default_config like most other core.*
variables.
I just noticed that dying if the specified workdir is invalid can
cause trouble too:
$ export GIT_DIR=/path/to/repository
$ git config core.workdir /non-existent
$ git config core.workdir ../workdir
fatal: Unable to stat git working directory '/non-existent'
Workaround is either to edit the file manually or do:
$ git --work-dir=. config core.workdir ../workdir
---
Documentation/config.txt | 4 +++
setup.c | 53 +++++++++++++++++++++++++++++++++++++++++----
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5408dd6..663d82d 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -162,6 +162,10 @@ repository that ends in "/.git" is assumed to be not bare (bare =
false), while all other repositories are assumed to be bare (bare
= true).
+core.workdir::
+ Directory to be used as toplevel working directory when GIT_DIR
+ is set. This can be overriden by GIT_WORK_DIR.
+
core.logAllRefUpdates::
Updates to a ref <ref> is logged to the file
"$GIT_DIR/logs/<ref>", by appending the new and old
diff --git a/setup.c b/setup.c
index ebf628e..913c4b4 100644
--- a/setup.c
+++ b/setup.c
@@ -192,6 +192,53 @@ int is_inside_git_dir(void)
return inside_git_dir;
}
+static char **git_work_dir;
+
+static int git_workdir_config(const char *var, const char *value)
+{
+ if (!strcmp(var, "core.workdir")) {
+ strlcpy(value, *git_work_dir, PATH_MAX);
+ }
+ return 0;
+}
+
+static int stat_git_work_dir(struct stat *st)
+{
+ char workdir[PATH_MAX], cwd[PATH_MAX];
+ const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
+ const char *gitwd = getenv(GIT_WORKING_DIR_ENVIRONMENT);
+
+ if (gitwd) {
+ if (!stat(gitwd, st))
+ return 1;
+ die("Unable to stat git working directory '%s'", gitwd);
+ }
+
+ /* get workdir from config */
+ workdir[0] = '\0';
+ git_work_dir = workdir;
+ git_config(git_workdir_config);
+ git_workdir_config = NULL;
+ if (!workdir[0])
+ return 0;
+
+ /* relative path: change to gitdir for stat */
+ if (workdir[0] != '/') {
+ if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
+ die("Unable to read current working directory");
+ if (chdir(gitdir))
+ die("Cannot change directory to '%s'", gitdir);
+ }
+
+ if (stat(workdir, st))
+ die("Unable to stat git working directory '%s'", workdir);
+
+ if (workdir[0] != '/' && chdir(cwd))
+ die("Cannot come back to cwd");
+
+ return 1;
+}
+
int has_working_directory = -1;
const char *setup_git_directory_gently(int *nongit_ok)
@@ -203,7 +250,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
if (gitdirenv) {
struct stat st, st_work, st_git;
- const char *gitwd;
char *prefix;
char c;
int len;
@@ -219,11 +265,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
}
/* check for working directory */
- gitwd = getenv(GIT_WORKING_DIR_ENVIRONMENT);
- if (!gitwd)
+ if (!stat_git_work_dir(&st_work))
return NULL;
- if (stat(gitwd, &st_work))
- die("Unable to stat git working directory '%s'", gitwd);
if (inside_git_dir == -1 && stat(gitdirenv, &st_git))
die("Unable to stat git directory");
if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
--
1.5.0.3.970.ge984-dirty
next prev parent reply other threads:[~2007-03-13 23:10 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 ` Matthias Lederhofer [this message]
2007-03-13 23:57 ` [PATCH(amend)] core.workdir config variable 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 ` [PATCH] git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is set Matthias Lederhofer
2007-03-12 12:12 ` 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=20070313231004.GA15058@moooo.ath.cx \
--to=matled@gmx.net \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.