summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d19938a)
raw | patch | inline | side by side (parent: d19938a)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 10 May 2005 05:57:58 +0000 (22:57 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 10 May 2005 05:57:58 +0000 (22:57 -0700) |
During the mailing list discussion on renaming GIT_ environment
variables, people felt that having one environment that lets the
user (or Porcelain) specify both SHA1_FILE_DIRECTORY (now
GIT_OBJECT_DIRECTORY) and GIT_INDEX_FILE for the default layout
would be handy. This change introduces GIT_DIR environment
variable, from which the defaults for GIT_INDEX_FILE and
GIT_OBJECT_DIRECTORY are derived. When GIT_DIR is not defined,
it defaults to ".git". GIT_INDEX_FILE defaults to
"$GIT_DIR/index" and GIT_OBJECT_DIRECTORY defaults to
"$GIT_DIR/objects".
Special thanks for ideas and discussions go to Petr Baudis and
Daniel Barkalow. Bugs are mine ;-)
Signed-off-by: Junio C Hamano <junkio@cox.net>
variables, people felt that having one environment that lets the
user (or Porcelain) specify both SHA1_FILE_DIRECTORY (now
GIT_OBJECT_DIRECTORY) and GIT_INDEX_FILE for the default layout
would be handy. This change introduces GIT_DIR environment
variable, from which the defaults for GIT_INDEX_FILE and
GIT_OBJECT_DIRECTORY are derived. When GIT_DIR is not defined,
it defaults to ".git". GIT_INDEX_FILE defaults to
"$GIT_DIR/index" and GIT_OBJECT_DIRECTORY defaults to
"$GIT_DIR/objects".
Special thanks for ideas and discussions go to Petr Baudis and
Daniel Barkalow. Bugs are mine ;-)
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
git-prune-script | patch | blob | history | |
git-pull-script | patch | blob | history | |
git-resolve-script | patch | blob | history | |
git-tag-script | patch | blob | history | |
init-db.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
index 1c15b2be0891159da376c76f972f23ec27fc6579..0901fae8a459c44f4953a98f957723317da6f234 100644 (file)
--- a/cache.h
+++ b/cache.h
struct cache_entry **active_cache;
unsigned int active_nr, active_alloc, active_cache_changed;
+#define GIT_DIR_ENVIRONMENT "GIT_DIR"
+#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
-#define DEFAULT_DB_ENVIRONMENT ".git/objects"
-#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
-
-#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() (gitenv(INDEX_ENVIRONMENT) ? : DEFAULT_INDEX_ENVIRONMENT)
+extern char *get_object_directory(void);
+extern char *get_index_file(void);
+
+#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
#define alloc_nr(x) (((x)+16)*3/2)
diff --git a/git-prune-script b/git-prune-script
index c0ffb1dcba3bc59fe5717ca8d89645ce899452b5..1a97ccc91ded1522d3016d76cbdf62557585d514 100755 (executable)
--- a/git-prune-script
+++ b/git-prune-script
shift;
done
+: ${GIT_DIR=.git}
+: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
+
# Defaulting to include .git/refs/*/* may be debatable from the
# purist POV but power users can always give explicit parameters
# to the script anyway.
0)
x_40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
x_40="$x_40$x_40$x_40$x_40$x_40$x_40$x_40$x_40"
- set x $(sed -ne "/^$x_40\$/p" .git/HEAD .git/refs/*/* 2>/dev/null)
+ set x $(sed -ne "/^$x_40\$/p" \
+ "$GIT_DIR"/HEAD "$GIT_DIR"/refs/*/* /dev/null 2>/dev/null)
shift ;;
esac
s/unreachable [^ ][^ ]* //
s|\(..\)|\1/|p
}' | {
- for d in "$GIT_OBJECT_DIRECTORY" "$SHA1_FILE_DIRECTORY" ''
- do
- test "$d" != "" && test -d "$d" && break
- done
- case "$d" in
- '') cd .git/objects/ ;;
- *) cd "$d" ;;
- esac || exit
+ cd "$GIT_OBJECT_DIRECTORY" || exit
xargs -r $dryrun rm -f
}
+
diff --git a/git-pull-script b/git-pull-script
index 78d2f3df346b7b8d24b3dbe28a244b8d0ba141e7..bd892c7bbc8b236d46b19444d94e2c023410f4d5 100755 (executable)
--- a/git-pull-script
+++ b/git-pull-script
merge_repo=$1
merge_name=${2:-HEAD}
+: ${GIT_DIR=.git}
+: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
+
download_one () {
# remote_path="$1" local_file="$2"
case "$1" in
git-local-pull -l -a "$2" "$1/"
;;
*)
- rsync -avz --ignore-existing "$1/objects/." \
- ${SHA_FILE_DIRECTORY:-.git/objects}/.
+ rsync -avz --ignore-existing \
+ "$1/objects/." "$GIT_OBJECT_DIRECTORY"/.
;;
esac
}
echo "Getting remote $merge_name"
-download_one "$merge_repo/$merge_name" .git/MERGE_HEAD
+download_one "$merge_repo/$merge_name" "$GIT_DIR"/MERGE_HEAD
echo "Getting object database"
-download_objects "$merge_repo" "$(cat .git/MERGE_HEAD)"
+download_objects "$merge_repo" "$(cat "$GIT_DIR"/MERGE_HEAD)"
-git-resolve-script "$(cat .git/HEAD)" "$(cat .git/MERGE_HEAD)" "$merge_repo"
+git-resolve-script \
+ "$(cat "$GIT_DIR"/HEAD)" \
+ "$(cat "$GIT_DIR"/MERGE_HEAD)" \
+ "$merge_repo"
diff --git a/git-resolve-script b/git-resolve-script
index c2f7a6e240fb9efad97b00595bd1d5ed3829a8b8..ec646fbb915d932cad66d8b4bd7457d844b7dd38 100644 (file)
--- a/git-resolve-script
+++ b/git-resolve-script
#!/bin/sh
#
+# Copyright (c) 2005 Linus Torvalds
+#
# Resolve two trees.
#
head="$1"
merge="$2"
merge_repo="$3"
-rm -f .git/MERGE_HEAD .git/ORIG_HEAD
-echo $head > .git/ORIG_HEAD
-echo $merge > .git/MERGE_HEAD
+: ${GIT_DIR=.git}
+: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
+
+rm -f "$GIT_DIR"/MERGE_HEAD "$GIT_DIR"/ORIG_HEAD
+echo $head > "$GIT_DIR"/ORIG_HEAD
+echo $merge > "$GIT_DIR"/MERGE_HEAD
#
# The remote name is just used for the message,
echo "Kill me within 3 seconds.."
sleep 3
git-read-tree -m $merge && git-checkout-cache -f -a && git-update-cache --refresh
- echo $merge > .git/HEAD
+ echo $merge > "$GIT_DIR"/HEAD
git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1
exit 0
fi
fi
result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
echo "Committed merge $result_commit"
-echo $result_commit > .git/HEAD
+echo $result_commit > "$GIT_DIR"/HEAD
git-checkout-cache -f -a && git-update-cache --refresh
git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1
diff --git a/git-tag-script b/git-tag-script
index ccc75dcfbdd70e738f088a43aec9dc2866e3923c..281d192814ec200199379f44fef10d2b04f762c1 100755 (executable)
--- a/git-tag-script
+++ b/git-tag-script
#!/bin/sh
-object=${2:-$(cat .git/HEAD)}
+# Copyright (c) 2005 Linus Torvalds
+
+: ${GIT_DIR=.git}
+
+object=${2:-$(cat "$GIT_DIR"/HEAD)}
type=$(git-cat-file -t $object) || exit 1
( echo -e "object $object\ntype $type\ntag $1\n"; cat ) > .tmp-tag
rm -f .tmp-tag.asc
diff --git a/init-db.c b/init-db.c
index 157b92b471b0bf5334a474f830b6110cc90465e5..b6bb78356762bd28261949da54638f46776e6d4b 100644 (file)
--- a/init-db.c
+++ b/init-db.c
char *path;
int len, i;
- safe_create_dir(".git");
-
- sha1_dir = gitenv(DB_ENVIRONMENT);
- if (!sha1_dir) {
- sha1_dir = DEFAULT_DB_ENVIRONMENT;
+ sha1_dir = get_object_directory();
+ if (!gitenv(DB_ENVIRONMENT) && !gitenv(GIT_DIR_ENVIRONMENT)) {
+ /* We create leading paths only when we fall back
+ * to local .git/objects, at least for now.
+ */
+ safe_create_dir(DEFAULT_GIT_DIR_ENVIRONMENT);
fprintf(stderr, "defaulting to local storage area\n");
}
len = strlen(sha1_dir);
diff --git a/sha1_file.c b/sha1_file.c
index 430f5fdfbf0a0f4a226dfcc9af199bb1242a0ad0..7ca0a386f4757bea7a82b321587079cfc1b05611 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return get_sha1_hex(buffer, result);
}
+static char *git_dir, *git_object_dir, *git_index_file;
+static void setup_git_env(void)
+{
+ git_dir = gitenv(GIT_DIR_ENVIRONMENT);
+ if (!git_dir)
+ git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ git_object_dir = gitenv(DB_ENVIRONMENT);
+ if (!git_object_dir) {
+ git_object_dir = xmalloc(strlen(git_dir) + 9);
+ sprintf(git_object_dir, "%s/objects", git_dir);
+ }
+ git_index_file = gitenv(INDEX_ENVIRONMENT);
+ if (!git_index_file) {
+ git_index_file = xmalloc(strlen(git_dir) + 7);
+ sprintf(git_index_file, "%s/index", git_dir);
+ }
+}
+
+char *get_object_directory(void)
+{
+ if (!git_object_dir)
+ setup_git_env();
+ return git_object_dir;
+}
+
+char *get_index_file(void)
+{
+ if (!git_index_file)
+ setup_git_env();
+ return git_index_file;
+}
+
int get_sha1(const char *str, unsigned char *sha1)
{
static char pathname[PATH_MAX];
"refs/snap",
NULL
};
- const char *gitdir;
const char **p;
if (!get_sha1_hex(str, sha1))
return 0;
- gitdir = ".git";
+ if (!git_dir)
+ setup_git_env();
for (p = prefix; *p; p++) {
- snprintf(pathname, sizeof(pathname), "%s/%s/%s", gitdir, *p, str);
+ snprintf(pathname, sizeof(pathname), "%s/%s/%s",
+ git_dir, *p, str);
if (!get_sha1_file(pathname, sha1))
return 0;
}