* [BUG] git-init does not respect existing separate-git-dir
@ 2013-08-29 12:39 Ximin Luo
2013-08-29 13:04 ` Duy Nguyen
0 siblings, 1 reply; 5+ messages in thread
From: Ximin Luo @ 2013-08-29 12:39 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 609 bytes --]
It should not be necessary to re-specify --separate-git-dir when re-initialising a git repo.
$ git init --separate-git-dir ../repo
Initialized empty Git repository in /home/infinity0/tmp/repo/
$ git init
/home/infinity0/tmp/wtree/.git/refs: Not a directory
1
One big motivation is so "git init" can be a good "fire-and-forget" invocation that should work anywhere. Currently, one has to do "git init --separate-git-dir $(git rev-parse --git-dir)" which is a lot less elegant.
(Please CC me as I am not subscribed.)
--
GPG: 4096R/1318EFAC5FBBDBCE
git://github.com/infinity0/pubkeys.git
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 897 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] git-init does not respect existing separate-git-dir
2013-08-29 12:39 [BUG] git-init does not respect existing separate-git-dir Ximin Luo
@ 2013-08-29 13:04 ` Duy Nguyen
2013-08-29 17:12 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Duy Nguyen @ 2013-08-29 13:04 UTC (permalink / raw)
To: Ximin Luo; +Cc: git
On Thu, Aug 29, 2013 at 01:39:02PM +0100, Ximin Luo wrote:
> It should not be necessary to re-specify --separate-git-dir when re-initialising a git repo.
>
> $ git init --separate-git-dir ../repo
> Initialized empty Git repository in /home/infinity0/tmp/repo/
>
> $ git init
> /home/infinity0/tmp/wtree/.git/refs: Not a directory
> 1
This patch seems to work. Lightly tested.
-- 8< --
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 78aa387..d0e5b2e 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -192,6 +192,15 @@ static int create_default_files(const char *template_path)
die(_("insane git directory %s"), git_dir);
memcpy(path, git_dir, len);
+ if (!lstat(path, &st1) && S_ISREG(st1.st_mode)) {
+ git_dir = read_gitfile(git_dir);
+ len = strlen(git_dir);
+ if (len > sizeof(path)-50)
+ die(_("insane git directory %s"), git_dir);
+ set_git_dir(git_dir);
+ memcpy(path, git_dir, len);
+ }
+
if (len && path[len-1] != '/')
path[len++] = '/';
-- 8< --
> One big motivation is so "git init" can be a good "fire-and-forget"
> invocation that should work anywhere. Currently, one has to do "git
> init --separate-git-dir $(git rev-parse --git-dir)" which is a lot
> less elegant.
--
Duy
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [BUG] git-init does not respect existing separate-git-dir
2013-08-29 13:04 ` Duy Nguyen
@ 2013-08-29 17:12 ` Junio C Hamano
2013-08-31 1:04 ` [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified Nguyễn Thái Ngọc Duy
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2013-08-29 17:12 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Ximin Luo, git
Duy Nguyen <pclouds@gmail.com> writes:
> On Thu, Aug 29, 2013 at 01:39:02PM +0100, Ximin Luo wrote:
>> It should not be necessary to re-specify --separate-git-dir when re-initialising a git repo.
>>
>> $ git init --separate-git-dir ../repo
>> Initialized empty Git repository in /home/infinity0/tmp/repo/
>>
>> $ git init
>> /home/infinity0/tmp/wtree/.git/refs: Not a directory
>> 1
>
> This patch seems to work. Lightly tested.
>
> -- 8< --
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 78aa387..d0e5b2e 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -192,6 +192,15 @@ static int create_default_files(const char *template_path)
> die(_("insane git directory %s"), git_dir);
> memcpy(path, git_dir, len);
>
> + if (!lstat(path, &st1) && S_ISREG(st1.st_mode)) {
> + git_dir = read_gitfile(git_dir);
> + len = strlen(git_dir);
> + if (len > sizeof(path)-50)
> + die(_("insane git directory %s"), git_dir);
> + set_git_dir(git_dir);
This repetition from the pre-context of the patch makes me wonder if
it may be a better solution to make sure we have already resolved
the gitfile way before we get here, so that get_git_dir() gives the
real location.
The codepaths in init and clone are both special in that they may be
dealing with a new repository and because of that, they may need to
call set_git_dir() themselves, but in the codeflow for normal (read:
those who deal with an existing repositories) programs, discovery of
the real ".git" directory is done by environment.c::get_git_dir(),
which to calls setup_git_env(), which in turn read_gitfile()'s on
".git" when using the default ".git", like so:
static void setup_git_env(void)
{
git_dir = getenv(GIT_DIR_ENVIRONMENT);
git_dir = git_dir ? xstrdup(git_dir) : NULL;
if (!git_dir) {
git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
git_dir = git_dir ? xstrdup(git_dir) : NULL;
}
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
And after this sequence, git_object_dir and git_index_file are
computed off of git_dir, unless they are specified to use an
alternate location via environment variables.
I wonder if the last "use DEFAULT_GIT_DIR_ENVIRONMENT" (which is
".git") should also do the read_gitfile() thing, perhaps like this
(totally untested):
environment.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/environment.c b/environment.c
index 5398c36..944e10e 100644
--- a/environment.c
+++ b/environment.c
@@ -123,14 +123,16 @@ static char *expand_namespace(const char *raw_namespace)
static void setup_git_env(void)
{
+ const char *gitfile;
+
git_dir = getenv(GIT_DIR_ENVIRONMENT);
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
- if (!git_dir) {
- git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
- }
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ gitfile = read_gitfile(git_dir);
+ if (!gitfile)
+ git_dir = xstrdup(git_dir);
+ else
+ git_dir = gitfile;
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
git_object_dir = xmalloc(strlen(git_dir) + 9);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified
2013-08-29 17:12 ` Junio C Hamano
@ 2013-08-31 1:04 ` Nguyễn Thái Ngọc Duy
2013-09-03 18:14 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2013-08-31 1:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Ximin Luo, Nguyễn Thái Ngọc Duy
This makes reinitializing on a .git file repository work.
This is probably the only case that setup_git_env() (via
set_git_dir()) is called on a .git file. Other cases in
setup_git_dir_gently() and enter_repo() both cover .git file case
explicitly because they need to verify the target repo is valid.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Reported-by: Ximin Luo <infinity0@gmx.com>
---
Slight change in the patch to xstrdup(gitfile) because read_gitfile
returns a static buffer.
environment.c | 9 ++++-----
t/t0001-init.sh | 4 ++++
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/environment.c b/environment.c
index 5398c36..378254c 100644
--- a/environment.c
+++ b/environment.c
@@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
static void setup_git_env(void)
{
+ const char *gitfile;
+
git_dir = getenv(GIT_DIR_ENVIRONMENT);
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
- if (!git_dir) {
- git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
- }
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ gitfile = read_gitfile(git_dir);
+ git_dir = xstrdup(gitfile ? gitfile : git_dir);
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
git_object_dir = xmalloc(strlen(git_dir) + 9);
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index ad66410..9fb582b 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
test -d realgitdir/refs
'
+test_expect_success 're-init on .git file' '
+ ( cd newdir && git init )
+'
+
test_expect_success 're-init to update git link' '
(
cd newdir &&
--
1.8.2.83.gc99314b
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified
2013-08-31 1:04 ` [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified Nguyễn Thái Ngọc Duy
@ 2013-09-03 18:14 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2013-09-03 18:14 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git, Ximin Luo
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> This makes reinitializing on a .git file repository work.
>
> This is probably the only case that setup_git_env() (via
> set_git_dir()) is called on a .git file. Other cases in
> setup_git_dir_gently() and enter_repo() both cover .git file case
> explicitly because they need to verify the target repo is valid.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> Reported-by: Ximin Luo <infinity0@gmx.com>
> ---
> Slight change in the patch to xstrdup(gitfile) because read_gitfile
> returns a static buffer.
Thanks for fixing it up. Will queue.
>
> environment.c | 9 ++++-----
> t/t0001-init.sh | 4 ++++
> 2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/environment.c b/environment.c
> index 5398c36..378254c 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
>
> static void setup_git_env(void)
> {
> + const char *gitfile;
> +
> git_dir = getenv(GIT_DIR_ENVIRONMENT);
> - git_dir = git_dir ? xstrdup(git_dir) : NULL;
> - if (!git_dir) {
> - git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
> - git_dir = git_dir ? xstrdup(git_dir) : NULL;
> - }
> if (!git_dir)
> git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
> + gitfile = read_gitfile(git_dir);
> + git_dir = xstrdup(gitfile ? gitfile : git_dir);
> git_object_dir = getenv(DB_ENVIRONMENT);
> if (!git_object_dir) {
> git_object_dir = xmalloc(strlen(git_dir) + 9);
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index ad66410..9fb582b 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
> test -d realgitdir/refs
> '
>
> +test_expect_success 're-init on .git file' '
> + ( cd newdir && git init )
> +'
> +
> test_expect_success 're-init to update git link' '
> (
> cd newdir &&
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-03 18:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-29 12:39 [BUG] git-init does not respect existing separate-git-dir Ximin Luo
2013-08-29 13:04 ` Duy Nguyen
2013-08-29 17:12 ` Junio C Hamano
2013-08-31 1:04 ` [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified Nguyễn Thái Ngọc Duy
2013-09-03 18:14 ` Junio C Hamano
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).