]> git.ipfire.org Git - thirdparty/git.git/blobdiff - update-cache.c
Add git-write-blob.
[thirdparty/git.git] / update-cache.c
index 16e1bb9aea6413db35039042289605124d759501..0401372e47b2783b67b02415bdbba79ebfd6e92a 100644 (file)
@@ -31,57 +31,6 @@ static inline long IS_ERR(const void *ptr)
        return (unsigned long)ptr > (unsigned long)-1000L;
 }
 
-static int index_fd(unsigned char *sha1, int fd, struct stat *st)
-{
-       z_stream stream;
-       unsigned long size = st->st_size;
-       int max_out_bytes = size + 200;
-       void *out = xmalloc(max_out_bytes);
-       void *metadata = xmalloc(200);
-       int metadata_size;
-       void *in;
-       SHA_CTX c;
-
-       in = "";
-       if (size)
-               in = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
-       close(fd);
-       if (!out || (int)(long)in == -1)
-               return -1;
-
-       metadata_size = 1+sprintf(metadata, "blob %lu", size);
-
-       SHA1_Init(&c);
-       SHA1_Update(&c, metadata, metadata_size);
-       SHA1_Update(&c, in, size);
-       SHA1_Final(sha1, &c);
-
-       memset(&stream, 0, sizeof(stream));
-       deflateInit(&stream, Z_BEST_COMPRESSION);
-
-       /*
-        * ASCII size + nul byte
-        */     
-       stream.next_in = metadata;
-       stream.avail_in = metadata_size;
-       stream.next_out = out;
-       stream.avail_out = max_out_bytes;
-       while (deflate(&stream, 0) == Z_OK)
-               /* nothing */;
-
-       /*
-        * File content
-        */
-       stream.next_in = in;
-       stream.avail_in = size;
-       while (deflate(&stream, Z_FINISH) == Z_OK)
-               /*nothing */;
-
-       deflateEnd(&stream);
-       
-       return write_sha1_buffer(sha1, out, stream.total_out);
-}
-
 /*
  * This only updates the "non-critical" parts of the directory
  * cache, ie the parts that aren't tracked by GIT, and only used
@@ -111,7 +60,7 @@ static int add_file_to_cache(char *path)
 
        fd = open(path, O_RDONLY);
        if (fd < 0) {
-               if (errno == ENOENT) {
+               if (errno == ENOENT || errno == ENOTDIR) {
                        if (allow_remove)
                                return remove_file_from_cache(path);
                }
@@ -212,15 +161,17 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce)
        return updated;
 }
 
-static void refresh_cache(void)
+static int refresh_cache(void)
 {
        int i;
+       int has_errors = 0;
 
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce, *new;
                ce = active_cache[i];
                if (ce_stage(ce)) {
                        printf("%s: needs merge\n", ce->name);
+                       has_errors = 1;
                        while ((i < active_nr) &&
                               ! strcmp(active_cache[i]->name, ce->name))
                                i++;
@@ -230,12 +181,15 @@ static void refresh_cache(void)
 
                new = refresh_entry(ce);
                if (IS_ERR(new)) {
-                       if (!(not_new && PTR_ERR(new) == -ENOENT))
+                       if (!(not_new && PTR_ERR(new) == -ENOENT)) {
                                printf("%s: needs update\n", ce->name);
+                               has_errors = 1;
+                       }
                        continue;
                }
                active_cache[i] = new;
        }
+       return has_errors;
 }
 
 /*
@@ -307,7 +261,7 @@ static void remove_lock_file_on_signal(int signo)
 
 int main(int argc, char **argv)
 {
-       int i, newfd, entries;
+       int i, newfd, entries, has_errors = 0;
        int allow_options = 1;
        static char lockfile[MAXPATHLEN+1];
        const char *indexfile = get_index_file();
@@ -343,7 +297,7 @@ int main(int argc, char **argv)
                                continue;
                        }
                        if (!strcmp(path, "--refresh")) {
-                               refresh_cache();
+                               has_errors |= refresh_cache();
                                continue;
                        }
                        if (!strcmp(path, "--cacheinfo")) {
@@ -369,5 +323,5 @@ int main(int argc, char **argv)
                die("Unable to write new cachefile");
 
        lockfile_name = NULL;
-       return 0;
+       return has_errors;
 }