summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/core-git.txt27
-rw-r--r--Makefile3
-rw-r--r--README2
-rw-r--r--cache.h15
-rw-r--r--commit-tree.c10
-rw-r--r--diff.c10
-rwxr-xr-xgit-prune-script8
-rw-r--r--gitenv.c75
-rw-r--r--init-db.c7
-rw-r--r--rsh.c4
-rw-r--r--sha1_file.c8
11 files changed, 130 insertions, 39 deletions
diff --git a/Documentation/core-git.txt b/Documentation/core-git.txt
index 09a70f269e..4c80c7e9c7 100644
--- a/Documentation/core-git.txt
+++ b/Documentation/core-git.txt
@@ -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.
diff --git a/Makefile b/Makefile
index f8fea48617..5c078f907a 100644
--- 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 d4fa56f7c6..0cccfe866f 100644
--- 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 7a656c70d3..1c15b2be08 100644
--- a/cache.h
+++ b/cache.h
@@ -31,6 +31,13 @@
#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
*
* NOTE NOTE NOTE! This is all in the native CPU byte format. It's
@@ -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)
diff --git a/commit-tree.c b/commit-tree.c
index cfd6730fe8..b8dd36f0b8 100644
--- a/commit-tree.c
+++ b/commit-tree.c
@@ -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 748ab4a2fb..3230997122 100644
--- 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;
diff --git a/git-prune-script b/git-prune-script
index 9ba89a5b9d..c0ffb1dcba 100755
--- a/git-prune-script
+++ b/git-prune-script
@@ -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
index 0000000000..ab9396f969
--- /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;
+}
diff --git a/init-db.c b/init-db.c
index 83f95e8b92..157b92b471 100644
--- 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 2a52e59816..5d1cb9d578 100644
--- 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++) = ' ';
diff --git a/sha1_file.c b/sha1_file.c
index 549d45af25..430f5fdfbf 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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