diff.c: color moved lines differently
[gitweb.git] / fast-import.c
index ba886c9e7e2036f6d533ae2ed754b06e4bd0958f..a959161b4631e134602aa9b5502105ee5c5bcfb8 100644 (file)
@@ -154,6 +154,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "blob.h"
@@ -280,7 +281,7 @@ struct recent_command {
 };
 
 /* Configured limits on output */
-static unsigned long max_depth = 10;
+static unsigned long max_depth = 50;
 static off_t max_packsize;
 static int unpack_limit = 100;
 static int force_update;
@@ -565,7 +566,7 @@ static struct object_entry *new_object(struct object_id *oid)
                alloc_objects(object_entry_alloc);
 
        e = blocks->next_free++;
-       hashcpy(e->idx.sha1, oid->hash);
+       oidcpy(&e->idx.oid, oid);
        return e;
 }
 
@@ -574,7 +575,7 @@ static struct object_entry *find_object(struct object_id *oid)
        unsigned int h = oid->hash[0] << 8 | oid->hash[1];
        struct object_entry *e;
        for (e = object_table[h]; e; e = e->next)
-               if (!hashcmp(oid->hash, e->idx.sha1))
+               if (!oidcmp(oid, &e->idx.oid))
                        return e;
        return NULL;
 }
@@ -585,7 +586,7 @@ static struct object_entry *insert_object(struct object_id *oid)
        struct object_entry *e = object_table[h];
 
        while (e) {
-               if (!hashcmp(oid->hash, e->idx.sha1))
+               if (!oidcmp(oid, &e->idx.oid))
                        return e;
                e = e->next;
        }
@@ -1063,8 +1064,7 @@ static void end_packfile(void)
                close(pack_data->pack_fd);
                unlink_or_warn(pack_data->pack_name);
        }
-       free(pack_data);
-       pack_data = NULL;
+       FREE_AND_NULL(pack_data);
        running = 0;
 
        /* We can't carry a delta across packfiles. */
@@ -1149,8 +1149,7 @@ static int store_object(
 
                /* We cannot carry a delta into the new pack. */
                if (delta) {
-                       free(delta);
-                       delta = NULL;
+                       FREE_AND_NULL(delta);
 
                        git_deflate_init(&s, pack_compression_level);
                        s.next_in = (void *)dat->buf;
@@ -1763,8 +1762,8 @@ static int update_branch(struct branch *b)
        if (!force_update && !is_null_oid(&old_oid)) {
                struct commit *old_cmit, *new_cmit;
 
-               old_cmit = lookup_commit_reference_gently(old_oid.hash, 0);
-               new_cmit = lookup_commit_reference_gently(b->oid.hash, 0);
+               old_cmit = lookup_commit_reference_gently(&old_oid, 0);
+               new_cmit = lookup_commit_reference_gently(&b->oid, 0);
                if (!old_cmit || !new_cmit)
                        return error("Branch %s is missing commits.", b->name);
 
@@ -1849,7 +1848,7 @@ static void dump_marks_helper(FILE *f,
                for (k = 0; k < 1024; k++) {
                        if (m->data.marked[k])
                                fprintf(f, ":%" PRIuMAX " %s\n", base + k,
-                                       sha1_to_hex(m->data.marked[k]->idx.sha1));
+                                       oid_to_hex(&m->data.marked[k]->idx.oid));
                }
        }
 }
@@ -2389,7 +2388,7 @@ static void file_change_m(const char *p, struct branch *b)
 
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
-               hashcpy(oid.hash, oe->idx.sha1);
+               oidcpy(&oid, &oe->idx.oid);
        } else if (skip_prefix(p, "inline ", &p)) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
@@ -2555,7 +2554,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
        /* <dataref> or 'inline' */
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
-               hashcpy(oid.hash, oe->idx.sha1);
+               oidcpy(&oid, &oe->idx.oid);
        } else if (skip_prefix(p, "inline ", &p)) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
@@ -2578,7 +2577,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
                struct object_entry *commit_oe = find_mark(commit_mark);
                if (commit_oe->type != OBJ_COMMIT)
                        die("Mark :%" PRIuMAX " not a commit", commit_mark);
-               hashcpy(commit_oid.hash, commit_oe->idx.sha1);
+               oidcpy(&commit_oid, &commit_oe->idx.oid);
        } else if (!get_oid(p, &commit_oid)) {
                unsigned long size;
                char *buf = read_object_with_reference(commit_oid.hash,
@@ -2683,8 +2682,8 @@ static int parse_from(struct branch *b)
                struct object_entry *oe = find_mark(idnum);
                if (oe->type != OBJ_COMMIT)
                        die("Mark :%" PRIuMAX " not a commit", idnum);
-               if (hashcmp(b->oid.hash, oe->idx.sha1)) {
-                       hashcpy(b->oid.hash, oe->idx.sha1);
+               if (oidcmp(&b->oid, &oe->idx.oid)) {
+                       oidcpy(&b->oid, &oe->idx.oid);
                        if (oe->pack_id != MAX_PACK_ID) {
                                unsigned long size;
                                char *buf = gfi_unpack_entry(oe, &size);
@@ -2727,7 +2726,7 @@ static struct hash_list *parse_merge(unsigned int *count)
                        struct object_entry *oe = find_mark(idnum);
                        if (oe->type != OBJ_COMMIT)
                                die("Mark :%" PRIuMAX " not a commit", idnum);
-                       hashcpy(n->oid.hash, oe->idx.sha1);
+                       oidcpy(&n->oid, &oe->idx.oid);
                } else if (!get_oid(from, &n->oid)) {
                        unsigned long size;
                        char *buf = read_object_with_reference(n->oid.hash,
@@ -2884,7 +2883,7 @@ static void parse_new_tag(const char *arg)
                from_mark = parse_mark_ref_eol(from);
                oe = find_mark(from_mark);
                type = oe->type;
-               hashcpy(oid.hash, oe->idx.sha1);
+               oidcpy(&oid, &oe->idx.oid);
        } else if (!get_oid(from, &oid)) {
                struct object_entry *oe = find_object(&oid);
                if (!oe) {
@@ -3014,7 +3013,7 @@ static void parse_get_mark(const char *p)
        if (!oe)
                die("Unknown mark: %s", command_buf.buf);
 
-       xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
+       xsnprintf(output, sizeof(output), "%s\n", oid_to_hex(&oe->idx.oid));
        cat_blob_write(output, GIT_SHA1_HEXSZ + 1);
 }
 
@@ -3028,7 +3027,7 @@ static void parse_cat_blob(const char *p)
                oe = find_mark(parse_mark_ref_eol(p));
                if (!oe)
                        die("Unknown mark: %s", command_buf.buf);
-               hashcpy(oid.hash, oe->idx.sha1);
+               oidcpy(&oid, &oe->idx.oid);
        } else {
                if (parse_oid_hex(p, &oid, &p))
                        die("Invalid dataref: %s", command_buf.buf);
@@ -3100,7 +3099,7 @@ static struct object_entry *parse_treeish_dataref(const char **p)
                e = find_mark(parse_mark_ref_space(p));
                if (!e)
                        die("Unknown mark: %s", command_buf.buf);
-               hashcpy(oid.hash, e->idx.sha1);
+               oidcpy(&oid, &e->idx.oid);
        } else {        /* <sha1> */
                if (parse_oid_hex(*p, &oid, p))
                        die("Invalid dataref: %s", command_buf.buf);
@@ -3154,7 +3153,7 @@ static void parse_ls(const char *p, struct branch *b)
        } else {
                struct object_entry *e = parse_treeish_dataref(&p);
                root = new_tree_entry();
-               hashcpy(root->versions[1].oid.hash, e->idx.sha1);
+               oidcpy(&root->versions[1].oid, &e->idx.oid);
                if (!is_null_oid(&root->versions[1].oid))
                        root->versions[1].mode = S_IFDIR;
                load_tree(root);
@@ -3285,9 +3284,7 @@ static void option_export_pack_edges(const char *edges)
 {
        if (pack_edges)
                fclose(pack_edges);
-       pack_edges = fopen(edges, "a");
-       if (!pack_edges)
-               die_errno("Cannot open '%s'", edges);
+       pack_edges = xfopen(edges, "a");
 }
 
 static int parse_one_option(const char *option)