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:
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)
{
/*
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 */
};
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;
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));
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);
} 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);
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
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);
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);
}
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;
"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));
"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";
}
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);
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 */