Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [RFC] Renaming environment variables.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:41:56

quoted
quoted
quoted
quoted
"DB" == Daniel Barkalow [off-list ref] writes:
DB> On Mon, 9 May 2005, Junio C Hamano wrote:
quoted
quoted
quoted
quoted
quoted
quoted
"DB" == Daniel Barkalow [off-list ref] writes:
DB> While we're at it, it would be useful to have one for what is normally
DB> ".git",...
quoted
If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and
your only gripe is about git-init-db creating ".git" in the
current working directory regardless of SHA1_FILE_DIRECTORY, I
would agree that what git-init-db does is broken.  Not that I
have a suggested "right behaviour" for it, though.
DB> It could just create all missing parents of the object directory, which
DB> would be better, at least.

I am ambivalent about this.  Here is an excerpt from my WIP.  I
am trying to keep the original semantics of "we create the
leading paths only if we default to .git/objects":

$ GIT_DIFF_OPTS=-u8 jit-diff 1: init-db.c
# - HEAD: Rename environment variables.
# + (working tree)
--- a/init-db.c
+++ b/init-db.c
@@ -22,21 +22,22 @@
  * be the judge.  The default case is to have one DB per managed directory.
  */
 int main(int argc, char **argv)
 {
 	const char *sha1_dir;
 	char *path;
 	int len, i;
 
-	safe_create_dir(".git");
-
-	sha1_dir = gitenv(DB_ENVIRONMENT);
-	if (!sha1_dir) {
-		sha1_dir = DEFAULT_DB_ENVIRONMENT;
+	sha1_dir = get_object_directory();
+	if (!gitenv(DB_ENVIRONMENT) && !gitenv(GIT_DIR_ENVIRONMENT)) {
+		/* We create leading paths only when we fall back
+		 * to local ".git/objects".
+		 */
+		safe_create_dir(DEFAULT_GIT_DIR_ENVIRONMENT);
 		fprintf(stderr, "defaulting to local storage area\n");
 	}
 	len = strlen(sha1_dir);
 	path = xmalloc(len + 40);
 	memcpy(path, sha1_dir, len);
 
 	safe_create_dir(sha1_dir);
 	for (i = 0; i < 256; i++) {
Here DEFAULT_GIT_DIR_ENVIRONMENT is defined as ".git", and the
directory is created only if we do not have GIT_OBJECT_DIRECTORY
nor GIT_DIR environment variables, which should match the intent
of the original by Linus.  Otherwise we at least require the
parent directory of GIT_OBJECT_DIRECTORY to exist.  I think that
is a reasonable default (well that is not something I can take
credit), in that if the user is clued enough to use something
different from the default he should at least know enough to
create the leading paths beforehand (or the script could do that
for him).

Other than this part, I think the code is ready to go.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help