Print empty line between raw, stat, summary and patch
[gitweb.git] / pack-objects.c
index b430b02cf7f5b39c97bc090634ef26346a022ade..bed2497b7974bed96a6ac9478807059cb8de17cb 100644 (file)
@@ -10,7 +10,6 @@
 #include "tree-walk.h"
 #include <sys/time.h>
 #include <signal.h>
-#include <stdint.h>
 
 static const char pack_usage[] = "git-pack-objects [-q] [--no-reuse-delta] [--non-empty] [--local] [--incremental] [--window=N] [--depth=N] {--stdout | base-name} < object-list";
 
@@ -157,7 +156,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
 
        rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));
        for (i = 0; i < num_ent; i++) {
-               uint32_t hl = *((uint32_t *)(index + 24 * i));
+               unsigned int hl = *((unsigned int *)((char *) index + 24*i));
                rix->revindex[i] = ntohl(hl);
        }
        /* This knows the pack format -- the 20-byte trailer
@@ -301,7 +300,7 @@ static unsigned long write_object(struct sha1file *f,
                use_packed_git(p);
 
                datalen = find_packed_object_size(p, entry->in_pack_offset);
-               buf = p->pack_base + entry->in_pack_offset;
+               buf = (char *) p->pack_base + entry->in_pack_offset;
                sha1write(f, buf, datalen);
                unuse_packed_git(p);
                hdrlen = 0; /* not really */
@@ -464,48 +463,21 @@ static void rehash_objects(void)
        }
 }
 
-struct name_path {
-       struct name_path *up;
-       const char *elem;
-       int len;
-};
-
-#define DIRBITS 12
-
-static unsigned name_hash(struct name_path *path, const char *name)
+static unsigned name_hash(const char *name)
 {
-       struct name_path *p = path;
-       const char *n = name + strlen(name);
-       unsigned hash = 0, name_hash = 0, name_done = 0;
-
-       if (n != name && n[-1] == '\n')
-               n--;
-       while (name <= --n) {
-               unsigned char c = *n;
-               if (c == '/' && !name_done) {
-                       name_hash = hash;
-                       name_done = 1;
-                       hash = 0;
-               }
-               hash = hash * 11 + c;
-       }
-       if (!name_done) {
-               name_hash = hash;
-               hash = 0;
-       }
-       for (p = path; p; p = p->up) {
-               hash = hash * 11 + '/';
-               n = p->elem + p->len;
-               while (p->elem <= --n) {
-                       unsigned char c = *n;
-                       hash = hash * 11 + c;
-               }
-       }
+       unsigned char c;
+       unsigned hash = 0;
+
        /*
-        * Make sure "Makefile" and "t/Makefile" are hashed separately
-        * but close enough.
+        * This effectively just creates a sortable number from the
+        * last sixteen non-whitespace characters. Last characters
+        * count "most", so things that end in ".c" sort together.
         */
-       hash = (name_hash<<DIRBITS) | (hash & ((1U<<DIRBITS )-1));
+       while ((c = *name++) != 0) {
+               if (isspace(c))
+                       continue;
+               hash = (hash >> 2) + (c << 24);
+       }
        return hash;
 }
 
@@ -687,48 +659,39 @@ static int name_cmp_len(const char *name)
 }
 
 static void add_pbase_object(struct tree_desc *tree,
-                            struct name_path *up,
                             const char *name,
-                            int cmplen)
+                            int cmplen,
+                            const char *fullname)
 {
-       while (tree->size) {
-               const unsigned char *sha1;
-               const char *entry_name;
-               int entry_len;
-               unsigned mode;
+       struct name_entry entry;
+
+       while (tree_entry(tree,&entry)) {
                unsigned long size;
                char type[20];
 
-               sha1 = tree_entry_extract(tree, &entry_name, &mode);
-               update_tree_entry(tree);
-               entry_len = strlen(entry_name);
-               if (entry_len != cmplen ||
-                   memcmp(entry_name, name, cmplen) ||
-                   !has_sha1_file(sha1) ||
-                   sha1_object_info(sha1, type, &size))
+               if (entry.pathlen != cmplen ||
+                   memcmp(entry.path, name, cmplen) ||
+                   !has_sha1_file(entry.sha1) ||
+                   sha1_object_info(entry.sha1, type, &size))
                        continue;
                if (name[cmplen] != '/') {
-                       unsigned hash = name_hash(up, name);
-                       add_object_entry(sha1, hash, 1);
+                       unsigned hash = name_hash(fullname);
+                       add_object_entry(entry.sha1, hash, 1);
                        return;
                }
                if (!strcmp(type, tree_type)) {
                        struct tree_desc sub;
-                       struct name_path me;
                        struct pbase_tree_cache *tree;
                        const char *down = name+cmplen+1;
                        int downlen = name_cmp_len(down);
 
-                       tree = pbase_tree_get(sha1);
+                       tree = pbase_tree_get(entry.sha1);
                        if (!tree)
                                return;
                        sub.buf = tree->tree_data;
                        sub.size = tree->tree_size;
 
-                       me.up = up;
-                       me.elem = entry_name;
-                       me.len = entry_len;
-                       add_pbase_object(&sub, &me, down, downlen);
+                       add_pbase_object(&sub, down, downlen, fullname);
                        pbase_tree_put(tree);
                }
        }
@@ -784,14 +747,14 @@ static void add_preferred_base_object(char *name, unsigned hash)
 
        for (it = pbase_tree; it; it = it->next) {
                if (cmplen == 0) {
-                       hash = name_hash(NULL, "");
+                       hash = name_hash("");
                        add_object_entry(it->pcache.sha1, hash, 1);
                }
                else {
                        struct tree_desc tree;
                        tree.buf = it->pcache.tree_data;
                        tree.size = it->pcache.tree_size;
-                       add_pbase_object(&tree, NULL, name, cmplen);
+                       add_pbase_object(&tree, name, cmplen, name);
                }
        }
 }
@@ -1037,9 +1000,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
        if (src_entry->depth >= max_depth)
                return 0;
 
-       /* Now some size filtering euristics. */
+       /* Now some size filtering heuristics. */
        size = trg_entry->size;
-       max_size = (size/2 - 20) / (src_entry->depth + 1);
+       max_size = size/2 - 20;
+       max_size = max_size * (max_depth - src_entry->depth) / max_depth;
+       if (max_size == 0)
+               return 0;
        if (trg_entry->delta && trg_entry->delta_size <= max_size)
                max_size = trg_entry->delta_size-1;
        src_size = src_entry->size;
@@ -1255,6 +1221,10 @@ int main(int argc, char **argv)
                                local = 1;
                                continue;
                        }
+                       if (!strcmp("--progress", arg)) {
+                               progress = 1;
+                               continue;
+                       }
                        if (!strcmp("--incremental", arg)) {
                                incremental = 1;
                                continue;
@@ -1331,7 +1301,7 @@ int main(int argc, char **argv)
                }
                if (get_sha1_hex(line, sha1))
                        die("expected sha1, got garbage:\n %s", line);
-               hash = name_hash(NULL, line+41);
+               hash = name_hash(line+41);
                add_preferred_base_object(line+41, hash);
                add_object_entry(sha1, hash, 0);
        }