]> asedeno.scripts.mit.edu Git - git.git/blobdiff - pack-redundant.c
Merge branch 'master' of git://repo.or.cz/git-gui
[git.git] / pack-redundant.c
index 92a09ed36281b293a8c9002a33ab80f740949a37..c8f7d9af7b502e12a3d36fc3b3e796e43b4f2bdb 100644 (file)
@@ -139,7 +139,7 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
 
        l = (hint == NULL) ? list->front : hint;
        while (l) {
-               int cmp = memcmp(l->sha1, sha1, 20);
+               int cmp = hashcmp(l->sha1, sha1);
                if (cmp > 0) { /* we insert before this entry */
                        return llist_insert(list, prev, sha1);
                }
@@ -162,7 +162,7 @@ redo_from_start:
        l = (hint == NULL) ? list->front : hint;
        prev = NULL;
        while (l) {
-               int cmp = memcmp(l->sha1, sha1, 20);
+               int cmp = hashcmp(l->sha1, sha1);
                if (cmp > 0) /* not in list, since sorted */
                        return prev;
                if(!cmp) { /* found */
@@ -256,7 +256,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
        while (p1_off <= p1->pack->index_size - 3 * 20 &&
               p2_off <= p2->pack->index_size - 3 * 20)
        {
-               int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
+               int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
                /* cmp ~ p1 - p2 */
                if (cmp == 0) {
                        p1_hint = llist_sorted_remove(p1->unique_objects,
@@ -351,16 +351,16 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
 {
        size_t ret = 0;
        int p1_off, p2_off;
-       char *p1_base, *p2_base;
+       unsigned char *p1_base, *p2_base;
 
        p1_off = p2_off = 256 * 4 + 4;
-       p1_base = (char *)p1->index_base;
-       p2_base = (char *)p2->index_base;
+       p1_base = (unsigned char *)p1->index_base;
+       p2_base = (unsigned char *)p2->index_base;
 
        while (p1_off <= p1->index_size - 3 * 20 &&
               p2_off <= p2->index_size - 3 * 20)
        {
-               int cmp = memcmp(p1_base + p1_off, p2_base + p2_off, 20);
+               int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
                /* cmp ~ p1 - p2 */
                if (cmp == 0) {
                        ret++;
@@ -396,9 +396,9 @@ static size_t get_pack_redundancy(struct pack_list *pl)
        return ret;
 }
 
-static inline size_t pack_set_bytecount(struct pack_list *pl)
+static inline off_t pack_set_bytecount(struct pack_list *pl)
 {
-       size_t ret = 0;
+       off_t ret = 0;
        while (pl) {
                ret += pl->pack->pack_size;
                ret += pl->pack->index_size;
@@ -413,7 +413,7 @@ static void minimize(struct pack_list **min)
                *non_unique = NULL, *min_perm = NULL;
        struct pll *perm, *perm_all, *perm_ok = NULL, *new_perm;
        struct llist *missing;
-       size_t min_perm_size = (size_t)-1, perm_size;
+       off_t min_perm_size = 0, perm_size;
        int n;
 
        pl = local_packs;
@@ -461,7 +461,7 @@ static void minimize(struct pack_list **min)
        perm = perm_ok;
        while (perm) {
                perm_size = pack_set_bytecount(perm->pl);
-               if (min_perm_size > perm_size) {
+               if (!min_perm_size || min_perm_size > perm_size) {
                        min_perm_size = perm_size;
                        min_perm = perm->pl;
                }