]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Rename environment variables.
authorJunio C Hamano <junkio@cox.net>
Tue, 10 May 2005 00:57:56 +0000 (17:57 -0700)
committerJunio C Hamano <junkio@cox.net>
Tue, 10 May 2005 00:57:56 +0000 (17:57 -0700)
H. Peter Anvin mentioned that using SHA1_whatever as an
environment variable name is not nice and we should instead use
names starting with "GIT_" prefix to avoid conflicts.  Here is
what this patch does:

 * Renames the following environment variables:

    New name                           Old Name

    GIT_AUTHOR_DATE                    AUTHOR_DATE
    GIT_AUTHOR_EMAIL                   AUTHOR_EMAIL
    GIT_AUTHOR_NAME                    AUTHOR_NAME
    GIT_COMMITTER_EMAIL                COMMIT_AUTHOR_EMAIL
    GIT_COMMITTER_NAME                 COMMIT_AUTHOR_NAME
    GIT_ALTERNATE_OBJECT_DIRECTORIES   SHA1_FILE_DIRECTORIES
    GIT_OBJECT_DIRECTORY               SHA1_FILE_DIRECTORY

 * Introduces a compatibility macro, gitenv(), which does an
   getenv() and if it fails calls gitenv_bc(), which in turn
   picks up the value from old name while giving a warning about
   using an old name.

 * Changes all users of the environment variable to fetch
   environment variable with the new name using gitenv().

 * Updates the documentation and scripts shipped with Linus GIT
   distribution.

The transition plan is as follows:

 * We will keep the backward compatibility list used by gitenv()
   for now, so the current scripts and user environments
   continue to work as before.  The users will get warnings when
   they have old name but not new name in their environment to
   the stderr.

 * The Porcelain layers should start using new names.  However,
   just in case it ends up calling old Plumbing layer
   implementation, they should also export old names, taking
   values from the corresponding new names, during the
   transition period.

 * After a transition period, we would drop the compatibility
   support and drop gitenv().  Revert the callers to directly
   call getenv() but keep using the new names.

   The last part is probably optional and the transition
   duration needs to be set to a reasonable value.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/core-git.txt
Makefile
README
cache.h
commit-tree.c
diff.c
git-prune-script
gitenv.c [new file with mode: 0644]
init-db.c
rsh.c
sha1_file.c

index 09a70f269e8c0953404b68626d8040e64677a2f5..4c80c7e9c7779dc6d92095772488b84a58271d88 100644 (file)
@@ -210,15 +210,16 @@ Environment Variables
 ---------------------
 Various git commands use the following environment variables:
 
-- 'AUTHOR_NAME'
-- 'AUTHOR_EMAIL'
-- 'AUTHOR_DATE'
-- 'COMMIT_AUTHOR_NAME'
-- 'COMMIT_AUTHOR_EMAIL'
+- 'GIT_AUTHOR_NAME'
+- 'GIT_AUTHOR_EMAIL'
+- 'GIT_AUTHOR_DATE'
+- 'GIT_COMMITTER_NAME'
+- 'GIT_COMMITTER_EMAIL'
 - 'GIT_DIFF_OPTS'
 - 'GIT_EXTERNAL_DIFF'
 - 'GIT_INDEX_FILE'
-- 'SHA1_FILE_DIRECTORY'
+- 'GIT_OBJECT_DIRECTORY'
+- 'GIT_ALTERNATE_OBJECT_DIRECTORIES'
 
 
 NAME
@@ -439,11 +440,11 @@ If not provided, "git-commit-tree" uses your name, hostname and domain to
 provide author and committer info. This can be overridden using the
 following environment variables.
 
-       AUTHOR_NAME
-       AUTHOR_EMAIL
-       AUTHOR_DATE
-       COMMIT_AUTHOR_NAME
-       COMMIT_AUTHOR_EMAIL
+       GIT_AUTHOR_NAME
+       GIT_AUTHOR_EMAIL
+       GIT_AUTHOR_DATE
+       GIT_COMMITTER_NAME
+       GIT_COMMITTER_EMAIL
 
 (nb <,> and '\n's are stripped)
 
@@ -876,7 +877,7 @@ sha1 mismatch <object>::
 Environment Variables
 ---------------------
 
-SHA1_FILE_DIRECTORY::
+GIT_OBJECT_DIRECTORY::
        used to specify the object database root (usually .git/objects)
 
 GIT_INDEX_FILE::
@@ -918,7 +919,7 @@ DESCRIPTION
 This simply creates an empty git object database - basically a `.git`
 directory and `.git/object/??/` directories.
 
-If the object storage directory is specified via the 'SHA1_FILE_DIRECTORY'
+If the object storage directory is specified via the 'GIT_OBJECT_DIRECTORY'
 environment variable then the sha1 directories are created underneath -
 otherwise the default `.git/objects` directory is used.
 
index f8fea4861777c8d226389f79056c9a056eb9f230..5c078f907aaecab48703bd1f86800b11785b0fb6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,8 @@ LIB_OBJS += strbuf.o
 LIB_H += diff.h
 LIB_OBJS += diff.o
 
+LIB_OBJS += gitenv.o
+
 LIBS = $(LIB_FILE)
 LIBS += -lz
 
@@ -116,6 +118,7 @@ sha1_file.o: $(LIB_H)
 usage.o: $(LIB_H)
 diff.o: $(LIB_H)
 strbuf.o: $(LIB_H)
+gitenv.o: $(LIB_H)
 
 clean:
        rm -f *.o mozilla-sha1/*.o ppc/*.o $(PROG) $(LIB_FILE)
diff --git a/README b/README
index d4fa56f7c6e8acfa72e545dc37fbe10135702043..0cccfe866fedb37a5adb0eb2a893d387e7166a49 100644 (file)
--- a/README
+++ b/README
@@ -24,7 +24,7 @@ There are two object abstractions: the "object database", and the
 
 
 
-       The Object Database (SHA1_FILE_DIRECTORY)
+       The Object Database (GIT_OBJECT_DIRECTORY)
 
 
 The object database is literally just a content-addressable collection
diff --git a/cache.h b/cache.h
index 7a656c70d317c486c0f3bcd6461ef6601c06a077..1c15b2be0891159da376c76f972f23ec27fc6579 100644 (file)
--- a/cache.h
+++ b/cache.h
 #define DTYPE(de)      DT_UNKNOWN
 #endif
 
+/*
+ * Environment variables transition.
+ * We accept older names for now but warn.
+ */
+extern char *gitenv_bc(const char *);
+#define gitenv(e) (getenv(e) ? : gitenv_bc(e))
+
 /*
  * Basic data structures for the directory cache
  *
@@ -99,16 +106,16 @@ static inline unsigned int create_ce_mode(unsigned int mode)
 struct cache_entry **active_cache;
 unsigned int active_nr, active_alloc, active_cache_changed;
 
-#define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
+#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
 #define DEFAULT_DB_ENVIRONMENT ".git/objects"
-#define ALTERNATE_DB_ENVIRONMENT "SHA1_FILE_DIRECTORIES"
+#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
-#define get_object_directory() (getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)
+#define get_object_directory() (gitenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT)
 
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
 #define DEFAULT_INDEX_ENVIRONMENT ".git/index"
 
-#define get_index_file() (getenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)
+#define get_index_file() (gitenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)
 
 #define alloc_nr(x) (((x)+16)*3/2)
 
index cfd6730fe8da68a9b4e10ccf6481a2a1264fc81d..b8dd36f0b8d7b1c49a478b1aae42de5d594897ab 100644 (file)
@@ -146,11 +146,11 @@ int main(int argc, char **argv)
        datestamp(realdate, sizeof(realdate));
        strcpy(date, realdate);
 
-       commitgecos = getenv("COMMIT_AUTHOR_NAME") ? : realgecos;
-       commitemail = getenv("COMMIT_AUTHOR_EMAIL") ? : realemail;
-       gecos = getenv("AUTHOR_NAME") ? : realgecos;
-       email = getenv("AUTHOR_EMAIL") ? : realemail;
-       audate = getenv("AUTHOR_DATE");
+       commitgecos = gitenv("GIT_COMMITTER_NAME") ? : realgecos;
+       commitemail = gitenv("GIT_COMMITTER_EMAIL") ? : realemail;
+       gecos = gitenv("GIT_AUTHOR_NAME") ? : realgecos;
+       email = gitenv("GIT_AUTHOR_EMAIL") ? : realemail;
+       audate = gitenv("GIT_AUTHOR_DATE");
        if (audate)
                parse_date(audate, date, sizeof(date));
 
diff --git a/diff.c b/diff.c
index 748ab4a2fbd44ee43448b2db4efa2e5826b5e472..32309971222bfd0647cb3885d9cf4903b7dfaacf 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -8,11 +8,11 @@
 #include "cache.h"
 #include "diff.h"
 
-static char *diff_opts = "-pu";
+static const char *diff_opts = "-pu";
 
 static const char *external_diff(void)
 {
-       static char *external_diff_cmd = NULL;
+       static const char *external_diff_cmd = NULL;
        static int done_preparing = 0;
 
        if (done_preparing)
@@ -26,11 +26,11 @@ static const char *external_diff(void)
         *
         * GIT_DIFF_OPTS="-c";
         */
-       if (getenv("GIT_EXTERNAL_DIFF"))
-               external_diff_cmd = getenv("GIT_EXTERNAL_DIFF");
+       if (gitenv("GIT_EXTERNAL_DIFF"))
+               external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF");
 
        /* In case external diff fails... */
-       diff_opts = getenv("GIT_DIFF_OPTS") ? : diff_opts;
+       diff_opts = gitenv("GIT_DIFF_OPTS") ? : diff_opts;
 
        done_preparing = 1;
        return external_diff_cmd;
index 9ba89a5b9d0d484aee54d0bdb6deabdc71962c85..c0ffb1dcba3bc59fe5717ca8d89645ce899452b5 100755 (executable)
@@ -28,9 +28,13 @@ sed -ne '/unreachable /{
     s/unreachable [^ ][^ ]* //
     s|\(..\)|\1/|p
 }' | {
-       case "$SHA1_FILE_DIRECTORY" in
+       for d in "$GIT_OBJECT_DIRECTORY" "$SHA1_FILE_DIRECTORY" ''
+       do
+               test "$d" != "" && test -d "$d" && break
+       done
+       case "$d" in
        '') cd .git/objects/ ;;
-       *) cd "$SHA1_FILE_DIRECTORY" ;;
+       *) cd "$d" ;;
        esac || exit
        xargs -r $dryrun rm -f
 }
diff --git a/gitenv.c b/gitenv.c
new file mode 100644 (file)
index 0000000..ab9396f
--- /dev/null
+++ b/gitenv.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2005 Junio C Hamano
+ */
+#include "cache.h"
+
+/*
+ * This array must be sorted by its canonical name, because
+ * we do look-up by binary search.
+ */
+static struct backward_compatible_env {
+       const char *canonical;
+       const char *old;
+} bc_name[] = {
+       { "GIT_ALTERNATE_OBJECT_DIRECTORIES", "SHA1_FILE_DIRECTORIES" },
+       { "GIT_AUTHOR_DATE", "AUTHOR_DATE" },
+       { "GIT_AUTHOR_EMAIL", "AUTHOR_EMAIL" },
+       { "GIT_AUTHOR_NAME", "AUTHOR_NAME" }, 
+       { "GIT_COMMITTER_EMAIL", "COMMIT_AUTHOR_EMAIL" },
+       { "GIT_COMMITTER_NAME", "COMMIT_AUTHOR_NAME" },
+       { "GIT_OBJECT_DIRECTORY", "SHA1_FILE_DIRECTORY" },
+};
+
+static void warn_old_environment(int pos)
+{
+       int i;
+       static int warned = 0;
+       if (warned)
+               return;
+
+       warned = 1;
+       fprintf(stderr,
+               "warning: Attempting to use %s\n",
+               bc_name[pos].old);
+       fprintf(stderr,
+               "warning: GIT environment variables have been renamed.\n"
+               "warning: Please adjust your scripts and environment.\n");
+       for (i = 0; i < sizeof(bc_name) / sizeof(bc_name[0]); i++) {
+               /* warning is needed only when old name is there and
+                * new name is not.
+                */
+               if (!getenv(bc_name[i].canonical) && getenv(bc_name[i].old))
+                       fprintf(stderr, "warning: old %s => new %s\n",
+                               bc_name[i].old, bc_name[i].canonical);
+       }
+}
+
+char *gitenv_bc(const char *e)
+{
+       int first, last;
+       char *val = getenv(e);
+       if (val)
+               die("gitenv_bc called on existing %s; fix the caller.", e);
+
+       first = 0;
+       last = sizeof(bc_name) / sizeof(bc_name[0]);
+       while (last > first) {
+               int next = (last + first) >> 1;
+               int cmp = strcmp(e, bc_name[next].canonical);
+               if (!cmp) {
+                       val = getenv(bc_name[next].old);
+                       /* If the user has only old name, warn.
+                        * otherwise stay silent.
+                        */
+                       if (val)
+                               warn_old_environment(next);
+                       return val;
+               }
+               if (cmp < 0) {
+                       last = next;
+                       continue;
+               }
+               first = next+1;
+       }
+       return NULL;
+}
index 83f95e8b926f4fd28e0db0ccfc4f040d4172ee8a..157b92b471b0bf5334a474f830b6110cc90465e5 100644 (file)
--- a/init-db.c
+++ b/init-db.c
@@ -5,7 +5,7 @@
  */
 #include "cache.h"
 
-void safe_create_dir(char *dir)
+void safe_create_dir(const char *dir)
 {
        if (mkdir(dir, 0755) < 0) {
                if (errno != EEXIST) {
@@ -23,12 +23,13 @@ void safe_create_dir(char *dir)
  */
 int main(int argc, char **argv)
 {
-       char *sha1_dir, *path;
+       const char *sha1_dir;
+       char *path;
        int len, i;
 
        safe_create_dir(".git");
 
-       sha1_dir = getenv(DB_ENVIRONMENT);
+       sha1_dir = gitenv(DB_ENVIRONMENT);
        if (!sha1_dir) {
                sha1_dir = DEFAULT_DB_ENVIRONMENT;
                fprintf(stderr, "defaulting to local storage area\n");
diff --git a/rsh.c b/rsh.c
index 2a52e598164b565fcb06e452d6fb9866344e4c12..5d1cb9d578a8e679fc190a9d7d2c842ad811223f 100644 (file)
--- a/rsh.c
+++ b/rsh.c
@@ -36,8 +36,8 @@ int setup_connection(int *fd_in, int *fd_out, char *remote_prog,
        *(path++) = '\0';
        /* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */
        snprintf(command, COMMAND_SIZE, 
-                "cd /%s; SHA1_FILE_DIRECTORY=objects %s",
-                path, remote_prog);
+                "cd /%s; %s=objects %s",
+                path, DB_ENVIRONMENT, remote_prog);
        posn = command + strlen(command);
        for (i = 0; i < rmt_argc; i++) {
                *(posn++) = ' ';
index 549d45af258d0019d1819edea976ed5555f1bf03..430f5fdfbf0a0f4a226dfcc9af199bb1242a0ad0 100644 (file)
@@ -120,7 +120,7 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
  *
  * Also note that this returns the location for creating.  Reading
  * SHA1 file can happen from any alternate directory listed in the
- * SHA1_FILE_DIRECTORIES environment variable if it is not found in
+ * DB_ENVIRONMENT environment variable if it is not found in
  * the primary object database.
  */
 char *sha1_file_name(const unsigned char *sha1)
@@ -128,7 +128,7 @@ char *sha1_file_name(const unsigned char *sha1)
        static char *name, *base;
 
        if (!base) {
-               char *sha1_file_directory = get_object_directory();
+               const char *sha1_file_directory = get_object_directory();
                int len = strlen(sha1_file_directory);
                base = xmalloc(len + 60);
                memcpy(base, sha1_file_directory, len);
@@ -151,7 +151,7 @@ static struct alternate_object_database {
  * alt_odb points at an array of struct alternate_object_database.
  * This array is terminated with an element that has both its base
  * and name set to NULL.  alt_odb[n] comes from n'th non-empty
- * element from colon separated $SHA1_FILE_DIRECTORIES environment
+ * element from colon separated ALTERNATE_DB_ENVIRONMENT environment
  * variable, and its base points at a statically allocated buffer
  * that contains "/the/directory/corresponding/to/.git/objects/...",
  * while its name points just after the slash at the end of
@@ -167,7 +167,7 @@ static void prepare_alt_odb(void)
        int pass, totlen, i;
        const char *cp, *last;
        char *op = 0;
-       const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
+       const char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
 
        /* The first pass counts how large an area to allocate to
         * hold the entire alt_odb structure, including array of