]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/fast-import.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / builtin / fast-import.c
index 20406f677542c0c1e34b623fc3f4b2b349700525..31b8732128d0afcb193518732952e049922ca8ae 100644 (file)
@@ -1,5 +1,9 @@
 #include "builtin.h"
+#include "abspath.h"
 #include "cache.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
 #include "repository.h"
 #include "config.h"
 #include "lockfile.h"
 #include "dir.h"
 #include "run-command.h"
 #include "packfile.h"
+#include "object-name.h"
 #include "object-store.h"
 #include "mem-pool.h"
 #include "commit-reach.h"
 #include "khash.h"
+#include "date.h"
+#include "wrapper.h"
 
 #define PACK_ID_BITS 16
 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -45,7 +52,7 @@ struct object_entry {
                depth : DEPTH_BITS;
 };
 
-static int object_entry_hashcmp(const void *map_data,
+static int object_entry_hashcmp(const void *map_data UNUSED,
                                const struct hashmap_entry *eptr,
                                const struct hashmap_entry *entry_or_key,
                                const void *keydata)
@@ -176,8 +183,9 @@ static int global_argc;
 static const char **global_argv;
 
 /* Memory pools */
-static struct mem_pool fi_mem_pool =  {NULL, 2*1024*1024 -
-                                      sizeof(struct mp_block), 0 };
+static struct mem_pool fi_mem_pool = {
+       .block_alloc = 2*1024*1024 - sizeof(struct mp_block),
+};
 
 /* Atom management */
 static unsigned int atom_table_sz = 4451;
@@ -205,7 +213,9 @@ static int import_marks_file_done;
 static int relative_marks_paths;
 
 /* Our last blob */
-static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
+static struct last_object last_blob = {
+       .data = STRBUF_INIT,
+ };
 
 /* Tree management */
 static unsigned int tree_entry_alloc = 1000;
@@ -231,7 +241,10 @@ static struct tag *last_tag;
 static whenspec_type whenspec = WHENSPEC_RAW;
 static struct strbuf command_buf = STRBUF_INIT;
 static int unread_command_buf;
-static struct recent_command cmd_hist = {&cmd_hist, &cmd_hist, NULL};
+static struct recent_command cmd_hist = {
+       .prev = &cmd_hist,
+       .next = &cmd_hist,
+};
 static struct recent_command *cmd_tail = &cmd_hist;
 static struct recent_command *rc_free;
 static unsigned int cmd_save = 100;
@@ -401,16 +414,18 @@ static void dump_marks(void);
 
 static NORETURN void die_nicely(const char *err, va_list params)
 {
+       va_list cp;
        static int zombie;
-       char message[2 * PATH_MAX];
+       report_fn die_message_fn = get_die_message_routine();
 
-       vsnprintf(message, sizeof(message), err, params);
-       fputs("fatal: ", stderr);
-       fputs(message, stderr);
-       fputc('\n', stderr);
+       va_copy(cp, params);
+       die_message_fn(err, params);
 
        if (!zombie) {
+               char message[2 * PATH_MAX];
+
                zombie = 1;
+               vsnprintf(message, sizeof(message), err, cp);
                write_crash_report(message);
                end_packfile();
                unkeep_all_packs();
@@ -427,7 +442,7 @@ static void set_checkpoint_signal(void)
 
 #else
 
-static void checkpoint_signal(int signo)
+static void checkpoint_signal(int signo UNUSED)
 {
        checkpoint_requested = 1;
 }
@@ -856,7 +871,7 @@ static void end_packfile(void)
                struct tag *t;
 
                close_pack_windows(pack_data);
-               finalize_hashfile(pack_file, cur_pack_oid.hash, 0);
+               finalize_hashfile(pack_file, cur_pack_oid.hash, FSYNC_COMPONENT_PACK, 0);
                fixup_pack_header_footer(pack_data->pack_fd, pack_data->hash,
                                         pack_data->pack_name, object_count,
                                         cur_pack_oid.hash, pack_size);
@@ -935,8 +950,8 @@ static int store_object(
        git_hash_ctx c;
        git_zstream s;
 
-       hdrlen = xsnprintf((char *)hdr, sizeof(hdr), "%s %lu",
-                          type_name(type), (unsigned long)dat->len) + 1;
+       hdrlen = format_object_header((char *)hdr, sizeof(hdr), type,
+                                     dat->len);
        the_hash_algo->init_fn(&c);
        the_hash_algo->update_fn(&c, hdr, hdrlen);
        the_hash_algo->update_fn(&c, dat->buf, dat->len);
@@ -1089,7 +1104,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
        hashfile_checkpoint(pack_file, &checkpoint);
        offset = checkpoint.offset;
 
-       hdrlen = xsnprintf((char *)out_buf, out_sz, "blob %" PRIuMAX, len) + 1;
+       hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len);
 
        the_hash_algo->init_fn(&c);
        the_hash_algo->update_fn(&c, out_buf, hdrlen);
@@ -1256,7 +1271,7 @@ static void load_tree(struct tree_entry *root)
                        die("Can't load tree %s", oid_to_hex(oid));
        } else {
                enum object_type type;
-               buf = read_object_file(oid, &type, &size);
+               buf = repo_read_object_file(the_repository, oid, &type, &size);
                if (!buf || type != OBJ_TREE)
                        die("Can't load tree %s", oid_to_hex(oid));
        }
@@ -1616,7 +1631,7 @@ static int update_branch(struct branch *b)
                if (!old_cmit || !new_cmit)
                        return error("Branch %s is missing commits.", b->name);
 
-               if (!in_merge_bases(old_cmit, new_cmit)) {
+               if (!repo_in_merge_bases(the_repository, old_cmit, new_cmit)) {
                        warning("Not updating %s"
                                " (new tip %s does not contain %s)",
                                b->name, oid_to_hex(&b->oid),
@@ -2477,11 +2492,11 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
                if (commit_oe->type != OBJ_COMMIT)
                        die("Mark :%" PRIuMAX " not a commit", commit_mark);
                oidcpy(&commit_oid, &commit_oe->idx.oid);
-       } else if (!get_oid(p, &commit_oid)) {
+       } else if (!repo_get_oid(the_repository, p, &commit_oid)) {
                unsigned long size;
                char *buf = read_object_with_reference(the_repository,
                                                       &commit_oid,
-                                                      commit_type, &size,
+                                                      OBJ_COMMIT, &size,
                                                       &commit_oid);
                if (!buf || size < the_hash_algo->hexsz + 6)
                        die("Not a valid commit: %s", p);
@@ -2553,7 +2568,7 @@ static void parse_from_existing(struct branch *b)
                char *buf;
 
                buf = read_object_with_reference(the_repository,
-                                                &b->oid, commit_type, &size,
+                                                &b->oid, OBJ_COMMIT, &size,
                                                 &b->oid);
                parse_from_commit(b, buf, size);
                free(buf);
@@ -2590,7 +2605,7 @@ static int parse_objectish(struct branch *b, const char *objectish)
                        } else
                                parse_from_existing(b);
                }
-       } else if (!get_oid(objectish, &b->oid)) {
+       } else if (!repo_get_oid(the_repository, objectish, &b->oid)) {
                parse_from_existing(b);
                if (is_null_oid(&b->oid))
                        b->delete = 1;
@@ -2645,11 +2660,11 @@ static struct hash_list *parse_merge(unsigned int *count)
                        if (oe->type != OBJ_COMMIT)
                                die("Mark :%" PRIuMAX " not a commit", idnum);
                        oidcpy(&n->oid, &oe->idx.oid);
-               } else if (!get_oid(from, &n->oid)) {
+               } else if (!repo_get_oid(the_repository, from, &n->oid)) {
                        unsigned long size;
                        char *buf = read_object_with_reference(the_repository,
                                                               &n->oid,
-                                                              commit_type,
+                                                              OBJ_COMMIT,
                                                               &size, &n->oid);
                        if (!buf || size < the_hash_algo->hexsz + 6)
                                die("Not a valid commit: %s", from);
@@ -2818,7 +2833,7 @@ static void parse_new_tag(const char *arg)
                oe = find_mark(marks, from_mark);
                type = oe->type;
                oidcpy(&oid, &oe->idx.oid);
-       } else if (!get_oid(from, &oid)) {
+       } else if (!repo_get_oid(the_repository, from, &oid)) {
                struct object_entry *oe = find_object(&oid);
                if (!oe) {
                        type = oid_object_info(the_repository, &oid, NULL);
@@ -2927,7 +2942,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
        char *buf;
 
        if (!oe || oe->pack_id == MAX_PACK_ID) {
-               buf = read_object_file(oid, &type, &size);
+               buf = repo_read_object_file(the_repository, oid, &type, &size);
        } else {
                type = oe->type;
                buf = gfi_unpack_entry(oe, &size);
@@ -3035,7 +3050,8 @@ static struct object_entry *dereference(struct object_entry *oe,
                buf = gfi_unpack_entry(oe, &size);
        } else {
                enum object_type unused;
-               buf = read_object_file(oid, &unused, &size);
+               buf = repo_read_object_file(the_repository, oid, &unused,
+                                           &size);
        }
        if (!buf)
                die("Can't load object %s", oid_to_hex(oid));
@@ -3456,7 +3472,7 @@ static void git_pack_config(void)
                pack_idx_opts.version = indexversion_value;
                if (pack_idx_opts.version > 2)
                        git_die_config("pack.indexversion",
-                                       "bad pack.indexversion=%"PRIu32, pack_idx_opts.version);
+                                       "bad pack.indexVersion=%"PRIu32, pack_idx_opts.version);
        }
        if (!git_config_get_ulong("pack.packsizelimit", &packsizelimit_value))
                max_packsize = packsizelimit_value;