{"thread":{"id":"519","subject":"[PATCH] Introduce SHA1_FILE_DIRECTORIES","startedAt":"2005-05-06T23:35:27Z","lastAt":"2005-05-10T23:39:12Z","messageCount":30,"participants":["Junio C Hamano","Sean","H. Peter Anvin","Thomas Glanzmann","Daniel Barkalow","Petr Baudis","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2722","messageId":"7vmzr8apxc.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":null,"subject":"[PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-06T23:35:27Z","receivedAt":"2005-05-06T23:35:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"A new environment variable, SHA1_FILE_DIRECTORIES, is\nintroduced.  This affects the routines that read existing\nobjects from the object database, but not creation of new\nobjects.\n\nThe environment variable, when exists, is a colon separated list of\ndirectories.  If an object is not found in the usual location\nSHA1_FILE_DIRECTORY (or .git/objects), this list is consulted and if\nobject is found there it is returned.\n\nThis is an implementation of the idea floated on the GIT list a couple\nof days ago to archive really old history on a separate directory, even\non a read-only DVD ROM media.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\ncache.h     |    5 +-\nsha1_file.c |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n2 files changed, 112 insertions(+), 6 deletions(-)\n\n--- a/cache.h\n+++ b/cache.h\n@@ -101,8 +101,7 @@ unsigned int active_nr, active_alloc;\n \n #define DB_ENVIRONMENT \"SHA1_FILE_DIRECTORY\"\n #define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n-\n-#define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)\n+#define ALTERNATE_DB_ENVIRONMENT \"SHA1_FILE_DIRECTORIES\"\n \n #define INDEX_ENVIRONMENT \"GIT_INDEX_FILE\"\n #define DEFAULT_INDEX_ENVIRONMENT \".git/index\"\n@@ -130,7 +129,7 @@ extern int index_fd(unsigned char *sha1,\n #define DATA_CHANGED    0x0020\n #define TYPE_CHANGED    0x0040\n \n-/* Return a statically allocated filename matching the sha1 signature */\n+/* Return a statically allocated filename matching the sha1 signature. */\n extern char *sha1_file_name(const unsigned char *sha1);\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -100,10 +100,19 @@ char * sha1_to_hex(const unsigned char *\n \treturn buffer;\n }\n \n+static const char *get_object_directory(void)\n+{\n+\treturn getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n+}\n+\n /*\n  * NOTE! This returns a statically allocated buffer, so you have to be\n  * careful about using it. Do a \"strdup()\" if you need to save the\n  * filename.\n+ *\n+ * Also note that this returns the location for creating.  Reading\n+ * SHA1 file can happen from any alternate directory listed in the\n+ * SHA1_FILE_DIRECTORIES environment variable.\n  */\n char *sha1_file_name(const unsigned char *sha1)\n {\n@@ -130,6 +139,99 @@ char *sha1_file_name(const unsigned char\n \treturn base;\n }\n \n+static char *find_sha1_file(const unsigned char *sha1)\n+{\n+\tstruct stat st;\n+\tchar *name = sha1_file_name(sha1);\n+\tstatic struct {\n+\t\tint pfxlen;\n+\t\tchar *buf;\n+\t} *alternates = NULL;\n+\tstatic int num_alt = -1;\n+\tint i;\n+\n+\tif (num_alt < 0) {\n+\t\tint cnt;\n+\t\tint totlen;\n+\t\tconst char *cp, *last;\n+\t\tconst char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);\n+\t\tvoid *buf;\n+\t\tchar *op;\n+\n+\t\tif (!alt || !alt[0]) {\n+\t\t\tnum_alt = 0;\n+\t\t\treturn name;\n+\t\t}\n+\n+\t\tfor (last = cp = alt, totlen = cnt = 0; *cp; cp++) {\n+\t\t\t/* We could strip the empty path which would result\n+\t\t\t * in /xx/xxxxx from the filesystem root level,\n+\t\t\t * but who cares.  We are only constructing list of\n+\t\t\t * paths to attempt to read not write.\n+\t\t\t */\n+\t\t\tif (*cp == ':') {\n+\t\t\t\t/* 40 bytes plus two / and terminating NUL */\n+\t\t\t\ttotlen += cp - last + 43;\n+\t\t\t\tcnt++;\n+\t\t\t\tlast = cp + 1;\n+\t\t\t}\n+\t\t}\n+\t\tif (cp != last) {\n+\t\t\ttotlen += cp - last + 43;\n+\t\t\tcnt++;\n+\t\t}\n+\n+\t\tif (!cnt) {\n+\t\t\tnum_alt = 0;\n+\t\t\treturn name;\n+\t\t}\n+\t\tnum_alt = cnt;\n+\n+\t\tbuf = xmalloc(sizeof(*alternates) * (cnt + 1) + totlen);\n+\t\talternates = buf;\n+\t\talternates[num_alt].pfxlen = 0;\n+\t\talternates[num_alt].buf = NULL;\n+\t\top = (char*) (&alternates[cnt+1]);\n+\t\tfor (last = cp = alt, i = 0; i < num_alt; cp++) {\n+\t\t\tif (*cp == ':' || *cp == 0) {\n+\t\t\t\talternates[i].buf = op;\n+\t\t\t\talternates[i].pfxlen = cp - last;\n+\t\t\t\tmemcpy(op, last, cp - last);\n+\t\t\t\top[cp - last] = 0;\n+\t\t\t\top += (cp - last + 1);\n+\t\t\t\tlast = cp + 1;\n+\t\t\t\ti++;\n+\t\t\t}\n+\t\t}\n+\t\tif (cp != last) {\n+\t\t\talternates[i].buf = op;\n+\t\t\talternates[i].pfxlen = last - cp;\n+\t\t\tmemcpy(op, last, last - cp);\n+\t\t\top[last-cp] = 0;\n+\t\t}\n+\t}\n+\tif (!stat(name, &st))\n+\t\treturn name;\n+\tfor (i = 0; i < num_alt; i++) {\n+\t\tchar *alt = alternates[i].buf;\n+\t\tint len = alternates[i].pfxlen;\n+\t\tchar *name = alt + len;\n+\t\talt[len] = '/';\n+\t\talt[len+3] = '/';\n+\t\tname = alt + len + 1;\n+\t\tfor (i = 0; i < 20; i++) {\n+\t\t\tstatic char hex[] = \"0123456789abcdef\";\n+\t\t\tunsigned int val = sha1[i];\n+\t\t\tchar *pos = name + i*2 + (i > 0);\n+\t\t\t*pos++ = hex[val >> 4];\n+\t\t\t*pos = hex[val & 0xf];\n+\t\t}\n+\t\tif (!stat(alt, &st))\n+\t\t\treturn alt;\n+\t}\n+\treturn NULL;\n+}\n+\n int check_sha1_signature(unsigned char *sha1, void *map, unsigned long size, const char *type)\n {\n \tchar header[100];\n@@ -145,10 +247,14 @@ int check_sha1_signature(unsigned char *\n \n void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n {\n-\tchar *filename = sha1_file_name(sha1);\n \tstruct stat st;\n \tvoid *map;\n \tint fd;\n+\tchar *filename = find_sha1_file(sha1);\n+\tif (!filename) {\n+\t\terror(\"cannot map sha1 file %s\", sha1_to_hex(sha1));\n+\t\treturn NULL;\n+\t}\n \n \tfd = open(filename, O_RDONLY | sha1_file_open_flag);\n \tif (fd < 0) {\n@@ -442,8 +548,10 @@ int write_sha1_from_fd(const unsigned ch\n \n int has_sha1_file(const unsigned char *sha1)\n {\n-\tchar *filename = sha1_file_name(sha1);\n \tstruct stat st;\n+\tchar *filename = find_sha1_file(sha1);\n+\tif (!filename)\n+\t\treturn 0;\n \n \tif (!stat(filename, &st))\n \t\treturn 1;\n----------------------------------------------------------------\n\n"},{"id":"2725","messageId":"2637.10.10.10.24.1115425225.squirrel@linux1","threadId":"519","inReplyTo":"7vmzr8apxc.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-07T00:20:25Z","receivedAt":"2005-05-07T00:20:25Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Fri, May 6, 2005 7:35 pm, Junio C Hamano said:\n\nHi Junio,\n\n> This is an implementation of the idea floated on the GIT list a couple\n> of days ago to archive really old history on a separate directory, even\n> on a read-only DVD ROM media.\n\nDavid Lang should get the credit for the idea.\n\n>  int has_sha1_file(const unsigned char *sha1)\n>  {\n> -\tchar *filename = sha1_file_name(sha1);\n>  \tstruct stat st;\n> +\tchar *filename = find_sha1_file(sha1);\n> +\tif (!filename)\n> +\t\treturn 0;\n>\n>  \tif (!stat(filename, &st))\n>  \t\treturn 1;\n\nhas_sha1_file can be reduced to:\n\n\nint has_sha1_file(const unsigned char *sha1)\n{\n       return (!!find_sha1_file(sha1));\n}\n\n\nSean\n\n\n"},{"id":"2726","messageId":"7vis1vc27f.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"2637.10.10.10.24.1115425225.squirrel@linux1","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-07T00:24:52Z","receivedAt":"2005-05-07T00:24:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"S\" == Sean  <seanlkml@sympatico.ca> writes:\n\nS> has_sha1_file can be reduced to:\n\nS> int has_sha1_file(const unsigned char *sha1)\nS> {\nS>        return (!!find_sha1_file(sha1));\nS> }\n\nNot really.  If you do not have alternates it does not even\nbother to stat so you get the path that supposed to contain the\ndata and you need to do the checking yourself.\n\n"},{"id":"2728","messageId":"2721.10.10.10.24.1115425962.squirrel@linux1","threadId":"519","inReplyTo":"7vis1vc27f.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-07T00:32:42Z","receivedAt":"2005-05-07T00:32:42Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Fri, May 6, 2005 8:24 pm, Junio C Hamano said:\n>>>>>> \"S\" == Sean  <seanlkml@sympatico.ca> writes:\n>\n> S> has_sha1_file can be reduced to:\n>\n> S> int has_sha1_file(const unsigned char *sha1)\n> S> {\n> S>        return (!!find_sha1_file(sha1));\n> S> }\n>\n> Not really.  If you do not have alternates it does not even\n> bother to stat so you get the path that supposed to contain the\n> data and you need to do the checking yourself.\n>\n>\n\nPerhaps I'm just missing something in your code, but this fragment makes\nit look to me that stat is always called in find_sha1_file even when there\nare no alternates:\n\n+        char *name = sha1_file_name(sha1);\n[...]\n+        if (!stat(name, &st))\n+                return name;\n+        for (i = 0; i < num_alt; i++) {\n\n\nSean\n\n\n"},{"id":"2734","messageId":"7vbr7nbl89.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"2721.10.10.10.24.1115425962.squirrel@linux1","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-07T06:31:34Z","receivedAt":"2005-05-07T06:31:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"S\" == Sean  <seanlkml@sympatico.ca> writes:\n\nS> Perhaps I'm just missing something in your code,...\n\nYes you are.  You have spotted a very inconvenient inconsistency\nin the interface to the code.\n\nOnly on the very first time when it tries to constructs the\nalternate directory list, and if there is no alternate list, it\njust returns the name without stat(), which forces the callers\nto do stat() themselves all the time.  I think I should make it\nalways stat, since the reading side needs do it anyway.\n\nThankfully I think Linus had rejected this part in the series.\nI'll fix it up.\n\n"},{"id":"2753","messageId":"7vacn6ak7r.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"7vbr7nbl89.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-07T19:51:04Z","receivedAt":"2005-05-07T19:51:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"JCH\" == Junio C Hamano <junkio@cox.net> writes:\n>>>>> \"S\" == Sean  <seanlkml@sympatico.ca> writes:\n\nS> Perhaps I'm just missing something in your code,...\nJCH> Thankfully I think Linus had rejected this part in the series.\nJCH> I'll fix it up.\n\nHere is the fixed one.  The previous one was ugly and\ninconvenient to use (thanks for noticing, Sean).\n\nI'll keep it in the git-jc repository until Linus returns.\n\n------------\n\nAuthor: Junio C Hamano <junkio@cox.net>\nDate:   Sat May 7 00:38:04 2005 -0700\n    \nIntroduce SHA1_FILE_DIRECTORIES to support multiple object databases.\n\nSHA1_FILE_DIRECTORIES environment variable is a colon separated paths\nused when looking for SHA1 files not found in the usual place for\nreading.  Creating a new SHA1 file does not use this alternate object\ndatabase location mechanism.  This is useful to archive older, rarely\nused objects into separate directories.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n--- a/cache.h\n+++ b/cache.h\n@@ -101,6 +101,7 @@ unsigned int active_nr, active_alloc, ac\n \n #define DB_ENVIRONMENT \"SHA1_FILE_DIRECTORY\"\n #define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n+#define ALTERNATE_DB_ENVIRONMENT \"SHA1_FILE_DIRECTORIES\"\n \n #define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)\n \n--- a/fsck-cache.c\n+++ b/fsck-cache.c\n@@ -306,7 +306,7 @@ int main(int argc, char **argv)\n \t\t\tusage(\"fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]\");\n \t}\n \n-\tsha1_dir = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n+\tsha1_dir = get_object_directory();\n \tfor (i = 0; i < 256; i++) {\n \t\tstatic char dir[4096];\n \t\tsprintf(dir, \"%s/%02x\", sha1_dir, i);\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -100,18 +100,34 @@ char * sha1_to_hex(const unsigned char *\n \treturn buffer;\n }\n \n+static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)\n+{\n+\tint i;\n+\tfor (i = 0; i < 20; i++) {\n+\t\tstatic char hex[] = \"0123456789abcdef\";\n+\t\tunsigned int val = sha1[i];\n+\t\tchar *pos = pathbuf + i*2 + (i > 0);\n+\t\t*pos++ = hex[val >> 4];\n+\t\t*pos = hex[val & 0xf];\n+\t}\n+}\n+\n /*\n  * NOTE! This returns a statically allocated buffer, so you have to be\n  * careful about using it. Do a \"strdup()\" if you need to save the\n  * filename.\n+ *\n+ * Also note that this returns the location for creating.  Reading\n+ * SHA1 file can happen from any alternate directory listed in the\n+ * SHA1_FILE_DIRECTORIES environment variable if it is not found in\n+ * the primary object database.\n  */\n char *sha1_file_name(const unsigned char *sha1)\n {\n-\tint i;\n \tstatic char *name, *base;\n \n \tif (!base) {\n-\t\tchar *sha1_file_directory = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;\n+\t\tchar *sha1_file_directory = get_object_directory();\n \t\tint len = strlen(sha1_file_directory);\n \t\tbase = xmalloc(len + 60);\n \t\tmemcpy(base, sha1_file_directory, len);\n@@ -120,16 +136,74 @@ char *sha1_file_name(const unsigned char\n \t\tbase[len+3] = '/';\n \t\tname = base + len + 1;\n \t}\n-\tfor (i = 0; i < 20; i++) {\n-\t\tstatic char hex[] = \"0123456789abcdef\";\n-\t\tunsigned int val = sha1[i];\n-\t\tchar *pos = name + i*2 + (i > 0);\n-\t\t*pos++ = hex[val >> 4];\n-\t\t*pos = hex[val & 0xf];\n-\t}\n+\tfill_sha1_path(name, sha1);\n \treturn base;\n }\n \n+static struct alternate_object_database\n+{\n+\tchar *base;\n+\tchar *name;\n+} *alt_odb;\n+\n+static void prepare_alt_odb(void)\n+{\n+\tint pass, totlen, i;\n+\tvoid *buf;\n+\tconst char *cp, *last;\n+\tchar *op = 0;\n+\tconst char *alt = getenv(ALTERNATE_DB_ENVIRONMENT) ? : \"\";\n+\n+\tfor (totlen = pass = 0; pass < 2; pass++) {\n+\t\tlast = alt;\n+\t\ti = 0;\n+\t\tdo {\n+\t\t\tcp = strchr(last, ':') ? : last + strlen(last);\n+\t\t\tif (last != cp) {\n+\t\t\t\t/* 43 = 40-byte + 2 '/' + terminating NUL */\n+\t\t\t\tint pfxlen = cp - last;\n+\t\t\t\tint entlen = pfxlen + 43;\n+\t\t\t\tif (pass == 0)\n+\t\t\t\t\ttotlen += entlen;\n+\t\t\t\telse {\n+\t\t\t\t\talt_odb[i].base = op;\n+\t\t\t\t\talt_odb[i].name = op + pfxlen + 1;\n+\t\t\t\t\tmemcpy(op, last, pfxlen);\n+\t\t\t\t\top[pfxlen] = op[pfxlen + 3] = '/';\n+\t\t\t\t\top[entlen-1] = 0;\n+\t\t\t\t\top += entlen;\n+\t\t\t\t}\n+\t\t\t\ti++;\n+\t\t\t}\n+\t\t\twhile (*cp && *cp == ':')\n+\t\t\t\tcp++;\n+\t\t\tlast = cp;\n+\t\t} while (*cp);\n+\t\tif (pass)\n+\t\t\tbreak;\n+\t\talt_odb = buf = xmalloc(sizeof(*alt_odb) * (i + 1) + totlen);\n+\t\talt_odb[i].base = alt_odb[i].name = 0;\n+\t\top = (char*)(&alt_odb[i+1]);\n+\t}\n+}\n+\n+static char *find_sha1_file(const unsigned char *sha1, struct stat *st)\n+{\n+\tint i;\n+\tchar *name = sha1_file_name(sha1);\n+\n+\tif (!stat(name, st))\n+\t\treturn name;\n+\tif (!alt_odb)\n+\t\tprepare_alt_odb();\n+\tfor (i = 0; (name = alt_odb[i].name) != NULL; i++) {\n+\t\tfill_sha1_path(name, sha1);\n+\t\tif (!stat(alt_odb[i].base, st))\n+\t\t\treturn alt_odb[i].base;\n+\t}\n+\treturn NULL;\n+}\n+\n int check_sha1_signature(unsigned char *sha1, void *map, unsigned long size, const char *type)\n {\n \tchar header[100];\n@@ -145,10 +219,15 @@ int check_sha1_signature(unsigned char *\n \n void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n {\n-\tchar *filename = sha1_file_name(sha1);\n \tstruct stat st;\n \tvoid *map;\n \tint fd;\n+\tchar *filename = find_sha1_file(sha1, &st);\n+\n+\tif (!filename) {\n+\t\terror(\"cannot map sha1 file %s\", sha1_to_hex(sha1));\n+\t\treturn NULL;\n+\t}\n \n \tfd = open(filename, O_RDONLY | sha1_file_open_flag);\n \tif (fd < 0) {\n@@ -167,10 +246,6 @@ void *map_sha1_file(const unsigned char \n \t\t/* If it failed once, it will probably fail again. Stop using O_NOATIME */\n \t\tsha1_file_open_flag = 0;\n \t}\n-\tif (fstat(fd, &st) < 0) {\n-\t\tclose(fd);\n-\t\treturn NULL;\n-\t}\n \tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);\n \tclose(fd);\n \tif (-1 == (int)(long)map)\n@@ -315,6 +390,7 @@ int write_sha1_file(char *buf, unsigned \n \t}\n \n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s/obj_XXXXXX\", get_object_directory());\n+\n \tfd = mkstemp(tmpfile);\n \tif (fd < 0) {\n \t\tfprintf(stderr, \"unable to create temporary sha1 filename %s: %s\", tmpfile, strerror(errno));\n@@ -442,12 +518,8 @@ int write_sha1_from_fd(const unsigned ch\n \n int has_sha1_file(const unsigned char *sha1)\n {\n-\tchar *filename = sha1_file_name(sha1);\n \tstruct stat st;\n-\n-\tif (!stat(filename, &st))\n-\t\treturn 1;\n-\treturn 0;\n+\treturn !!find_sha1_file(sha1, &st);\n }\n \n int index_fd(unsigned char *sha1, int fd, struct stat *st)\n\n\n\n\n"},{"id":"2877","messageId":"427F6693.2080707@zytor.com","threadId":"519","inReplyTo":"7vacn6ak7r.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-05-09T13:33:07Z","receivedAt":"2005-05-09T13:33:07Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Naming the environment variables SHA1_FILE_<anything> is almost \ncertainly wrong; a much more logical name would be GIT_<something>. \nIt'd also be much less likely to cause conflicts.\n\n\t-hpa\n"},{"id":"2890","messageId":"7vll6oz755.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"427F6693.2080707@zytor.com","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-09T16:38:46Z","receivedAt":"2005-05-09T16:38:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"HPA\" == H Peter Anvin <hpa@zytor.com> writes:\n\nHPA> Naming the environment variables SHA1_FILE_<anything> is almost\nHPA> certainly wrong; a much more logical name would be\nHPA> GIT_<something>. It'd also be much less likely to cause conflicts.\n\nExactly my feeling from the beginning.\n\nBut you have to realize that you are suggesting to change the\nSHA1_FILE_DIRECTORY that was there from almost the beginning as\nwell.  I know the code change required for the rename is\nminimum, but there are users involved.  My feeling is that we\nshould contain the damage by changing the definition of\nDB_ENVIRONMENT in cache.h sooner rather than later, but I do not\nthink this is the week to do it.\n\n\n"},{"id":"2889","messageId":"3087.10.10.10.24.1115656919.squirrel@linux1","threadId":"519","inReplyTo":"7vll6oz755.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-09T16:41:59Z","receivedAt":"2005-05-09T16:41:59Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Mon, May 9, 2005 12:38 pm, Junio C Hamano said:\n>>>>>> \"HPA\" == H Peter Anvin <hpa@zytor.com> writes:\n>\n> HPA> Naming the environment variables SHA1_FILE_<anything> is almost\n> HPA> certainly wrong; a much more logical name would be\n> HPA> GIT_<something>. It'd also be much less likely to cause conflicts.\n>\n> Exactly my feeling from the beginning.\n>\n> But you have to realize that you are suggesting to change the\n> SHA1_FILE_DIRECTORY that was there from almost the beginning as\n> well.  I know the code change required for the rename is\n> minimum, but there are users involved.  My feeling is that we\n> should contain the damage by changing the definition of\n> DB_ENVIRONMENT in cache.h sooner rather than later, but I do not\n> think this is the week to do it.\n>\n>\n\nWhat about creating a transition plan that uses the GIT_ name if it exists\nand the SHA1_ name if it doesn't.  And mark the SHA1_ name as depreciated.\n That should be okay to do this week, no?\n\nSean\n\n\n"},{"id":"2900","messageId":"427FA5FD.1050000@zytor.com","threadId":"519","inReplyTo":"3087.10.10.10.24.1115656919.squirrel@linux1","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-05-09T18:03:41Z","receivedAt":"2005-05-09T18:03:41Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Sean wrote:\n> \n> What about creating a transition plan that uses the GIT_ name if it exists\n> and the SHA1_ name if it doesn't.  And mark the SHA1_ name as depreciated.\n>  That should be okay to do this week, no?\n> \n\nShould work.\n\n\t-hpa\n"},{"id":"2904","messageId":"7vfywwz11t.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"427FA5FD.1050000@zytor.com","subject":"Re: [PATCH] Introduce SHA1_FILE_DIRECTORIES","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-09T18:50:22Z","receivedAt":"2005-05-09T18:50:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"HPA\" == H Peter Anvin <hpa@zytor.com> writes:\n\nHPA> Sean wrote:\n>> What about creating a transition plan that uses the GIT_ name if it\n>> exists\n>> and the SHA1_ name if it doesn't.  And mark the SHA1_ name as depreciated.\n>> That should be okay to do this week, no?\n>> \n\nHPA> Should work.\n\nThanks, both Sean and H. Peter.  Would cook something up.\n\n\n\n\n\n"},{"id":"2909","messageId":"7vhdhcxj0z.fsf_-_@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"7vfywwz11t.fsf@assigned-by-dhcp.cox.net","subject":"[RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-09T20:05:00Z","receivedAt":"2005-05-09T20:05:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"H. Peter Anvin mentioned that using SHA1_whatever as an\nenvironment variable name is not nice and we should instead use\nnames starting with \"GIT_\" prefix to avoid conflicts.\n\nHere is a patch, requesting for comments.\n\n - Renames the following environment variables:\n\n    New name                Old Name\n\n    GIT_AUTHOR_DATE         AUTHOR_DATE\n    GIT_AUTHOR_EMAIL        AUTHOR_EMAIL\n    GIT_AUTHOR_NAME         AUTHOR_NAME\n    GIT_COMMIT_AUTHOR_EMAIL COMMIT_AUTHOR_EMAIL\n    GIT_COMMIT_AUTHOR_NAME  COMMIT_AUTHOR_NAME\n    GIT_ALTERNATE_OBJECTS   SHA1_FILE_DIRECTORIES\n    GIT_OBJECTS             SHA1_FILE_DIRECTORY\n\n - Changes all users of the environment variable to fetch\n   environment variable with the new name.\n\n - Introduces a compatibility macro, gitenv(), which does an\n   getenv() and if it fails calls gitenv_bc(), which in turn\n   picks up the value from old name while giving a warning about\n   using an old name.\n\nI've also updated the documentation and scripts shipped with\nLinus GIT distribution.\n\nThe transition plan is as follows:\n\n - We will keep the backward compatibility list used by gitenv()\n   for now, so the current scripts and user environments\n   continue to work as before.  The users will get warnings when\n   they have old name but not new name in their environment to\n   the stderr.\n\n - The Porcelain layers should start using new names.  However,\n   just in case it ends up calling old Plumbing layer\n   implementation, they should also export old names, taking\n   values from the corresponding new names, during the\n   transition period.\n\n - After a couple of weeks or so, we would drop the\n   compatibility support and drop gitenv().  Revert the callers\n   to directly call getenv() but keep using the new names.\n\n   The last part is probably optional and the transition\n   duration needs to be set to a reasonable value.\n\nNot-quite-signed-off-yet-by: Junio C Hamano <junkio@cox.net>\n------------\n\nDocumentation/core-git.txt |   17 +++++-----\nMakefile                   |    3 +\nREADME                     |    2 -\ncache.h                    |   15 +++++++--\ncommit-tree.c              |   10 +++---\ndiff.c                     |   10 +++---\ngit-prune-script           |    8 +++--\ngitenv.c                   |   70 +++++++++++++++++++++++++++++++++++++++++++++\ninit-db.c                  |    7 ++--\nrsh.c                      |    4 +-\nsha1_file.c                |    8 ++---\n11 files changed, 120 insertions(+), 34 deletions(-)\n\n# - HEAD: Fix git-update-cache --cacheinfo error message.\n# + 7: Rename Environment Variables\n--- a/Documentation/core-git.txt\n+++ b/Documentation/core-git.txt\n@@ -210,15 +210,16 @@ Environment Variables\n ---------------------\n Various git commands use the following environment variables:\n \n-- 'AUTHOR_NAME'\n-- 'AUTHOR_EMAIL'\n-- 'AUTHOR_DATE'\n-- 'COMMIT_AUTHOR_NAME'\n-- 'COMMIT_AUTHOR_EMAIL'\n+- 'GIT_AUTHOR_NAME'\n+- 'GIT_AUTHOR_EMAIL'\n+- 'GIT_AUTHOR_DATE'\n+- 'GIT_COMMIT_AUTHOR_NAME'\n+- 'GIT_COMMIT_AUTHOR_EMAIL'\n - 'GIT_DIFF_OPTS'\n - 'GIT_EXTERNAL_DIFF'\n - 'GIT_INDEX_FILE'\n-- 'SHA1_FILE_DIRECTORY'\n+- 'GIT_OBJECTS'\n+- 'GIT_ALTERNATE_OBJECTS'\n \n \n NAME\n@@ -876,7 +877,7 @@ sha1 mismatch <object>::\n Environment Variables\n ---------------------\n \n-SHA1_FILE_DIRECTORY::\n+GIT_OBJECTS::\n \tused to specify the object database root (usually .git/objects)\n \n GIT_INDEX_FILE::\n@@ -918,7 +919,7 @@ DESCRIPTION\n This simply creates an empty git object database - basically a `.git`\n directory and `.git/object/??/` directories.\n \n-If the object storage directory is specified via the 'SHA1_FILE_DIRECTORY'\n+If the object storage directory is specified via the 'GIT_OBJECTS'\n environment variable then the sha1 directories are created underneath -\n otherwise the default `.git/objects` directory is used.\n \n--- a/Makefile\n+++ b/Makefile\n@@ -46,6 +46,8 @@ LIB_OBJS += strbuf.o\n LIB_H += diff.h\n LIB_OBJS += diff.o\n \n+LIB_OBJS += gitenv.o\n+\n LIBS = $(LIB_FILE)\n LIBS += -lz\n \n@@ -116,6 +118,7 @@ sha1_file.o: $(LIB_H)\n usage.o: $(LIB_H)\n diff.o: $(LIB_H)\n strbuf.o: $(LIB_H)\n+gitenv.o: $(LIB_H)\n \n clean:\n \trm -f *.o mozilla-sha1/*.o ppc/*.o $(PROG) $(LIB_FILE)\n--- a/README\n+++ b/README\n@@ -24,7 +24,7 @@ There are two object abstractions: the \"\n \n \n \n-\tThe Object Database (SHA1_FILE_DIRECTORY)\n+\tThe Object Database (GIT_OBJECTS)\n \n \n The object database is literally just a content-addressable collection\n--- a/cache.h\n+++ b/cache.h\n@@ -31,6 +31,13 @@\n #endif\n \n /*\n+ * Environment variables transition.\n+ * We accept older names for now but warn.\n+ */\n+extern char *gitenv_bc(const char *);\n+#define gitenv(e) (getenv(e) ? : gitenv_bc(e))\n+\n+/*\n  * Basic data structures for the directory cache\n  *\n  * NOTE NOTE NOTE! This is all in the native CPU byte format. It's\n@@ -99,16 +106,16 @@ static inline unsigned int create_ce_mod\n struct cache_entry **active_cache;\n unsigned int active_nr, active_alloc, active_cache_changed;\n \n-#define DB_ENVIRONMENT \"SHA1_FILE_DIRECTORY\"\n+#define DB_ENVIRONMENT \"GIT_OBJECTS\"\n #define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n-#define ALTERNATE_DB_ENVIRONMENT \"SHA1_FILE_DIRECTORIES\"\n+#define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECTS\"\n \n-#define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)\n+#define get_object_directory() (gitenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)\n \n #define INDEX_ENVIRONMENT \"GIT_INDEX_FILE\"\n #define DEFAULT_INDEX_ENVIRONMENT \".git/index\"\n \n-#define get_index_file() (getenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)\n+#define get_index_file() (gitenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)\n \n #define alloc_nr(x) (((x)+16)*3/2)\n \n--- a/commit-tree.c\n+++ b/commit-tree.c\n@@ -146,11 +146,11 @@ int main(int argc, char **argv)\n \tdatestamp(realdate, sizeof(realdate));\n \tstrcpy(date, realdate);\n \n-\tcommitgecos = getenv(\"COMMIT_AUTHOR_NAME\") ? : realgecos;\n-\tcommitemail = getenv(\"COMMIT_AUTHOR_EMAIL\") ? : realemail;\n-\tgecos = getenv(\"AUTHOR_NAME\") ? : realgecos;\n-\temail = getenv(\"AUTHOR_EMAIL\") ? : realemail;\n-\taudate = getenv(\"AUTHOR_DATE\");\n+\tcommitgecos = gitenv(\"GIT_COMMIT_AUTHOR_NAME\") ? : realgecos;\n+\tcommitemail = gitenv(\"GIT_COMMIT_AUTHOR_EMAIL\") ? : realemail;\n+\tgecos = gitenv(\"GIT_AUTHOR_NAME\") ? : realgecos;\n+\temail = gitenv(\"GIT_AUTHOR_EMAIL\") ? : realemail;\n+\taudate = gitenv(\"GIT_AUTHOR_DATE\");\n \tif (audate)\n \t\tparse_date(audate, date, sizeof(date));\n \n--- a/diff.c\n+++ b/diff.c\n@@ -8,11 +8,11 @@\n #include \"cache.h\"\n #include \"diff.h\"\n \n-static char *diff_opts = \"-pu\";\n+static const char *diff_opts = \"-pu\";\n \n static const char *external_diff(void)\n {\n-\tstatic char *external_diff_cmd = NULL;\n+\tstatic const char *external_diff_cmd = NULL;\n \tstatic int done_preparing = 0;\n \n \tif (done_preparing)\n@@ -26,11 +26,11 @@ static const char *external_diff(void)\n \t *\n \t * GIT_DIFF_OPTS=\"-c\";\n \t */\n-\tif (getenv(\"GIT_EXTERNAL_DIFF\"))\n-\t\texternal_diff_cmd = getenv(\"GIT_EXTERNAL_DIFF\");\n+\tif (gitenv(\"GIT_EXTERNAL_DIFF\"))\n+\t\texternal_diff_cmd = gitenv(\"GIT_EXTERNAL_DIFF\");\n \n \t/* In case external diff fails... */\n-\tdiff_opts = getenv(\"GIT_DIFF_OPTS\") ? : diff_opts;\n+\tdiff_opts = gitenv(\"GIT_DIFF_OPTS\") ? : diff_opts;\n \n \tdone_preparing = 1;\n \treturn external_diff_cmd;\n--- a/git-prune-script\n+++ b/git-prune-script\n@@ -28,9 +28,13 @@ sed -ne '/unreachable /{\n     s/unreachable [^ ][^ ]* //\n     s|\\(..\\)|\\1/|p\n }' | {\n-\tcase \"$SHA1_FILE_DIRECTORY\" in\n+\tfor d in \"$GIT_OBJECTS\" \"$SHA1_FILE_DIRECTORY\" ''\n+\tdo\n+\t\ttest \"$d\" != \"\" && test -d \"$d\" && break\n+\tdone\n+\tcase \"$d\" in\n \t'') cd .git/objects/ ;;\n-\t*) cd \"$SHA1_FILE_DIRECTORY\" ;;\n+\t*) cd \"$d\" ;;\n \tesac || exit\n \txargs -r $dryrun rm -f\n }\nCreated: gitenv.c (mode:100644)\n--- /dev/null\n+++ b/gitenv.c\n@@ -0,0 +1,70 @@\n+#include \"cache.h\"\n+\n+/*\n+ * This array must be sorted by its canonical name, because\n+ * we do look-up by binary search.\n+ */\n+static struct backward_compatible_env {\n+\tconst char *canonical;\n+\tconst char *old;\n+} bc_name[] = {\n+\t{ \"GIT_ALTERNATE_OBJECTS\", \"SHA1_FILE_DIRECTORIES\" },\n+\t{ \"GIT_AUTHOR_DATE\", \"AUTHOR_DATE\" },\n+\t{ \"GIT_AUTHOR_EMAIL\", \"AUTHOR_EMAIL\" },\n+\t{ \"GIT_AUTHOR_NAME\", \"AUTHOR_NAME\" }, \n+\t{ \"GIT_COMMIT_AUTHOR_EMAIL\", \"COMMIT_AUTHOR_EMAIL\" },\n+\t{ \"GIT_COMMIT_AUTHOR_NAME\", \"COMMIT_AUTHOR_NAME\" },\n+\t{ \"GIT_OBJECTS\", \"SHA1_FILE_DIRECTORY\" },\n+};\n+\n+static void warn_old_environment(void)\n+{\n+\tint i;\n+\tstatic int warned = 0;\n+\tif (warned)\n+\t\treturn;\n+\n+\twarned = 1;\n+\tfprintf(stderr,\n+\t\t\"warning: GIT environment variables have been renamed.\\n\"\n+\t\t\"warning: Please adjust your scripts and environment.\\n\");\n+\tfor (i = 0; i < sizeof(bc_name) / sizeof(bc_name[0]); i++) {\n+\t\t/* warning is needed only when old name is there and\n+\t\t * new name is not.\n+\t\t */\n+\t\tif (!getenv(bc_name[i].canonical) && getenv(bc_name[i].old))\n+\t\t\tfprintf(stderr, \"warning: old %s => new %s\\n\",\n+\t\t\t\tbc_name[i].old, bc_name[i].canonical);\n+\t}\n+}\n+\n+char *gitenv_bc(const char *e)\n+{\n+\tint first, last;\n+\tchar *val = getenv(e);\n+\tif (val)\n+\t\t/* inefficient.  caller should use gitenv() not gitenv_bc() */\n+\t\treturn val;\n+\n+\tfirst = 0;\n+\tlast = sizeof(bc_name) / sizeof(bc_name[0]);\n+\twhile (last > first) {\n+\t\tint next = (last + first) >> 1;\n+\t\tint cmp = strcmp(e, bc_name[next].canonical);\n+\t\tif (!cmp) {\n+\t\t\tval = getenv(bc_name[next].old);\n+\t\t\t/* If the user has only old name, warn.\n+\t\t\t * otherwise stay silent.\n+\t\t\t */\n+\t\t\tif (val)\n+\t\t\t\twarn_old_environment();\n+\t\t\treturn val;\n+\t\t}\n+\t\tif (cmp < 0) {\n+\t\t\tlast = next;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfirst = next+1;\n+\t}\n+\treturn NULL;\n+}\n--- a/init-db.c\n+++ b/init-db.c\n@@ -5,7 +5,7 @@\n  */\n #include \"cache.h\"\n \n-void safe_create_dir(char *dir)\n+void safe_create_dir(const char *dir)\n {\n \tif (mkdir(dir, 0755) < 0) {\n \t\tif (errno != EEXIST) {\n@@ -23,12 +23,13 @@ void safe_create_dir(char *dir)\n  */\n int main(int argc, char **argv)\n {\n-\tchar *sha1_dir, *path;\n+\tconst char *sha1_dir;\n+\tchar *path;\n \tint len, i;\n \n \tsafe_create_dir(\".git\");\n \n-\tsha1_dir = getenv(DB_ENVIRONMENT);\n+\tsha1_dir = gitenv(DB_ENVIRONMENT);\n \tif (!sha1_dir) {\n \t\tsha1_dir = DEFAULT_DB_ENVIRONMENT;\n \t\tfprintf(stderr, \"defaulting to local storage area\\n\");\n--- a/rsh.c\n+++ b/rsh.c\n@@ -36,8 +36,8 @@ int setup_connection(int *fd_in, int *fd\n \t*(path++) = '\\0';\n \t/* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */\n \tsnprintf(command, COMMAND_SIZE, \n-\t\t \"cd /%s; SHA1_FILE_DIRECTORY=objects %s\",\n-\t\t path, remote_prog);\n+\t\t \"cd /%s; %s=objects %s\",\n+\t\t path, DB_ENVIRONMENT, remote_prog);\n \tposn = command + strlen(command);\n \tfor (i = 0; i < rmt_argc; i++) {\n \t\t*(posn++) = ' ';\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -120,7 +120,7 @@ static void fill_sha1_path(char *pathbuf\n  *\n  * Also note that this returns the location for creating.  Reading\n  * SHA1 file can happen from any alternate directory listed in the\n- * SHA1_FILE_DIRECTORIES environment variable if it is not found in\n+ * DB_ENVIRONMENT environment variable if it is not found in\n  * the primary object database.\n  */\n char *sha1_file_name(const unsigned char *sha1)\n@@ -128,7 +128,7 @@ char *sha1_file_name(const unsigned char\n \tstatic char *name, *base;\n \n \tif (!base) {\n-\t\tchar *sha1_file_directory = get_object_directory();\n+\t\tconst char *sha1_file_directory = get_object_directory();\n \t\tint len = strlen(sha1_file_directory);\n \t\tbase = xmalloc(len + 60);\n \t\tmemcpy(base, sha1_file_directory, len);\n@@ -151,7 +151,7 @@ static struct alternate_object_database \n  * alt_odb points at an array of struct alternate_object_database.\n  * This array is terminated with an element that has both its base\n  * and name set to NULL.  alt_odb[n] comes from n'th non-empty\n- * element from colon separated $SHA1_FILE_DIRECTORIES environment\n+ * element from colon separated ALTERNATE_DB_ENVIRONMENT environment\n  * variable, and its base points at a statically allocated buffer\n  * that contains \"/the/directory/corresponding/to/.git/objects/...\",\n  * while its name points just after the slash at the end of\n@@ -167,7 +167,7 @@ static void prepare_alt_odb(void)\n \tint pass, totlen, i;\n \tconst char *cp, *last;\n \tchar *op = 0;\n-\tconst char *alt = getenv(ALTERNATE_DB_ENVIRONMENT) ? : \"\";\n+\tconst char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : \"\";\n \n \t/* The first pass counts how large an area to allocate to\n \t * hold the entire alt_odb structure, including array of\n\n"},{"id":"2910","messageId":"20050509201520.GL24216@cip.informatik.uni-erlangen.de","threadId":"519","inReplyTo":"7vhdhcxj0z.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Thomas Glanzmann","fromEmail":"sithglan@stud.uni-erlangen.de","sentAt":"2005-05-09T20:15:20Z","receivedAt":"2005-05-09T20:15:20Z","isPatch":false,"sender":{"key":"sithglan@stud.uni-erlangen.de","avatar":null},"body":"Hello,\n\n> Here is a patch, requesting for comments.\n\nsounds good. But I would forget about downward compatibility. There is\nno need to maintain it at this early stage.\n\nAnd one thing which bothers me all the time but never spoke up about it:\nThere is no way to provide a GIT_COMMIT_DATE. This would be useful for\nvendortracking a CVS repository for example.\n\nAnd personally I think GIT_COMMIT_AUTHOR_EMAIL and\nGIT_COMMIT_AUTHOR_NAME are to long what about\nGIT_COMMITTER_{NAME,EMAIL}?  Whatever. You script them or put them in\nyour environment anyway so no big issue.\n\n\tThomas\n"},{"id":"2911","messageId":"3677.10.10.10.24.1115672678.squirrel@linux1","threadId":"519","inReplyTo":"7vhdhcxj0z.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2005-05-09T21:04:38Z","receivedAt":"2005-05-09T21:04:38Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Mon, May 9, 2005 4:05 pm, Junio C Hamano said:\n> H. Peter Anvin mentioned that using SHA1_whatever as an\n> environment variable name is not nice and we should instead use\n> names starting with \"GIT_\" prefix to avoid conflicts.\n>\n> Here is a patch, requesting for comments.\n\nJunio,\n\nLook quite good; you made short work of that!\n\nHowever I don't understand your gitenv_bc, wouldn't the following suffice?\n\nchar *gitenv_bc(const char *e)\n{\n        int i;\n        char *val = getenv(e);\n        if (val)\n                return val;\n\n        for (i=0; i < sizeof(bc_name) / sizeof(bc_name[0]); ++i) {\n                if (!strcmp(e, bc_name[i].canonical)) {\n                        if (val = getenv(bc_name[i].old))\n                                warn_old_environment();\n                        return val;\n                }\n        }\n        return NULL;\n}\n\n\nCheers,\nSean\n\n\n"},{"id":"2923","messageId":"Pine.LNX.4.21.0505091847050.30848-100000@iabervon.org","threadId":"519","inReplyTo":"7vhdhcxj0z.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-05-09T23:08:20Z","receivedAt":"2005-05-09T23:08:20Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 9 May 2005, Junio C Hamano wrote:\n\n> H. Peter Anvin mentioned that using SHA1_whatever as an\n> environment variable name is not nice and we should instead use\n> names starting with \"GIT_\" prefix to avoid conflicts.\n> \n> Here is a patch, requesting for comments.\n> \n>  - Renames the following environment variables:\n> \n>     New name                Old Name\n> \n>     GIT_AUTHOR_DATE         AUTHOR_DATE\n>     GIT_AUTHOR_EMAIL        AUTHOR_EMAIL\n>     GIT_AUTHOR_NAME         AUTHOR_NAME\n>     GIT_COMMIT_AUTHOR_EMAIL COMMIT_AUTHOR_EMAIL\n>     GIT_COMMIT_AUTHOR_NAME  COMMIT_AUTHOR_NAME\n>     GIT_ALTERNATE_OBJECTS   SHA1_FILE_DIRECTORIES\n>     GIT_OBJECTS             SHA1_FILE_DIRECTORY\n\nWhile we're at it, it would be useful to have one for what is normally\n\".git\", rather than just \".git/objects\". That way the same variable would\nbe useful for finding other things in the .git directory, and I haven't\nheard of any use of SHA1_FILE_DIRECTORY that didn't end in /objects\nanyway, and would enable the brokenness in init-db (it creates \".git\", and\nthen tries to create \"<obj-dir>/00-ff\").\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"2928","messageId":"7v7ji8vt5c.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"Pine.LNX.4.21.0505091847050.30848-100000@iabervon.org","subject":"Re: [RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T00:09:19Z","receivedAt":"2005-05-10T00:09:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n\nDB> While we're at it, it would be useful to have one for what is normally\nDB> \".git\",...\n\nIf you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\nyour only gripe is about git-init-db creating \".git\" in the\ncurrent working directory regardless of SHA1_FILE_DIRECTORY, I\nwould agree that what git-init-db does is broken.  Not that I\nhave a suggested \"right behaviour\" for it, though.\n\nHowever if you also mean by \".git\" the directory refs/heads and\nfriends hang underneath, then I have to disagree.  That does not\nbelong to core GIT, which always expects to run from the top\nlevel directory that has such directory directly under it, and\nat the same time corresponds to the tree structure the dircache\ndescribes.  There is no need for the environment variable you\nsuggest, since it always is the \".git\" subdirectory of such a\ndirectory.\n\nI once advocated GIT_WORKING_TREE to mean the current project\ntop, which is the parent directory of \".git\".  The proposal was\nshot down (see archives [*1*]).  While I still think that\nconfiguration (or your \".git\" location proposal, which is\nessentially the equivalent) may sometimes useful, I'd rather not\nconflate this environment variable renames with that issue.\nThey are pretty much independent issues.\n\n[References]\n*1* http://marc.theaimsgroup.com/?l=git&m=111412959320946&w=2\n\n"},{"id":"2929","messageId":"20050510001351.GH15712@pasky.ji.cz","threadId":"519","inReplyTo":"7v7ji8vt5c.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-10T00:13:51Z","receivedAt":"2005-05-10T00:13:51Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, May 10, 2005 at 02:09:19AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> told me that...\n> If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\n> your only gripe is about git-init-db creating \".git\" in the\n> current working directory regardless of SHA1_FILE_DIRECTORY, I\n> would agree that what git-init-db does is broken.  Not that I\n> have a suggested \"right behaviour\" for it, though.\n> \n> However if you also mean by \".git\" the directory refs/heads and\n> friends hang underneath, then I have to disagree.  That does not\n> belong to core GIT, which always expects to run from the top\n> level directory that has such directory directly under it, and\n> at the same time corresponds to the tree structure the dircache\n> describes.  There is no need for the environment variable you\n> suggest, since it always is the \".git\" subdirectory of such a\n> directory.\n\nI think it would be nice to have something like GIT_BASEDIR, which would\ndefault to .git, and the objects directory would then default to\n$GIT_BASEDIR/objects and the index file would default to\n$GIT_BASEDIR/index.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2930","messageId":"7vzmv4udyx.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"20050510001351.GH15712@pasky.ji.cz","subject":"Re: [RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T00:22:30Z","receivedAt":"2005-05-10T00:22:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n\nPB> I think it would be nice to have something like GIT_BASEDIR,\nPB> which would default to .git, and the objects directory would\nPB> then default to $GIT_BASEDIR/objects and the index file\nPB> would default to $GIT_BASEDIR/index.\n\nYes and no.  While I agree that having more things customizable\nmay be nicer than not having them, I do not see what GIT_BASEDIR\nbuys us.  That is, I cannot come up with a good use scenario\nthat would be helped by having that environment variable.\n\nExcept that you do not have to specify GIT_OBJECTS and\nGIT_INDEX_FILE separately, that is.  Is it what you are aiming\nfor?\n\n"},{"id":"2931","messageId":"20050510002548.GI15712@pasky.ji.cz","threadId":"519","inReplyTo":"7vhdhcxj0z.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-10T00:25:48Z","receivedAt":"2005-05-10T00:25:48Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, May 09, 2005 at 10:05:00PM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> told me that...\n>  - Renames the following environment variables:\n> \n>     New name                Old Name\n> \n>     GIT_AUTHOR_DATE         AUTHOR_DATE\n>     GIT_AUTHOR_EMAIL        AUTHOR_EMAIL\n>     GIT_AUTHOR_NAME         AUTHOR_NAME\n>     GIT_COMMIT_AUTHOR_EMAIL COMMIT_AUTHOR_EMAIL\n>     GIT_COMMIT_AUTHOR_NAME  COMMIT_AUTHOR_NAME\n>     GIT_ALTERNATE_OBJECTS   SHA1_FILE_DIRECTORIES\n>     GIT_OBJECTS             SHA1_FILE_DIRECTORY\n\nCould I please have s/COMMIT_AUTHOR/COMMITTER/ and\ns/OBJECTS/(OBJDIR|OBJECT_DIR)/?\n\n> The transition plan is as follows:\n> \n>  - We will keep the backward compatibility list used by gitenv()\n>    for now, so the current scripts and user environments\n>    continue to work as before.  The users will get warnings when\n>    they have old name but not new name in their environment to\n>    the stderr.\n> \n>  - The Porcelain layers should start using new names.  However,\n>    just in case it ends up calling old Plumbing layer\n>    implementation, they should also export old names, taking\n>    values from the corresponding new names, during the\n>    transition period.\n\n(Cogito needs its own git-merge-cache so that the merge goes properly\nanyway, and it already (or still) carries its Git around, so I think\nit's not applicable to it. Yes, I want and plan to start publishing the\nGit changes, I'm already making some steps for that and I hope I have\nsomething to show by tomorrow.)\n\n>  - After a couple of weeks or so, we would drop the\n>    compatibility support and drop gitenv().  Revert the callers\n>    to directly call getenv() but keep using the new names.\n> \n>    The last part is probably optional and the transition\n>    duration needs to be set to a reasonable value.\n\nYes, I think couple of weeks is too long. :-) I'd say one or two\nreleases is enough.\n\n> --- /dev/null\n> +++ b/gitenv.c\n\nPretty please, add copyright notices at the top of files.\n\n> +char *gitenv_bc(const char *e)\n> +{\n> +\tint first, last;\n> +\tchar *val = getenv(e);\n> +\tif (val)\n> +\t\t/* inefficient.  caller should use gitenv() not gitenv_bc() */\n> +\t\treturn val;\n\nCan this ever happen? If doing it at all, I'd expect gitenv_bc() to\nrather freak out and die(), the caller is broken.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2932","messageId":"20050510002736.GJ15712@pasky.ji.cz","threadId":"519","inReplyTo":"7vzmv4udyx.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-10T00:27:36Z","receivedAt":"2005-05-10T00:27:36Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, May 10, 2005 at 02:22:30AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> told me that...\n> Except that you do not have to specify GIT_OBJECTS and\n> GIT_INDEX_FILE separately, that is.  Is it what you are aiming\n> for?\n\nYes. Having less things to specify is better. What if another directory\nwill be added to the git repository? Everything which wants to work with\nsomething else than .git will be broken just because of this.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2933","messageId":"20050510003235.GK15712@pasky.ji.cz","threadId":"519","inReplyTo":"20050509201520.GL24216@cip.informatik.uni-erlangen.de","subject":"Re: [RFC] Renaming environment variables.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-10T00:32:35Z","receivedAt":"2005-05-10T00:32:35Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, May 09, 2005 at 10:15:20PM CEST, I got a letter\nwhere Thomas Glanzmann <sithglan@stud.uni-erlangen.de> told me that...\n> > Here is a patch, requesting for comments.\n> \n> sounds good. But I would forget about downward compatibility. There is\n> no need to maintain it at this early stage.\n\nSure there is. We are actually far from an early stage now, I'd say.\n\nAnd what I don't want to see are commits with messed up author\ninformation since people upgraded and did not notice.\n\n> And one thing which bothers me all the time but never spoke up about it:\n> There is no way to provide a GIT_COMMIT_DATE. This would be useful for\n> vendortracking a CVS repository for example.\n\nYou could use GIT_AUTHOR_DATE. :-)\n\nBut yes, I actually agree. When you are doing vendortracking of CVS\nrepository, you have one canonical source of the commit, and when you do\nthe CVS import twice independently, I think you _want_ the same commit,\nsince it _is_ the same commit after all (if the history is same too,\nobviously).\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2936","messageId":"Pine.LNX.4.21.0505092012340.30848-100000@iabervon.org","threadId":"519","inReplyTo":"7v7ji8vt5c.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-05-10T00:38:53Z","receivedAt":"2005-05-10T00:38:53Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 9 May 2005, Junio C Hamano wrote:\n\n> >>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n> \n> DB> While we're at it, it would be useful to have one for what is normally\n> DB> \".git\",...\n> \n> If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\n> your only gripe is about git-init-db creating \".git\" in the\n> current working directory regardless of SHA1_FILE_DIRECTORY, I\n> would agree that what git-init-db does is broken.  Not that I\n> have a suggested \"right behaviour\" for it, though.\n\nIt could just create all missing parents of the object directory, which\nwould be better, at least.\n\n> However if you also mean by \".git\" the directory refs/heads and\n> friends hang underneath, then I have to disagree.  That does not\n> belong to core GIT, which always expects to run from the top\n> level directory that has such directory directly under it, and\n> at the same time corresponds to the tree structure the dircache\n> describes.  There is no need for the environment variable you\n> suggest, since it always is the \".git\" subdirectory of such a\n> directory.\n\nSo far, I have never heard of SHA1_FILE_DIRECTORY being used to target\nsomething in .git other than objects. The only use of SHA1_FILE_DIRECTORY\nI've heard about is my own in rsh.c, which sets it to [PATH]/objects,\nbecause it has to write object files, most often, to\n.../project.git/objects/. You can't really cd to /scm/git<delete> and have\n.git/objects refer to the right thing.\n\nMy position is still that what refs/*/* gets used for is up to the user,\nbut the existance and format of the directory is a core thing. In\nparticular, I want to have atomic methods of modifying these files. (I.e.,\nyou give commit-cache a */* to write the result to, and it will make sure\nthat nobody writes to it or reads it expecting to write to it while you're\ncommitting).\n\nBut even if this is up to the wrapping scripts, it would be useful to have\nthe same environment variable used by those scripts for whatever they want\nto have in there.\n\n> I once advocated GIT_WORKING_TREE to mean the current project\n> top, which is the parent directory of \".git\".  The proposal was\n> shot down (see archives [*1*]).  While I still think that\n> configuration (or your \".git\" location proposal, which is\n> essentially the equivalent) may sometimes useful, I'd rather not\n> conflate this environment variable renames with that issue.\n> They are pretty much independent issues.\n\nThe reason to tackle them at once is so that there doesn't have to be\nmultiple changeovers.\n\n> [References]\n> *1* http://marc.theaimsgroup.com/?l=git&m=111412959320946&w=2\n\nI believe that Linus's primary gripe was about changing the expected\nlocation of the working tree, not about changing the expected location of\nthe git storage. So the .git location proposal is quite different.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"2937","messageId":"20050510004431.GM15712@pasky.ji.cz","threadId":"519","inReplyTo":"Pine.LNX.4.21.0505092012340.30848-100000@iabervon.org","subject":"Re: [RFC] Renaming environment variables.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-10T00:44:31Z","receivedAt":"2005-05-10T00:44:31Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, May 10, 2005 at 02:38:53AM CEST, I got a letter\nwhere Daniel Barkalow <barkalow@iabervon.org> told me that...\n> On Mon, 9 May 2005, Junio C Hamano wrote:\n> \n> > >>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n> > \n> > DB> While we're at it, it would be useful to have one for what is normally\n> > DB> \".git\",...\n> > \n> > If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\n> > your only gripe is about git-init-db creating \".git\" in the\n> > current working directory regardless of SHA1_FILE_DIRECTORY, I\n> > would agree that what git-init-db does is broken.  Not that I\n> > have a suggested \"right behaviour\" for it, though.\n> \n> It could just create all missing parents of the object directory, which\n> would be better, at least.\n\nWhat about the index file? Or should git-read-tree take care of that?\n\n> But even if this is up to the wrapping scripts, it would be useful to have\n> the same environment variable used by those scripts for whatever they want\n> to have in there.\n\nSeconded. That is another good reason for having that.\n\n> > I once advocated GIT_WORKING_TREE to mean the current project\n> > top, which is the parent directory of \".git\".  The proposal was\n> > shot down (see archives [*1*]).  While I still think that\n> > configuration (or your \".git\" location proposal, which is\n> > essentially the equivalent) may sometimes useful, I'd rather not\n> > conflate this environment variable renames with that issue.\n> > They are pretty much independent issues.\n> \n> The reason to tackle them at once is so that there doesn't have to be\n> multiple changeovers.\n\nThere should be no changeovers, just additions - the object directory\nand index file location environment variables should stay too.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2938","messageId":"Pine.LNX.4.21.0505092047190.30848-100000@iabervon.org","threadId":"519","inReplyTo":"20050510004431.GM15712@pasky.ji.cz","subject":"Re: [RFC] Renaming environment variables.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-05-10T00:53:19Z","receivedAt":"2005-05-10T00:53:19Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 10 May 2005, Petr Baudis wrote:\n\n> Dear diary, on Tue, May 10, 2005 at 02:38:53AM CEST, I got a letter\n> where Daniel Barkalow <barkalow@iabervon.org> told me that...\n> > On Mon, 9 May 2005, Junio C Hamano wrote:\n> > \n> > > >>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n> > > \n> > > DB> While we're at it, it would be useful to have one for what is normally\n> > > DB> \".git\",...\n> > > \n> > > If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\n> > > your only gripe is about git-init-db creating \".git\" in the\n> > > current working directory regardless of SHA1_FILE_DIRECTORY, I\n> > > would agree that what git-init-db does is broken.  Not that I\n> > > have a suggested \"right behaviour\" for it, though.\n> > \n> > It could just create all missing parents of the object directory, which\n> > would be better, at least.\n> \n> What about the index file? Or should git-read-tree take care of that?\n\nProbably whatever writes the index file should take care of making sure it\ncan be written (if possible).\n\n> > > I once advocated GIT_WORKING_TREE to mean the current project\n> > > top, which is the parent directory of \".git\".  The proposal was\n> > > shot down (see archives [*1*]).  While I still think that\n> > > configuration (or your \".git\" location proposal, which is\n> > > essentially the equivalent) may sometimes useful, I'd rather not\n> > > conflate this environment variable renames with that issue.\n> > > They are pretty much independent issues.\n> > \n> > The reason to tackle them at once is so that there doesn't have to be\n> > multiple changeovers.\n> \n> There should be no changeovers, just additions - the object directory\n> and index file location environment variables should stay too.\n\nDefinitely true of the index file, since people actually write different\nones. I'm not sure if there's a real use for specifying something\ndifferent for the objects directory than BASE + objects, though.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"2939","messageId":"7vk6m7vqph.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"20050510002548.GI15712@pasky.ji.cz","subject":"Re: [RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T01:02:02Z","receivedAt":"2005-05-10T01:02:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n\nPB> Could I please have s/COMMIT_AUTHOR/COMMITTER/ and\nPB> s/OBJECTS/(OBJDIR|OBJECT_DIR)/?\n\nThe former sounds much better.  The latter how about\nGIT_OBJECT_DIRECTORY?  Not much longer than the original\nSHA1_FILE_DIRECTORY anyway.\n\nPB> (Cogito needs its own git-merge-cache so that the merge goes properly\nPB> anyway, and it already (or still) carries its Git around, so I think\nPB> it's not applicable to it. Yes, I want and plan to start publishing the\nPB> Git changes, I'm already making some steps for that and I hope I have\nPB> something to show by tomorrow.)\n\nSounds good.  BTW, what happened to the plan of merging with my\ntip you sent a message earlier about?\n\nPB> Yes, I think couple of weeks is too long. :-) I'd say one or two\nPB> releases is enough.\n\nI'd leave that to community and Linus to decide when he returns.\n\nPB> Pretty please, add copyright notices at the top of files.\n\nThanks for pointing it out.\n\n>> +char *gitenv_bc(const char *e)\n>> +{\n>> +\tint first, last;\n>> +\tchar *val = getenv(e);\n>> +\tif (val)\n>> +\t\t/* inefficient.  caller should use gitenv() not gitenv_bc() */\n>> +\t\treturn val;\n\nPB> Can this ever happen? If doing it at all, I'd expect gitenv_bc() to\nPB> rather freak out and die(), the caller is broken.\n\nPoint taken.\n\nI've pushed out an updated version that addresses all of the\nabove issues to git-jc repository [*1*].  Please take a look.\n\n[References]\n*1* http://members.cox.net/junkio/\n\n\n"},{"id":"2942","messageId":"7vy8anu8po.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"Pine.LNX.4.21.0505091847050.30848-100000@iabervon.org","subject":"Re: [RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T02:16:03Z","receivedAt":"2005-05-10T02:16:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n>>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n\nDB> While we're at it, it would be useful to have one for what is normally\nDB> \".git\", rather than just \".git/objects\".\n\nPB> I think it would be nice to have something like GIT_BASEDIR, which would\nPB> default to .git, and the objects directory would then default to\nPB> $GIT_BASEDIR/objects and the index file would default to\nPB> $GIT_BASEDIR/index.\n\nAlthough what I pushed out at git-jc repository does not have\nthis, it does not mean I forgot this issue you two have raised,\nnor would want to veto it or anything like that.  Just that,\nunlike the one that I already committed, the proposed change\nwould touch rather many lines and I have not managed to\ndetermine the extent of the damage yet.\n\nI am willing to make (or take) a separate patch to do this one,\nsince I agree with Petr's \"currently we happen to have just two\nbut it would still be better to be able to set just one than\nhaving to change both of them in sync.\" argument.\n\nI am currently waiting for community consensus, including the\nfinal name of the variable.  I think the current consensus is\nthat this is a good idea, the semantics for it is to name what\ncorresponds to the current \"$(pwd)/.git\" directory, use it to\nbuild the default for GIT_INDEX_FILE and SHA1_FILE_DIRECTORY,\nand this directory does _not_ have anything to do with my\nprevious \"the directory that corresponds to the root of the tree\nstructure GIT_INDEX_FILE describes\".  I agree to all of the\nabove.\n\n"},{"id":"2946","messageId":"Pine.LNX.4.21.0505092311590.30848-100000@iabervon.org","threadId":"519","inReplyTo":"7vy8anu8po.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] Renaming environment variables.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-05-10T03:23:19Z","receivedAt":"2005-05-10T03:23:19Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 9 May 2005, Junio C Hamano wrote:\n\n> >>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n> >>>>> \"PB\" == Petr Baudis <pasky@ucw.cz> writes:\n> \n> DB> While we're at it, it would be useful to have one for what is normally\n> DB> \".git\", rather than just \".git/objects\".\n> \n> PB> I think it would be nice to have something like GIT_BASEDIR, which would\n> PB> default to .git, and the objects directory would then default to\n> PB> $GIT_BASEDIR/objects and the index file would default to\n> PB> $GIT_BASEDIR/index.\n> \n> Although what I pushed out at git-jc repository does not have\n> this, it does not mean I forgot this issue you two have raised,\n> nor would want to veto it or anything like that.  Just that,\n> unlike the one that I already committed, the proposed change\n> would touch rather many lines and I have not managed to\n> determine the extent of the damage yet.\n\nIt *should* only affect the places where the variables that depend on it\nget computed; didn't you already centralize the code to figure this out?\n\n> I am currently waiting for community consensus, including the\n> final name of the variable.  I think the current consensus is\n> that this is a good idea, the semantics for it is to name what\n> corresponds to the current \"$(pwd)/.git\" directory, use it to\n> build the default for GIT_INDEX_FILE and SHA1_FILE_DIRECTORY,\n> and this directory does _not_ have anything to do with my\n> previous \"the directory that corresponds to the root of the tree\n> structure GIT_INDEX_FILE describes\".  I agree to all of the\n> above.\n\nI agree to all of that, too. I'd suggest GIT_DIR for the variable, simply\nbecause I can't think of anything else that name could mean.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"2954","messageId":"7voebjr5vd.fsf@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"Pine.LNX.4.21.0505092012340.30848-100000@iabervon.org","subject":"Re: [RFC] Renaming environment variables.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T05:45:42Z","receivedAt":"2005-05-10T05:45:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n\nDB> On Mon, 9 May 2005, Junio C Hamano wrote:\n>> >>>>> \"DB\" == Daniel Barkalow <barkalow@iabervon.org> writes:\n>> \nDB> While we're at it, it would be useful to have one for what is normally\nDB> \".git\",...\n>> \n>> If you mean the parent directory of ${SHA1_FILE_DIRECTORY}, and\n>> your only gripe is about git-init-db creating \".git\" in the\n>> current working directory regardless of SHA1_FILE_DIRECTORY, I\n>> would agree that what git-init-db does is broken.  Not that I\n>> have a suggested \"right behaviour\" for it, though.\n\nDB> It could just create all missing parents of the object directory, which\nDB> would be better, at least.\n\nI am ambivalent about this.  Here is an excerpt from my WIP.  I\nam trying to keep the original semantics of \"we create the\nleading paths only if we default to .git/objects\":\n\n$ GIT_DIFF_OPTS=-u8 jit-diff 1: init-db.c\n# - HEAD: Rename environment variables.\n# + (working tree)\n--- a/init-db.c\n+++ b/init-db.c\n@@ -22,21 +22,22 @@\n  * be the judge.  The default case is to have one DB per managed directory.\n  */\n int main(int argc, char **argv)\n {\n \tconst char *sha1_dir;\n \tchar *path;\n \tint len, i;\n \n-\tsafe_create_dir(\".git\");\n-\n-\tsha1_dir = gitenv(DB_ENVIRONMENT);\n-\tif (!sha1_dir) {\n-\t\tsha1_dir = DEFAULT_DB_ENVIRONMENT;\n+\tsha1_dir = get_object_directory();\n+\tif (!gitenv(DB_ENVIRONMENT) && !gitenv(GIT_DIR_ENVIRONMENT)) {\n+\t\t/* We create leading paths only when we fall back\n+\t\t * to local \".git/objects\".\n+\t\t */\n+\t\tsafe_create_dir(DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\tfprintf(stderr, \"defaulting to local storage area\\n\");\n \t}\n \tlen = strlen(sha1_dir);\n \tpath = xmalloc(len + 40);\n \tmemcpy(path, sha1_dir, len);\n \n \tsafe_create_dir(sha1_dir);\n \tfor (i = 0; i < 256; i++) {\n\nHere DEFAULT_GIT_DIR_ENVIRONMENT is defined as \".git\", and the\ndirectory is created only if we do not have GIT_OBJECT_DIRECTORY\nnor GIT_DIR environment variables, which should match the intent\nof the original by Linus.  Otherwise we at least require the\nparent directory of GIT_OBJECT_DIRECTORY to exist.  I think that\nis a reasonable default (well that is not something I can take\ncredit), in that if the user is clued enough to use something\ndifferent from the default he should at least know enough to\ncreate the leading paths beforehand (or the script could do that\nfor him).\n\nOther than this part, I think the code is ready to go.\n\n\n"},{"id":"2957","messageId":"7v8y2nr411.fsf_-_@assigned-by-dhcp.cox.net","threadId":"519","inReplyTo":"7voebjr5vd.fsf@assigned-by-dhcp.cox.net","subject":"Introducing GIT_DIR environment variable.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-10T06:25:30Z","receivedAt":"2005-05-10T06:25:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ok, following the mailing list discussion, I've done GIT_DIR and\npushed it out to the usual git-jc repository, at:\n\n    http://members.cox.net/junkio/git-jc.git/\n\nAuthor: Junio C Hamano <junkio@cox.net>\nDate:   Mon May 9 22:57:58 2005 -0700\n    \n    Introduce GIT_DIR environment variable.\n    \n    During the mailing list discussion on renaming GIT_ environment\n    variables, people felt that having one environment that lets the\n    user (or Porcelain) specify both SHA1_FILE_DIRECTORY (now\n    GIT_OBJECT_DIRECTORY) and GIT_INDEX_FILE for the default layout\n    would be handy.  This change introduces GIT_DIR environment\n    variable, from which the defaults for GIT_INDEX_FILE and\n    GIT_OBJECT_DIRECTORY are derived.  When GIT_DIR is not defined,\n    it defaults to \".git\".  GIT_INDEX_FILE defaults to\n    \"$GIT_DIR/index\" and GIT_OBJECT_DIRECTORY defaults to\n    \"$GIT_DIR/objects\".\n    \n    Special thanks for ideas and discussions go to Petr Baudis and\n    Daniel Barkalow.  Bugs are mine ;-)\n    \nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n--- a/cache.h\n+++ b/cache.h\n@@ -106,16 +106,15 @@ static inline unsigned int create_ce_mod\n struct cache_entry **active_cache;\n unsigned int active_nr, active_alloc, active_cache_changed;\n \n+#define GIT_DIR_ENVIRONMENT \"GIT_DIR\"\n+#define DEFAULT_GIT_DIR_ENVIRONMENT \".git\"\n #define DB_ENVIRONMENT \"GIT_OBJECT_DIRECTORY\"\n-#define DEFAULT_DB_ENVIRONMENT \".git/objects\"\n-#define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\n-\n-#define get_object_directory() (gitenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)\n-\n #define INDEX_ENVIRONMENT \"GIT_INDEX_FILE\"\n-#define DEFAULT_INDEX_ENVIRONMENT \".git/index\"\n \n-#define get_index_file() (gitenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)\n+extern char *get_object_directory(void);\n+extern char *get_index_file(void);\n+\n+#define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\n \n #define alloc_nr(x) (((x)+16)*3/2)\n \n--- a/git-prune-script\n+++ b/git-prune-script\n@@ -11,6 +11,9 @@ do\n     shift;\n done\n \n+: ${GIT_DIR=.git}\n+: ${GIT_OBJECT_DIRECTORY=\"${SHA1_FILE_DIRECTORY-\"$GIT_DIR/objects\"}\"}\n+\n # Defaulting to include .git/refs/*/* may be debatable from the\n # purist POV but power users can always give explicit parameters\n # to the script anyway.\n@@ -19,7 +22,8 @@ case \"$#\" in\n 0)\n     x_40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n     x_40=\"$x_40$x_40$x_40$x_40$x_40$x_40$x_40$x_40\"\n-    set x $(sed -ne \"/^$x_40\\$/p\" .git/HEAD .git/refs/*/* 2>/dev/null)\n+    set x $(sed -ne \"/^$x_40\\$/p\" \\\n+\t\"$GIT_DIR\"/HEAD \"$GIT_DIR\"/refs/*/* /dev/null 2>/dev/null)\n     shift ;;\n esac\n \n@@ -28,13 +32,7 @@ sed -ne '/unreachable /{\n     s/unreachable [^ ][^ ]* //\n     s|\\(..\\)|\\1/|p\n }' | {\n-\tfor d in \"$GIT_OBJECT_DIRECTORY\" \"$SHA1_FILE_DIRECTORY\" ''\n-\tdo\n-\t\ttest \"$d\" != \"\" && test -d \"$d\" && break\n-\tdone\n-\tcase \"$d\" in\n-\t'') cd .git/objects/ ;;\n-\t*) cd \"$d\" ;;\n-\tesac || exit\n+\tcd \"$GIT_OBJECT_DIRECTORY\" || exit\n \txargs -r $dryrun rm -f\n }\n+\n--- a/git-pull-script\n+++ b/git-pull-script\n@@ -3,6 +3,9 @@\n merge_repo=$1\n merge_name=${2:-HEAD}\n \n+: ${GIT_DIR=.git}\n+: ${GIT_OBJECT_DIRECTORY=\"${SHA1_FILE_DIRECTORY-\"$GIT_DIR/objects\"}\"}\n+\n download_one () {\n \t# remote_path=\"$1\" local_file=\"$2\"\n \tcase \"$1\" in\n@@ -25,16 +28,19 @@ download_objects () {\n \t\tgit-local-pull -l -a \"$2\" \"$1/\"\n \t\t;;\n \t*)\n-\t\trsync -avz --ignore-existing \"$1/objects/.\" \\\n-\t\t\t${SHA_FILE_DIRECTORY:-.git/objects}/.\n+\t\trsync -avz --ignore-existing \\\n+\t\t\t\"$1/objects/.\" \"$GIT_OBJECT_DIRECTORY\"/.\n \t\t;;\n \tesac\n }\n \n echo \"Getting remote $merge_name\"\n-download_one \"$merge_repo/$merge_name\" .git/MERGE_HEAD\n+download_one \"$merge_repo/$merge_name\" \"$GIT_DIR\"/MERGE_HEAD\n \n echo \"Getting object database\"\n-download_objects \"$merge_repo\" \"$(cat .git/MERGE_HEAD)\"\n+download_objects \"$merge_repo\" \"$(cat \"$GIT_DIR\"/MERGE_HEAD)\"\n \n-git-resolve-script \"$(cat .git/HEAD)\" \"$(cat .git/MERGE_HEAD)\" \"$merge_repo\"\n+git-resolve-script \\\n+\t\"$(cat \"$GIT_DIR\"/HEAD)\" \\\n+\t\"$(cat \"$GIT_DIR\"/MERGE_HEAD)\" \\\n+\t\"$merge_repo\"\n--- a/git-resolve-script\n+++ b/git-resolve-script\n@@ -1,14 +1,19 @@\n #!/bin/sh\n #\n+# Copyright (c) 2005 Linus Torvalds\n+#\n # Resolve two trees.\n #\n head=\"$1\"\n merge=\"$2\"\n merge_repo=\"$3\"\n \n-rm -f .git/MERGE_HEAD .git/ORIG_HEAD\n-echo $head > .git/ORIG_HEAD\n-echo $merge > .git/MERGE_HEAD\n+: ${GIT_DIR=.git}\n+: ${GIT_OBJECT_DIRECTORY=\"${SHA1_FILE_DIRECTORY-\"$GIT_DIR/objects\"}\"}\n+\n+rm -f \"$GIT_DIR\"/MERGE_HEAD \"$GIT_DIR\"/ORIG_HEAD\n+echo $head > \"$GIT_DIR\"/ORIG_HEAD\n+echo $merge > \"$GIT_DIR\"/MERGE_HEAD\n \n #\n # The remote name is just used for the message,\n@@ -35,7 +40,7 @@ if [ \"$common\" == \"$head\" ]; then\n \techo \"Kill me within 3 seconds..\"\n \tsleep 3\n \tgit-read-tree -m $merge && git-checkout-cache -f -a && git-update-cache --refresh\n-\techo $merge > .git/HEAD\n+\techo $merge > \"$GIT_DIR\"/HEAD\n \tgit-diff-tree -p ORIG_HEAD HEAD | diffstat -p1\n \texit 0\n fi\n@@ -51,6 +56,6 @@ if [ $? -ne 0 ]; then\n fi\n result_commit=$(echo \"$merge_msg\" | git-commit-tree $result_tree -p $head -p $merge)\n echo \"Committed merge $result_commit\"\n-echo $result_commit > .git/HEAD\n+echo $result_commit > \"$GIT_DIR\"/HEAD\n git-checkout-cache -f -a && git-update-cache --refresh\n git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1\n--- a/git-tag-script\n+++ b/git-tag-script\n@@ -1,5 +1,9 @@\n #!/bin/sh\n-object=${2:-$(cat .git/HEAD)}\n+# Copyright (c) 2005 Linus Torvalds\n+\n+: ${GIT_DIR=.git}\n+\n+object=${2:-$(cat \"$GIT_DIR\"/HEAD)}\n type=$(git-cat-file -t $object) || exit 1\n ( echo -e \"object $object\\ntype $type\\ntag $1\\n\"; cat ) > .tmp-tag\n rm -f .tmp-tag.asc\n--- a/init-db.c\n+++ b/init-db.c\n@@ -27,11 +27,12 @@ int main(int argc, char **argv)\n \tchar *path;\n \tint len, i;\n \n-\tsafe_create_dir(\".git\");\n-\n-\tsha1_dir = gitenv(DB_ENVIRONMENT);\n-\tif (!sha1_dir) {\n-\t\tsha1_dir = DEFAULT_DB_ENVIRONMENT;\n+\tsha1_dir = get_object_directory();\n+\tif (!gitenv(DB_ENVIRONMENT) && !gitenv(GIT_DIR_ENVIRONMENT)) {\n+\t\t/* We create leading paths only when we fall back\n+\t\t * to local .git/objects, at least for now.\n+\t\t */\n+\t\tsafe_create_dir(DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\tfprintf(stderr, \"defaulting to local storage area\\n\");\n \t}\n \tlen = strlen(sha1_dir);\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -59,6 +59,38 @@ int get_sha1_file(const char *path, unsi\n \treturn get_sha1_hex(buffer, result);\n }\n \n+static char *git_dir, *git_object_dir, *git_index_file;\n+static void setup_git_env(void)\n+{\n+\tgit_dir = gitenv(GIT_DIR_ENVIRONMENT);\n+\tif (!git_dir)\n+\t\tgit_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n+\tgit_object_dir = gitenv(DB_ENVIRONMENT);\n+\tif (!git_object_dir) {\n+\t\tgit_object_dir = xmalloc(strlen(git_dir) + 9);\n+\t\tsprintf(git_object_dir, \"%s/objects\", git_dir);\n+\t}\n+\tgit_index_file = gitenv(INDEX_ENVIRONMENT);\n+\tif (!git_index_file) {\n+\t\tgit_index_file = xmalloc(strlen(git_dir) + 7);\n+\t\tsprintf(git_index_file, \"%s/index\", git_dir);\n+\t}\n+}\n+\n+char *get_object_directory(void)\n+{\n+\tif (!git_object_dir)\n+\t\tsetup_git_env();\n+\treturn git_object_dir;\n+}\n+\n+char *get_index_file(void)\n+{\n+\tif (!git_index_file)\n+\t\tsetup_git_env();\n+\treturn git_index_file;\n+}\n+\n int get_sha1(const char *str, unsigned char *sha1)\n {\n \tstatic char pathname[PATH_MAX];\n@@ -70,15 +102,16 @@ int get_sha1(const char *str, unsigned c\n \t\t\"refs/snap\",\n \t\tNULL\n \t};\n-\tconst char *gitdir;\n \tconst char **p;\n \n \tif (!get_sha1_hex(str, sha1))\n \t\treturn 0;\n \n-\tgitdir = \".git\";\n+\tif (!git_dir)\n+\t\tsetup_git_env();\n \tfor (p = prefix; *p; p++) {\n-\t\tsnprintf(pathname, sizeof(pathname), \"%s/%s/%s\", gitdir, *p, str);\n+\t\tsnprintf(pathname, sizeof(pathname), \"%s/%s/%s\",\n+\t\t\t git_dir, *p, str);\n \t\tif (!get_sha1_file(pathname, sha1))\n \t\t\treturn 0;\n \t}\n\n\n\n"},{"id":"3014","messageId":"81b0412b0505101639120788a5@mail.gmail.com","threadId":"519","inReplyTo":"7v8y2nr411.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: Introducing GIT_DIR environment variable.","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2005-05-10T23:39:12Z","receivedAt":"2005-05-10T23:39:12Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 5/10/05, Junio C Hamano <junkio@cox.net> wrote:\n> Ok, following the mailing list discussion, I've done GIT_DIR and\n> pushed it out to the usual git-jc repository, at:\n> \n>     http://members.cox.net/junkio/git-jc.git/\n> \n> Author: Junio C Hamano <junkio@cox.net>\n> Date:   Mon May 9 22:57:58 2005 -0700\n> \n>     Introduce GIT_DIR environment variable.\n> \n\nJust in case I missed it: was it already considered to use\nthe extended attributes (EAs) for saving pointer to GIT cache?\nSo I don't have to exclude anything from \"grep -rn <pattern> .\"\n"}]}