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)
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
}
+
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"
#!/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
#!/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
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);
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;
}