Code

relax usage of the progress API
[git.git] / sha1_file.c
index 59325d46bec1ec604e65f9e5414cd75bba929c63..83a06a7aed84715db191b703e529d3501df0a8f2 100644 (file)
@@ -1491,11 +1491,8 @@ found_cache_entry:
                ent->lru.next->prev = ent->lru.prev;
                ent->lru.prev->next = ent->lru.next;
                delta_base_cached -= ent->size;
-       }
-       else {
-               ret = xmalloc(ent->size + 1);
-               memcpy(ret, ent->data, ent->size);
-               ((char *)ret)[ent->size] = 0;
+       } else {
+               ret = xmemdupz(ent->data, ent->size);
        }
        *type = ent->type;
        *base_size = ent->size;
@@ -1684,22 +1681,22 @@ off_t find_pack_entry_one(const unsigned char *sha1,
        return 0;
 }
 
-static int matches_pack_name(struct packed_git *p, const char *ig)
+int matches_pack_name(struct packed_git *p, const char *name)
 {
        const char *last_c, *c;
 
-       if (!strcmp(p->pack_name, ig))
-               return 0;
+       if (!strcmp(p->pack_name, name))
+               return 1;
 
        for (c = p->pack_name, last_c = c; *c;)
                if (*c == '/')
                        last_c = ++c;
                else
                        ++c;
-       if (!strcmp(last_c, ig))
-               return 0;
+       if (!strcmp(last_c, name))
+               return 1;
 
-       return 1;
+       return 0;
 }
 
 static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
@@ -1717,7 +1714,7 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
                if (ignore_packed) {
                        const char **ig;
                        for (ig = ignore_packed; *ig; ig++)
-                               if (!matches_pack_name(p, *ig))
+                               if (matches_pack_name(p, *ig))
                                        break;
                        if (*ig)
                                goto next;
@@ -1872,12 +1869,9 @@ void *read_sha1_file(const unsigned char *sha1, enum object_type *type,
 
        co = find_cached_object(sha1);
        if (co) {
-               buf = xmalloc(co->size + 1);
-               memcpy(buf, co->buf, co->size);
-               ((char*)buf)[co->size] = 0;
                *type = co->type;
                *size = co->size;
-               return buf;
+               return xmemdupz(co->buf, co->size);
        }
 
        buf = read_packed_sha1(sha1, type, size);
@@ -2346,8 +2340,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
                strbuf_init(&nbuf, 0);
                if (convert_to_git(path, buf, size, &nbuf)) {
                        munmap(buf, size);
-                       size = nbuf.len;
-                       buf = nbuf.buf;
+                       buf = strbuf_detach(&nbuf, &size);
                        re_allocated = 1;
                }
        }