Re: [PATCH] Fix install-doc-quick target

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johannes Schindelin
Date: Sunday, August 5, 2007 - 6:12 am

Hi,

On Sun, 5 Aug 2007, Junio C Hamano wrote:


I do not like the behaviour "be stupid and assume cwd to be the working 
tree root, if GIT_DIR is set and GIT_WORK_TREE is not".

It bears _all_ kind of stupid connotations.  Just imagine what would 
happen with "git --git-dir=. add .".

IMHO the new behaviour is _better_, since you can not shoot yourself in 
the foot so easily.  Being able to safeguard against doing a work tree 
operation inside the git directory is a direct and elegant consequence of 
defaulting to $GIT_DIR/.. in case $GIT_DIR ends in "/.git", and no work 
tree if $GIT_DIR does _not_ end in "/.git".

The semantics "if GIT_DIR is set, just assume the cwd to be the work tree 
root unilaterally" is _broken_ as far as I am concerned.

NOTE: this change in semantics will _only_ _ever_ burn you if you set 
GIT_DIR, but not GIT_WORK_TREE, in a _subdirectory_ of $GIT_DIR/.. (if it 
ends in /.git, and $GIT_DIR otherwise).

So the _common_ use of setting GIT_DIR, namely something like

	$ git --git-dir=/some/where/completely/different bla

is _not_ affected.

So I really think that the code in install-doc-quick.sh is not only ugly, 
but also wrong.  It sets the GIT_DIR to _the same_ value as the default, 
to change git's idea of the _work tree_!  All at the same time as it is 
utterly clear that it wants to write to $HOME/share/man, but it does not 
make this its working tree.  No, sir.  It has to play cute games with the 
prefix.

However, you are the maintainer, and it is your decision.  If you want the 
old semantics (without sanity checks for work-tree operations inside the 
git directory), here is a patch.  I don't like it, but if you take it, 
I'll learn to live with it.

Ciao,
Dscho

-- snipsnap --
Reinstate the old behaviour when GIT_DIR is set and GIT_WORK_TREE is unset

The old behaviour was to unilaterally default to the cwd is the work tree 
when GIT_DIR was set, but GIT_WORK_TREE wasn't, no matter if we are inside 
the GIT_DIR, or if GIT_DIR is actually something like ../../../.git.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

	Feel free to change the commit message.

 setup.c |   50 +++++++++-----------------------------------------
 1 files changed, 9 insertions(+), 41 deletions(-)

diff --git a/setup.c b/setup.c
index 4945eb3..7bcf4eb 100644
--- a/setup.c
+++ b/setup.c
@@ -189,53 +189,21 @@ int is_inside_work_tree(void)
 }
 
 /*
- * If no worktree was given, and we are outside of a default work tree,
- * now is the time to set it.
- *
- * In other words, if the user calls git with something like
- *
- *	git --git-dir=/some/where/else/.git bla
- *
- * default to /some/where/else as working directory; if the specified
- * git-dir does not end in "/.git", the cwd is used as working directory.
+ * set_work_tree() is only ever called if you set GIT_DIR explicitely.
+ * The old behaviour (which we retain here) is to set the work tree root
+ * to the cwd, unless overridden by the config, the command line, or
+ * GIT_WORK_TREE.
  */
 const char *set_work_tree(const char *dir)
 {
-	char dir_buffer[PATH_MAX], *rel = NULL;
-	static char buffer[PATH_MAX + 1];
-	int len, suffix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1;
-
-	/* strip the variable 'dir' of the postfix "/.git" if it has it */
-	len = strlen(dir);
-	if (len > suffix_len &&
-	    !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
-		if ((len - suffix_len) >= sizeof(dir_buffer))
-			die("directory name too long");
-		memcpy(dir_buffer, dir, len - suffix_len);
-		dir_buffer[len - suffix_len] = '\0';
-
-		/* are we inside the default work tree? */
-		rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
-	}
+	char buffer[PATH_MAX + 1];
 
-	/* if rel is set, the cwd is _not_ the current working tree */
-	if (rel && *rel) {
-		if (!is_absolute_path(dir))
-			set_git_dir(make_absolute_path(dir));
-		dir = dir_buffer;
-		if (chdir(dir))
-			die("cannot chdir to %s: %s", dir, strerror(errno));
-		else
-			strcat(rel, "/");
-		inside_git_dir = 0;
-	} else {
-		rel = NULL;
-		dir = getcwd(buffer, sizeof(buffer));
-	}
-	git_work_tree_cfg = xstrdup(dir);
+	if (!getcwd(buffer, sizeof(buffer)))
+		die ("Could not get the current working directory");
+	git_work_tree_cfg = xstrdup(buffer);
 	inside_work_tree = 1;
 
-	return rel;
+	return NULL;
 }
 
 /*
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 8:07 am)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 8:38 am)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 9:00 am)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 9:04 am)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 9:08 am)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 9:14 am)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 9:16 am)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 9:21 am)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 9:27 am)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 10:56 am)
Re: rc4 - make quick-install-doc is broken, rene.scharfe, (Sat Aug 4, 1:19 pm)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 1:21 pm)
Re: rc4 - make quick-install-doc is broken, Mark Levedahl, (Sat Aug 4, 1:45 pm)
[PATCH] Fix quick-install-doc, Johannes Schindelin, (Sat Aug 4, 2:32 pm)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 2:33 pm)
Re: [PATCH] Fix quick-install-doc, rene.scharfe, (Sat Aug 4, 3:09 pm)
Re: rc4 - make quick-install-doc is broken, rene.scharfe, (Sat Aug 4, 3:09 pm)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 3:25 pm)
Re: rc4 - make quick-install-doc is broken, Johannes Schindelin, (Sat Aug 4, 3:37 pm)
Re: rc4 - make quick-install-doc is broken, rene.scharfe, (Sat Aug 4, 4:03 pm)
[PATCH] Fix install-doc-quick target, Junio C Hamano, (Sun Aug 5, 12:07 am)
Re: [PATCH] Fix install-doc-quick target, Johannes Schindelin, (Sun Aug 5, 6:12 am)
Re: [PATCH] Fix install-doc-quick target, Johannes Schindelin, (Sun Aug 5, 7:44 am)
Re: [PATCH] Fix install-doc-quick target, Junio C Hamano, (Sun Aug 5, 10:54 am)
Re: [PATCH] Fix install-doc-quick target, Johannes Schindelin, (Sun Aug 5, 11:10 am)
[PATCH] (Really) Fix install-doc-quick target, Mark Levedahl, (Mon Aug 6, 3:43 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Johannes Schindelin, (Mon Aug 6, 3:50 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Junio C Hamano, (Mon Aug 6, 4:07 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Mark Levedahl, (Mon Aug 6, 4:38 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Johannes Schindelin, (Mon Aug 6, 4:43 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Mark Levedahl, (Mon Aug 6, 4:49 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Junio C Hamano, (Mon Aug 6, 6:28 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Mark Levedahl, (Mon Aug 6, 6:55 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, Junio C Hamano, (Mon Aug 6, 8:53 pm)
Re: [PATCH] (Really) Fix install-doc-quick target, rene.scharfe, (Tue Aug 7, 6:55 am)
Re: [PATCH] (Really) Fix install-doc-quick target, Johannes Schindelin, (Tue Aug 7, 7:08 am)