git-config-set: add more options
[git.git] / sha1_file.c
index e456799..82a0188 100644 (file)
@@ -51,6 +51,8 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
 int safe_create_leading_directories(char *path)
 {
        char *pos = path;
+       if (*pos == '/')
+               pos++;
 
        while (pos) {
                pos = strchr(pos, '/');
@@ -422,6 +424,7 @@ struct packed_git *add_packed_git(char *path, int path_len, int local)
        struct packed_git *p;
        unsigned long idx_size;
        void *idx_map;
+       unsigned char sha1[20];
 
        if (check_packed_git_idx(path, &idx_size, &idx_map))
                return NULL;
@@ -445,6 +448,8 @@ struct packed_git *add_packed_git(char *path, int path_len, int local)
        p->pack_last_used = 0;
        p->pack_use_cnt = 0;
        p->pack_local = local;
+       if (!get_sha1_hex(path + path_len - 40 - 4, sha1))
+               memcpy(p->sha1, sha1, 20);
        return p;
 }
 
@@ -1232,18 +1237,22 @@ static int link_temp_to_file(const char *tmpfile, char *filename)
 int move_temp_to_file(const char *tmpfile, char *filename)
 {
        int ret = link_temp_to_file(tmpfile, filename);
-       if (ret) {
-               /*
-                * Coda hack - coda doesn't like cross-directory links,
-                * so we fall back to a rename, which will mean that it
-                * won't be able to check collisions, but that's not a
-                * big deal.
-                *
-                * When this succeeds, we just return 0. We have nothing
-                * left to unlink.
-                */
-               if (ret == EXDEV && !rename(tmpfile, filename))
+
+       /*
+        * Coda hack - coda doesn't like cross-directory links,
+        * so we fall back to a rename, which will mean that it
+        * won't be able to check collisions, but that's not a
+        * big deal.
+        *
+        * The same holds for FAT formatted media.
+        *
+        * When this succeeds, we just return 0. We have nothing
+        * left to unlink.
+        */
+       if (ret && ret != EEXIST) {
+               if (!rename(tmpfile, filename))
                        return 0;
+               ret = errno;
        }
        unlink(tmpfile);
        if (ret) {