Merge branch 'js/msgfmt-on-windows' of ../git-gui into js/git-gui-msgfmt-on-windows
[gitweb.git] / notes-merge.c
index 9dbf7f6a31e9bfbe673670d8c9f9a86c60e03beb..70e3fbeefbe24233a545e75c0322a8a310778e43 100644 (file)
@@ -22,21 +22,21 @@ void init_notes_merge_options(struct notes_merge_options *o)
        o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
 }
 
-static int path_to_sha1(const char *path, unsigned char *sha1)
+static int path_to_oid(const char *path, struct object_id *oid)
 {
-       char hex_sha1[40];
+       char hex_oid[GIT_SHA1_HEXSZ];
        int i = 0;
-       while (*path && i < 40) {
+       while (*path && i < GIT_SHA1_HEXSZ) {
                if (*path != '/')
-                       hex_sha1[i++] = *path;
+                       hex_oid[i++] = *path;
                path++;
        }
-       if (*path || i != 40)
+       if (*path || i != GIT_SHA1_HEXSZ)
                return -1;
-       return get_sha1_hex(hex_sha1, sha1);
+       return get_oid_hex(hex_oid, oid);
 }
 
-static int verify_notes_filepair(struct diff_filepair *p, unsigned char *sha1)
+static int verify_notes_filepair(struct diff_filepair *p, struct object_id *oid)
 {
        switch (p->status) {
        case DIFF_STATUS_MODIFIED:
@@ -54,11 +54,11 @@ static int verify_notes_filepair(struct diff_filepair *p, unsigned char *sha1)
                return -1;
        }
        assert(!strcmp(p->one->path, p->two->path));
-       return path_to_sha1(p->one->path, sha1);
+       return path_to_oid(p->one->path, oid);
 }
 
 static struct notes_merge_pair *find_notes_merge_pair_pos(
-               struct notes_merge_pair *list, int len, unsigned char *obj,
+               struct notes_merge_pair *list, int len, struct object_id *obj,
                int insert_new, int *occupied)
 {
        /*
@@ -75,7 +75,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
        int i = last_index < len ? last_index : len - 1;
        int prev_cmp = 0, cmp = -1;
        while (i >= 0 && i < len) {
-               cmp = hashcmp(obj, list[i].obj.hash);
+               cmp = oidcmp(obj, &list[i].obj);
                if (!cmp) /* obj belongs @ i */
                        break;
                else if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */
@@ -114,8 +114,8 @@ static struct object_id uninitialized = {
 };
 
 static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
-                                                const unsigned char *base,
-                                                const unsigned char *remote,
+                                                const struct object_id *base,
+                                                const struct object_id *remote,
                                                 int *num_changes)
 {
        struct diff_options opt;
@@ -123,13 +123,13 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
        int i, len = 0;
 
        trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
-              sha1_to_hex(base), sha1_to_hex(remote));
+              oid_to_hex(base), oid_to_hex(remote));
 
        diff_setup(&opt);
        DIFF_OPT_SET(&opt, RECURSIVE);
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
-       diff_tree_sha1(base, remote, "", &opt);
+       diff_tree_oid(base, remote, "", &opt);
        diffcore_std(&opt);
 
        changes = xcalloc(diff_queued_diff.nr, sizeof(struct notes_merge_pair));
@@ -138,19 +138,19 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
                struct diff_filepair *p = diff_queued_diff.queue[i];
                struct notes_merge_pair *mp;
                int occupied;
-               unsigned char obj[20];
+               struct object_id obj;
 
-               if (verify_notes_filepair(p, obj)) {
+               if (verify_notes_filepair(p, &obj)) {
                        trace_printf("\t\tCannot merge entry '%s' (%c): "
                               "%.7s -> %.7s. Skipping!\n", p->one->path,
                               p->status, oid_to_hex(&p->one->oid),
                               oid_to_hex(&p->two->oid));
                        continue;
                }
-               mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);
+               mp = find_notes_merge_pair_pos(changes, len, &obj, 1, &occupied);
                if (occupied) {
                        /* We've found an addition/deletion pair */
-                       assert(!hashcmp(mp->obj.hash, obj));
+                       assert(!oidcmp(&mp->obj, &obj));
                        if (is_null_oid(&p->one->oid)) { /* addition */
                                assert(is_null_oid(&mp->remote));
                                oidcpy(&mp->remote, &p->two->oid);
@@ -160,7 +160,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
                        } else
                                assert(!"Invalid existing change recorded");
                } else {
-                       hashcpy(mp->obj.hash, obj);
+                       oidcpy(&mp->obj, &obj);
                        oidcpy(&mp->base, &p->one->oid);
                        oidcpy(&mp->local, &uninitialized);
                        oidcpy(&mp->remote, &p->two->oid);
@@ -179,45 +179,45 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
 
 static void diff_tree_local(struct notes_merge_options *o,
                            struct notes_merge_pair *changes, int len,
-                           const unsigned char *base,
-                           const unsigned char *local)
+                           const struct object_id *base,
+                           const struct object_id *local)
 {
        struct diff_options opt;
        int i;
 
        trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
-              len, sha1_to_hex(base), sha1_to_hex(local));
+              len, oid_to_hex(base), oid_to_hex(local));
 
        diff_setup(&opt);
        DIFF_OPT_SET(&opt, RECURSIVE);
        opt.output_format = DIFF_FORMAT_NO_OUTPUT;
        diff_setup_done(&opt);
-       diff_tree_sha1(base, local, "", &opt);
+       diff_tree_oid(base, local, "", &opt);
        diffcore_std(&opt);
 
        for (i = 0; i < diff_queued_diff.nr; i++) {
                struct diff_filepair *p = diff_queued_diff.queue[i];
                struct notes_merge_pair *mp;
                int match;
-               unsigned char obj[20];
+               struct object_id obj;
 
-               if (verify_notes_filepair(p, obj)) {
+               if (verify_notes_filepair(p, &obj)) {
                        trace_printf("\t\tCannot merge entry '%s' (%c): "
                               "%.7s -> %.7s. Skipping!\n", p->one->path,
                               p->status, oid_to_hex(&p->one->oid),
                               oid_to_hex(&p->two->oid));
                        continue;
                }
-               mp = find_notes_merge_pair_pos(changes, len, obj, 0, &match);
+               mp = find_notes_merge_pair_pos(changes, len, &obj, 0, &match);
                if (!match) {
                        trace_printf("\t\tIgnoring local-only change for %s: "
-                              "%.7s -> %.7s\n", sha1_to_hex(obj),
+                              "%.7s -> %.7s\n", oid_to_hex(&obj),
                               oid_to_hex(&p->one->oid),
                               oid_to_hex(&p->two->oid));
                        continue;
                }
 
-               assert(!hashcmp(mp->obj.hash, obj));
+               assert(!oidcmp(&mp->obj, &obj));
                if (is_null_oid(&p->two->oid)) { /* deletion */
                        /*
                         * Either this is a true deletion (1), or it is part
@@ -292,11 +292,11 @@ static void check_notes_merge_worktree(struct notes_merge_options *o)
                    git_path(NOTES_MERGE_WORKTREE));
 }
 
-static void write_buf_to_worktree(const unsigned char *obj,
+static void write_buf_to_worktree(const struct object_id *obj,
                                  const char *buf, unsigned long size)
 {
        int fd;
-       char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj));
+       char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));
        if (safe_create_leading_directories_const(path))
                die_errno("unable to create directory for '%s'", path);
 
@@ -320,19 +320,19 @@ static void write_buf_to_worktree(const unsigned char *obj,
        free(path);
 }
 
-static void write_note_to_worktree(const unsigned char *obj,
-                                  const unsigned char *note)
+static void write_note_to_worktree(const struct object_id *obj,
+                                  const struct object_id *note)
 {
        enum object_type type;
        unsigned long size;
-       void *buf = read_sha1_file(note, &type, &size);
+       void *buf = read_sha1_file(note->hash, &type, &size);
 
        if (!buf)
                die("cannot read note %s for object %s",
-                   sha1_to_hex(note), sha1_to_hex(obj));
+                   oid_to_hex(note), oid_to_hex(obj));
        if (type != OBJ_BLOB)
                die("blob expected in note %s for object %s",
-                   sha1_to_hex(note), sha1_to_hex(obj));
+                   oid_to_hex(note), oid_to_hex(obj));
        write_buf_to_worktree(obj, buf, size);
        free(buf);
 }
@@ -358,7 +358,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
        if ((status < 0) || !result_buf.ptr)
                die("Failed to execute internal merge");
 
-       write_buf_to_worktree(p->obj.hash, result_buf.ptr, result_buf.size);
+       write_buf_to_worktree(&p->obj, result_buf.ptr, result_buf.size);
        free(result_buf.ptr);
 
        return status;
@@ -393,7 +393,7 @@ static int merge_one_change_manual(struct notes_merge_options *o,
                                "deleted in %s and modified in %s. Version from %s "
                                "left in tree.\n",
                                oid_to_hex(&p->obj), lref, rref, rref);
-               write_note_to_worktree(p->obj.hash, p->remote.hash);
+               write_note_to_worktree(&p->obj, &p->remote);
        } else if (is_null_oid(&p->remote)) {
                /* D/F conflict, checkout p->local */
                assert(!is_null_oid(&p->local));
@@ -402,7 +402,7 @@ static int merge_one_change_manual(struct notes_merge_options *o,
                                "deleted in %s and modified in %s. Version from %s "
                                "left in tree.\n",
                                oid_to_hex(&p->obj), rref, lref, lref);
-               write_note_to_worktree(p->obj.hash, p->local.hash);
+               write_note_to_worktree(&p->obj, &p->local);
        } else {
                /* "regular" conflict, checkout result of ll_merge() */
                const char *reason = "content";
@@ -505,16 +505,17 @@ static int merge_changes(struct notes_merge_options *o,
 }
 
 static int merge_from_diffs(struct notes_merge_options *o,
-                           const unsigned char *base,
-                           const unsigned char *local,
-                           const unsigned char *remote, struct notes_tree *t)
+                           const struct object_id *base,
+                           const struct object_id *local,
+                           const struct object_id *remote,
+                           struct notes_tree *t)
 {
        struct notes_merge_pair *changes;
        int num_changes, conflicts;
 
        trace_printf("\tmerge_from_diffs(base = %.7s, local = %.7s, "
-              "remote = %.7s)\n", sha1_to_hex(base), sha1_to_hex(local),
-              sha1_to_hex(remote));
+              "remote = %.7s)\n", oid_to_hex(base), oid_to_hex(local),
+              oid_to_hex(remote));
 
        changes = diff_tree_remote(o, base, remote, &num_changes);
        diff_tree_local(o, changes, num_changes, base, local);
@@ -636,8 +637,8 @@ int notes_merge(struct notes_merge_options *o,
                goto found_result;
        }
 
-       result = merge_from_diffs(o, base_tree_oid->hash, local->tree->object.oid.hash,
-                                 remote->tree->object.oid.hash, local_tree);
+       result = merge_from_diffs(o, base_tree_oid, &local->tree->object.oid,
+                                 &remote->tree->object.oid, local_tree);
 
        if (result != 0) { /* non-trivial merge (with or without conflicts) */
                /* Commit (partial) result */