---------------------
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
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)
Environment Variables
---------------------
-SHA1_FILE_DIRECTORY::
+GIT_OBJECT_DIRECTORY::
used to specify the object database root (usually .git/objects)
GIT_INDEX_FILE::
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.
LIB_H += diff.h
LIB_OBJS += diff.o
+LIB_OBJS += gitenv.o
+
LIBS = $(LIB_FILE)
LIBS += -lz
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)
- The Object Database (SHA1_FILE_DIRECTORY)
+ The Object Database (GIT_OBJECT_DIRECTORY)
The object database is literally just a content-addressable collection
#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
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)
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));
#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)
*
* 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;
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
}
--- /dev/null
+/*
+ * 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;
+}
*/
#include "cache.h"
-void safe_create_dir(char *dir)
+void safe_create_dir(const char *dir)
{
if (mkdir(dir, 0755) < 0) {
if (errno != EEXIST) {
*/
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");
*(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++) = ' ';
*
* 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)
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);
* 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
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