Code

Merge branch 'maint'
[git.git] / fast-import.c
index bea12151c29af7f4242baaf80e12fd26eb550a45..3a2d5ed8e667af06f97d2559b3cffb8a01f94565 100644 (file)
@@ -651,42 +651,6 @@ static void start_packfile(void)
        all_packs[pack_id] = p;
 }
 
-static void fixup_header_footer(void)
-{
-       static const int buf_sz = 128 * 1024;
-       int pack_fd = pack_data->pack_fd;
-       SHA_CTX c;
-       struct pack_header hdr;
-       char *buf;
-
-       if (lseek(pack_fd, 0, SEEK_SET) != 0)
-               die("Failed seeking to start: %s", strerror(errno));
-       if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))
-               die("Unable to reread header of %s", pack_data->pack_name);
-       if (lseek(pack_fd, 0, SEEK_SET) != 0)
-               die("Failed seeking to start: %s", strerror(errno));
-       hdr.hdr_entries = htonl(object_count);
-       write_or_die(pack_fd, &hdr, sizeof(hdr));
-
-       SHA1_Init(&c);
-       SHA1_Update(&c, &hdr, sizeof(hdr));
-
-       buf = xmalloc(buf_sz);
-       for (;;) {
-               size_t n = xread(pack_fd, buf, buf_sz);
-               if (!n)
-                       break;
-               if (n < 0)
-                       die("Failed to checksum %s", pack_data->pack_name);
-               SHA1_Update(&c, buf, n);
-       }
-       free(buf);
-
-       SHA1_Final(pack_data->sha1, &c);
-       write_or_die(pack_fd, pack_data->sha1, sizeof(pack_data->sha1));
-       close(pack_fd);
-}
-
 static int oecmp (const void *a_, const void *b_)
 {
        struct object_entry *a = *((struct object_entry**)a_);
@@ -802,7 +766,9 @@ static void end_packfile(void)
                struct branch *b;
                struct tag *t;
 
-               fixup_header_footer();
+               fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
+                                   pack_data->pack_name, object_count);
+               close(pack_data->pack_fd);
                idx_name = keep_pack(create_index());
 
                /* Register the packfile with core git's machinary. */
@@ -904,6 +870,12 @@ static int store_object(
        if (e->offset) {
                duplicate_count_by_type[type]++;
                return 1;
+       } else if (find_sha1_pack(sha1, packed_git)) {
+               e->type = type;
+               e->pack_id = MAX_PACK_ID;
+               e->offset = 1; /* just not zero! */
+               duplicate_count_by_type[type]++;
+               return 1;
        }
 
        if (last && last->data && last->depth < max_depth) {
@@ -1193,6 +1165,8 @@ static int tree_content_set(
                n = slash1 - p;
        else
                n = strlen(p);
+       if (!n)
+               die("Empty path component found in input");
 
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
@@ -1312,7 +1286,7 @@ static int update_branch(struct branch *b)
 
                if (!in_merge_bases(old_cmit, &new_cmit, 1)) {
                        unlock_ref(lock);
-                       warn("Not updating %s"
+                       warning("Not updating %s"
                                " (new tip %s does not contain %s)",
                                b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1));
                        return -1;
@@ -2021,6 +1995,7 @@ static void import_marks(const char *input_file)
                        e = insert_object(sha1);
                        e->type = type;
                        e->pack_id = MAX_PACK_ID;
+                       e->offset = 1; /* just not zero! */
                }
                insert_mark(mark, e);
        }
@@ -2086,6 +2061,7 @@ int main(int argc, const char **argv)
        if (i != argc)
                usage(fast_import_usage);
 
+       prepare_packed_git();
        start_packfile();
        for (;;) {
                read_next_command();