Merge head 'cvs2git' of http://netz.smurf.noris.de/git/git
authorLinus Torvalds <torvalds@g5.osdl.org>
Tue, 5 Jul 2005 19:03:14 +0000 (12:03 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 5 Jul 2005 19:03:14 +0000 (12:03 -0700)
cache.h
fetch-pack.c
git-fetch-script
refs.c
refs.h
send-pack.c
sha1_file.c
upload-pack.c

diff --git a/cache.h b/cache.h
index c79c70f..c84e797 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -158,6 +158,7 @@ extern void rollback_index_file(struct cache_file *);
 #define TYPE_CHANGED    0x0040
 
 /* Return a statically allocated filename matching the sha1 signature */
+extern char *git_path(const char *fmt, ...);
 extern char *sha1_file_name(const unsigned char *sha1);
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
index b8367a4..a4c1ecc 100644 (file)
@@ -72,13 +72,9 @@ static int find_common(int fd[2], unsigned char *result_sha1, unsigned char *rem
 
 static int get_old_sha1(const char *refname, unsigned char *sha1)
 {
-       static char pathname[PATH_MAX];
-       const char *git_dir;
        int fd, ret;
 
-       git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
-       snprintf(pathname, sizeof(pathname), "%s/%s", git_dir, refname);
-       fd = open(pathname, O_RDONLY);
+       fd = open(git_path("%s", refname), O_RDONLY);
        ret = -1;
        if (fd >= 0) {
                char buffer[60];
index fb4a537..8a2d37d 100755 (executable)
@@ -11,37 +11,23 @@ fi
 
 : ${GIT_DIR=.git}
 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
+TMP_HEAD="$GIT_DIR/TMP_HEAD"
 
-download_one () {
-       # remote_path="$1" local_file="$2"
-       case "$1" in
-       http://*)
-               wget -q -O "$2" "$1" ;;
-       /*)
-               test -f "$1" && cat >"$2" "$1" ;;
-       *)
-               rsync -L "$1" "$2" ;;
-       esac
-}
-
-download_objects () {
-       # remote_repo="$1" head_sha1="$2"
-       case "$1" in
-       http://*)
-               git-http-pull -a "$2" "$1/"
-               ;;
-       /*)
-               git-local-pull -l -a "$2" "$1/"
-               ;;
-       *)
-               rsync -avz --ignore-existing \
-                       "$1/objects/." "$GIT_OBJECT_DIRECTORY"/.
-               ;;
-       esac
-}
-
-echo "Getting remote $merge_name"
-download_one "$merge_repo/$merge_name" "$GIT_DIR/$destination" || exit 1
-
-echo "Getting object database"
-download_objects "$merge_repo" "$(cat "$GIT_DIR/$destination")" || exit 1
+case "$merge_repo" in
+http://*)
+       head=$(wget -q -O - "$merge_repo/$merge_name") || exit 1
+       echo Fetching $head using http
+       git-http-pull -v -a "$head" "$merge_repo/"
+       ;;
+rsync://*)
+       rsync -L "$merge_repo/$merge_name" "$TMP_HEAD" || exit 1
+       head=$(git-rev-parse TMP_HEAD)
+       rm -f "$TMP_HEAD"
+       rsync -avz --ignore-existing "$merge_repo/objects/" "$GIT_OBJECT_DIRECTORY/"
+       ;;
+*)
+       head=$(git-fetch-pack "$merge_repo" "$merge_name")
+       ;;
+esac || exit 1
+git-rev-parse --verify "$head" > /dev/null || exit 1
+echo "$head" > "$GIT_DIR/$destination"
diff --git a/refs.c b/refs.c
index 7ccd721..6ca04d3 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -68,6 +68,15 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
        return retval;
 }
 
+int head_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+       unsigned char sha1[20];
+       const char *headpath = git_path("HEAD");
+       if (!read_ref(headpath, sha1))
+               fn(headpath, sha1);
+       return do_for_each_ref(get_refs_directory(), fn);
+}
+
 int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
 {
        return do_for_each_ref(get_refs_directory(), fn);
diff --git a/refs.h b/refs.h
index a79cb13..2625596 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -5,6 +5,7 @@
  * Calls the specified function for each ref file until it returns nonzero,
  * and returns the value
  */
+extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));
 extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));
 
 /** Reads the refs file specified into sha1 **/
index f098acb..7287c3d 100644 (file)
@@ -92,12 +92,9 @@ static int pack_objects(int fd, struct ref *refs)
 static int read_ref(const char *ref, unsigned char *sha1)
 {
        int fd, ret;
-       static char pathname[PATH_MAX];
        char buffer[60];
-       const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT;
 
-       snprintf(pathname, sizeof(pathname), "%s/%s", git_dir, ref);
-       fd = open(pathname, O_RDONLY);
+       fd = open(git_path("%s", ref), O_RDONLY);
        if (fd < 0)
                return -1;
        ret = -1;
index 8f20e2f..74dc2aa 100644 (file)
@@ -102,9 +102,30 @@ char *get_index_file(void)
        return git_index_file;
 }
 
-int get_sha1(const char *str, unsigned char *sha1)
+char *git_path(const char *fmt, ...)
 {
        static char pathname[PATH_MAX];
+       va_list args;
+       int len;
+
+       if (!git_dir)
+               setup_git_env();
+       len = strlen(git_dir);
+       if (len == 1 && *git_dir == '.')
+               len = 0;
+       if (len > PATH_MAX-100)
+               return "pad-path";
+       memcpy(pathname, git_dir, len);
+       if (len && git_dir[len-1] != '/')
+               pathname[len++] = '/';
+       va_start(args, fmt);
+       vsnprintf(pathname + len, sizeof(pathname) - len, fmt, args);
+       va_end(args);
+       return pathname;
+}
+
+int get_sha1(const char *str, unsigned char *sha1)
+{
        static const char *prefix[] = {
                "",
                "refs",
@@ -118,11 +139,8 @@ int get_sha1(const char *str, unsigned char *sha1)
        if (!get_sha1_hex(str, sha1))
                return 0;
 
-       if (!git_dir)
-               setup_git_env();
        for (p = prefix; *p; p++) {
-               snprintf(pathname, sizeof(pathname), "%s/%s/%s",
-                        git_dir, *p, str);
+               char * pathname = git_path("%s/%s", *p, str);
                if (!get_sha1_file(pathname, sha1))
                        return 0;
        }
index d35c068..9edbf51 100644 (file)
@@ -153,6 +153,7 @@ static int send_ref(const char *refname, const unsigned char *sha1)
 
 static int upload_pack(void)
 {
+       head_ref(send_ref);
        for_each_ref(send_ref);
        packet_flush(1);
        nr_needs = receive_needs();