notes-merge: convert struct notes_merge_pair to struct object_id
Convert each of this structure's members from an unsigned char array to a struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
60af7691db
commit
e910bb1e79
127
notes-merge.c
127
notes-merge.c
@ -12,7 +12,7 @@
|
|||||||
#include "notes-utils.h"
|
#include "notes-utils.h"
|
||||||
|
|
||||||
struct notes_merge_pair {
|
struct notes_merge_pair {
|
||||||
unsigned char obj[20], base[20], local[20], remote[20];
|
struct object_id obj, base, local, remote;
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_notes_merge_options(struct notes_merge_options *o)
|
void init_notes_merge_options(struct notes_merge_options *o)
|
||||||
@ -75,7 +75,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
|
|||||||
int i = last_index < len ? last_index : len - 1;
|
int i = last_index < len ? last_index : len - 1;
|
||||||
int prev_cmp = 0, cmp = -1;
|
int prev_cmp = 0, cmp = -1;
|
||||||
while (i >= 0 && i < len) {
|
while (i >= 0 && i < len) {
|
||||||
cmp = hashcmp(obj, list[i].obj);
|
cmp = hashcmp(obj, list[i].obj.hash);
|
||||||
if (!cmp) /* obj belongs @ i */
|
if (!cmp) /* obj belongs @ i */
|
||||||
break;
|
break;
|
||||||
else if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */
|
else if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */
|
||||||
@ -108,9 +108,10 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
|
|||||||
return list + i;
|
return list + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char uninitialized[20] =
|
static struct object_id uninitialized = {
|
||||||
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" \
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" \
|
||||||
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
||||||
|
};
|
||||||
|
|
||||||
static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
|
static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
|
||||||
const unsigned char *base,
|
const unsigned char *base,
|
||||||
@ -149,25 +150,25 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
|
|||||||
mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);
|
mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);
|
||||||
if (occupied) {
|
if (occupied) {
|
||||||
/* We've found an addition/deletion pair */
|
/* We've found an addition/deletion pair */
|
||||||
assert(!hashcmp(mp->obj, obj));
|
assert(!hashcmp(mp->obj.hash, obj));
|
||||||
if (is_null_oid(&p->one->oid)) { /* addition */
|
if (is_null_oid(&p->one->oid)) { /* addition */
|
||||||
assert(is_null_sha1(mp->remote));
|
assert(is_null_oid(&mp->remote));
|
||||||
hashcpy(mp->remote, p->two->oid.hash);
|
oidcpy(&mp->remote, &p->two->oid);
|
||||||
} else if (is_null_oid(&p->two->oid)) { /* deletion */
|
} else if (is_null_oid(&p->two->oid)) { /* deletion */
|
||||||
assert(is_null_sha1(mp->base));
|
assert(is_null_oid(&mp->base));
|
||||||
hashcpy(mp->base, p->one->oid.hash);
|
oidcpy(&mp->base, &p->one->oid);
|
||||||
} else
|
} else
|
||||||
assert(!"Invalid existing change recorded");
|
assert(!"Invalid existing change recorded");
|
||||||
} else {
|
} else {
|
||||||
hashcpy(mp->obj, obj);
|
hashcpy(mp->obj.hash, obj);
|
||||||
hashcpy(mp->base, p->one->oid.hash);
|
oidcpy(&mp->base, &p->one->oid);
|
||||||
hashcpy(mp->local, uninitialized);
|
oidcpy(&mp->local, &uninitialized);
|
||||||
hashcpy(mp->remote, p->two->oid.hash);
|
oidcpy(&mp->remote, &p->two->oid);
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
trace_printf("\t\tStored remote change for %s: %.7s -> %.7s\n",
|
trace_printf("\t\tStored remote change for %s: %.7s -> %.7s\n",
|
||||||
sha1_to_hex(mp->obj), sha1_to_hex(mp->base),
|
oid_to_hex(&mp->obj), oid_to_hex(&mp->base),
|
||||||
sha1_to_hex(mp->remote));
|
oid_to_hex(&mp->remote));
|
||||||
}
|
}
|
||||||
diff_flush(&opt);
|
diff_flush(&opt);
|
||||||
clear_pathspec(&opt.pathspec);
|
clear_pathspec(&opt.pathspec);
|
||||||
@ -216,7 +217,7 @@ static void diff_tree_local(struct notes_merge_options *o,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!hashcmp(mp->obj, obj));
|
assert(!hashcmp(mp->obj.hash, obj));
|
||||||
if (is_null_oid(&p->two->oid)) { /* deletion */
|
if (is_null_oid(&p->two->oid)) { /* deletion */
|
||||||
/*
|
/*
|
||||||
* Either this is a true deletion (1), or it is part
|
* Either this is a true deletion (1), or it is part
|
||||||
@ -227,8 +228,8 @@ static void diff_tree_local(struct notes_merge_options *o,
|
|||||||
* (3) mp->local is uninitialized; set it to null_sha1
|
* (3) mp->local is uninitialized; set it to null_sha1
|
||||||
* (will be overwritten by following addition)
|
* (will be overwritten by following addition)
|
||||||
*/
|
*/
|
||||||
if (!hashcmp(mp->local, uninitialized))
|
if (!oidcmp(&mp->local, &uninitialized))
|
||||||
hashclr(mp->local);
|
oidclr(&mp->local);
|
||||||
} else if (is_null_oid(&p->one->oid)) { /* addition */
|
} else if (is_null_oid(&p->one->oid)) { /* addition */
|
||||||
/*
|
/*
|
||||||
* Either this is a true addition (1), or it is part
|
* Either this is a true addition (1), or it is part
|
||||||
@ -238,22 +239,22 @@ static void diff_tree_local(struct notes_merge_options *o,
|
|||||||
* (2) mp->local is uninitialized; set to p->two->sha1
|
* (2) mp->local is uninitialized; set to p->two->sha1
|
||||||
* (3) mp->local is null_sha1; set to p->two->sha1
|
* (3) mp->local is null_sha1; set to p->two->sha1
|
||||||
*/
|
*/
|
||||||
assert(is_null_sha1(mp->local) ||
|
assert(is_null_oid(&mp->local) ||
|
||||||
!hashcmp(mp->local, uninitialized));
|
!oidcmp(&mp->local, &uninitialized));
|
||||||
hashcpy(mp->local, p->two->oid.hash);
|
oidcpy(&mp->local, &p->two->oid);
|
||||||
} else { /* modification */
|
} else { /* modification */
|
||||||
/*
|
/*
|
||||||
* This is a true modification. p->one->sha1 shall
|
* This is a true modification. p->one->sha1 shall
|
||||||
* match mp->base, and mp->local shall be uninitialized.
|
* match mp->base, and mp->local shall be uninitialized.
|
||||||
* Set mp->local to p->two->sha1.
|
* Set mp->local to p->two->sha1.
|
||||||
*/
|
*/
|
||||||
assert(!hashcmp(p->one->oid.hash, mp->base));
|
assert(!oidcmp(&p->one->oid, &mp->base));
|
||||||
assert(!hashcmp(mp->local, uninitialized));
|
assert(!oidcmp(&mp->local, &uninitialized));
|
||||||
hashcpy(mp->local, p->two->oid.hash);
|
oidcpy(&mp->local, &p->two->oid);
|
||||||
}
|
}
|
||||||
trace_printf("\t\tStored local change for %s: %.7s -> %.7s\n",
|
trace_printf("\t\tStored local change for %s: %.7s -> %.7s\n",
|
||||||
sha1_to_hex(mp->obj), sha1_to_hex(mp->base),
|
oid_to_hex(&mp->obj), oid_to_hex(&mp->base),
|
||||||
sha1_to_hex(mp->local));
|
oid_to_hex(&mp->local));
|
||||||
}
|
}
|
||||||
diff_flush(&opt);
|
diff_flush(&opt);
|
||||||
clear_pathspec(&opt.pathspec);
|
clear_pathspec(&opt.pathspec);
|
||||||
@ -343,11 +344,11 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
|
|||||||
mmfile_t base, local, remote;
|
mmfile_t base, local, remote;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
read_mmblob(&base, p->base);
|
read_mmblob(&base, p->base.hash);
|
||||||
read_mmblob(&local, p->local);
|
read_mmblob(&local, p->local.hash);
|
||||||
read_mmblob(&remote, p->remote);
|
read_mmblob(&remote, p->remote.hash);
|
||||||
|
|
||||||
status = ll_merge(&result_buf, sha1_to_hex(p->obj), &base, NULL,
|
status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
|
||||||
&local, o->local_ref, &remote, o->remote_ref, NULL);
|
&local, o->local_ref, &remote, o->remote_ref, NULL);
|
||||||
|
|
||||||
free(base.ptr);
|
free(base.ptr);
|
||||||
@ -357,7 +358,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
|
|||||||
if ((status < 0) || !result_buf.ptr)
|
if ((status < 0) || !result_buf.ptr)
|
||||||
die("Failed to execute internal merge");
|
die("Failed to execute internal merge");
|
||||||
|
|
||||||
write_buf_to_worktree(p->obj, result_buf.ptr, result_buf.size);
|
write_buf_to_worktree(p->obj.hash, result_buf.ptr, result_buf.size);
|
||||||
free(result_buf.ptr);
|
free(result_buf.ptr);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -372,51 +373,52 @@ static int merge_one_change_manual(struct notes_merge_options *o,
|
|||||||
|
|
||||||
trace_printf("\t\t\tmerge_one_change_manual(obj = %.7s, base = %.7s, "
|
trace_printf("\t\t\tmerge_one_change_manual(obj = %.7s, base = %.7s, "
|
||||||
"local = %.7s, remote = %.7s)\n",
|
"local = %.7s, remote = %.7s)\n",
|
||||||
sha1_to_hex(p->obj), sha1_to_hex(p->base),
|
oid_to_hex(&p->obj), oid_to_hex(&p->base),
|
||||||
sha1_to_hex(p->local), sha1_to_hex(p->remote));
|
oid_to_hex(&p->local), oid_to_hex(&p->remote));
|
||||||
|
|
||||||
/* add "Conflicts:" section to commit message first time through */
|
/* add "Conflicts:" section to commit message first time through */
|
||||||
if (!o->has_worktree)
|
if (!o->has_worktree)
|
||||||
strbuf_addstr(&(o->commit_msg), "\n\nConflicts:\n");
|
strbuf_addstr(&(o->commit_msg), "\n\nConflicts:\n");
|
||||||
|
|
||||||
strbuf_addf(&(o->commit_msg), "\t%s\n", sha1_to_hex(p->obj));
|
strbuf_addf(&(o->commit_msg), "\t%s\n", oid_to_hex(&p->obj));
|
||||||
|
|
||||||
if (o->verbosity >= 2)
|
if (o->verbosity >= 2)
|
||||||
printf("Auto-merging notes for %s\n", sha1_to_hex(p->obj));
|
printf("Auto-merging notes for %s\n", oid_to_hex(&p->obj));
|
||||||
check_notes_merge_worktree(o);
|
check_notes_merge_worktree(o);
|
||||||
if (is_null_sha1(p->local)) {
|
if (is_null_oid(&p->local)) {
|
||||||
/* D/F conflict, checkout p->remote */
|
/* D/F conflict, checkout p->remote */
|
||||||
assert(!is_null_sha1(p->remote));
|
assert(!is_null_oid(&p->remote));
|
||||||
if (o->verbosity >= 1)
|
if (o->verbosity >= 1)
|
||||||
printf("CONFLICT (delete/modify): Notes for object %s "
|
printf("CONFLICT (delete/modify): Notes for object %s "
|
||||||
"deleted in %s and modified in %s. Version from %s "
|
"deleted in %s and modified in %s. Version from %s "
|
||||||
"left in tree.\n",
|
"left in tree.\n",
|
||||||
sha1_to_hex(p->obj), lref, rref, rref);
|
oid_to_hex(&p->obj), lref, rref, rref);
|
||||||
write_note_to_worktree(p->obj, p->remote);
|
write_note_to_worktree(p->obj.hash, p->remote.hash);
|
||||||
} else if (is_null_sha1(p->remote)) {
|
} else if (is_null_oid(&p->remote)) {
|
||||||
/* D/F conflict, checkout p->local */
|
/* D/F conflict, checkout p->local */
|
||||||
assert(!is_null_sha1(p->local));
|
assert(!is_null_oid(&p->local));
|
||||||
if (o->verbosity >= 1)
|
if (o->verbosity >= 1)
|
||||||
printf("CONFLICT (delete/modify): Notes for object %s "
|
printf("CONFLICT (delete/modify): Notes for object %s "
|
||||||
"deleted in %s and modified in %s. Version from %s "
|
"deleted in %s and modified in %s. Version from %s "
|
||||||
"left in tree.\n",
|
"left in tree.\n",
|
||||||
sha1_to_hex(p->obj), rref, lref, lref);
|
oid_to_hex(&p->obj), rref, lref, lref);
|
||||||
write_note_to_worktree(p->obj, p->local);
|
write_note_to_worktree(p->obj.hash, p->local.hash);
|
||||||
} else {
|
} else {
|
||||||
/* "regular" conflict, checkout result of ll_merge() */
|
/* "regular" conflict, checkout result of ll_merge() */
|
||||||
const char *reason = "content";
|
const char *reason = "content";
|
||||||
if (is_null_sha1(p->base))
|
if (is_null_oid(&p->base))
|
||||||
reason = "add/add";
|
reason = "add/add";
|
||||||
assert(!is_null_sha1(p->local));
|
assert(!is_null_oid(&p->local));
|
||||||
assert(!is_null_sha1(p->remote));
|
assert(!is_null_oid(&p->remote));
|
||||||
if (o->verbosity >= 1)
|
if (o->verbosity >= 1)
|
||||||
printf("CONFLICT (%s): Merge conflict in notes for "
|
printf("CONFLICT (%s): Merge conflict in notes for "
|
||||||
"object %s\n", reason, sha1_to_hex(p->obj));
|
"object %s\n", reason,
|
||||||
|
oid_to_hex(&p->obj));
|
||||||
ll_merge_in_worktree(o, p);
|
ll_merge_in_worktree(o, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_printf("\t\t\tremoving from partial merge result\n");
|
trace_printf("\t\t\tremoving from partial merge result\n");
|
||||||
remove_note(t, p->obj);
|
remove_note(t, p->obj.hash);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -435,29 +437,29 @@ static int merge_one_change(struct notes_merge_options *o,
|
|||||||
case NOTES_MERGE_RESOLVE_OURS:
|
case NOTES_MERGE_RESOLVE_OURS:
|
||||||
if (o->verbosity >= 2)
|
if (o->verbosity >= 2)
|
||||||
printf("Using local notes for %s\n",
|
printf("Using local notes for %s\n",
|
||||||
sha1_to_hex(p->obj));
|
oid_to_hex(&p->obj));
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
return 0;
|
return 0;
|
||||||
case NOTES_MERGE_RESOLVE_THEIRS:
|
case NOTES_MERGE_RESOLVE_THEIRS:
|
||||||
if (o->verbosity >= 2)
|
if (o->verbosity >= 2)
|
||||||
printf("Using remote notes for %s\n",
|
printf("Using remote notes for %s\n",
|
||||||
sha1_to_hex(p->obj));
|
oid_to_hex(&p->obj));
|
||||||
if (add_note(t, p->obj, p->remote, combine_notes_overwrite))
|
if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))
|
||||||
die("BUG: combine_notes_overwrite failed");
|
die("BUG: combine_notes_overwrite failed");
|
||||||
return 0;
|
return 0;
|
||||||
case NOTES_MERGE_RESOLVE_UNION:
|
case NOTES_MERGE_RESOLVE_UNION:
|
||||||
if (o->verbosity >= 2)
|
if (o->verbosity >= 2)
|
||||||
printf("Concatenating local and remote notes for %s\n",
|
printf("Concatenating local and remote notes for %s\n",
|
||||||
sha1_to_hex(p->obj));
|
oid_to_hex(&p->obj));
|
||||||
if (add_note(t, p->obj, p->remote, combine_notes_concatenate))
|
if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))
|
||||||
die("failed to concatenate notes "
|
die("failed to concatenate notes "
|
||||||
"(combine_notes_concatenate)");
|
"(combine_notes_concatenate)");
|
||||||
return 0;
|
return 0;
|
||||||
case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
|
case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
|
||||||
if (o->verbosity >= 2)
|
if (o->verbosity >= 2)
|
||||||
printf("Concatenating unique lines in local and remote "
|
printf("Concatenating unique lines in local and remote "
|
||||||
"notes for %s\n", sha1_to_hex(p->obj));
|
"notes for %s\n", oid_to_hex(&p->obj));
|
||||||
if (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq))
|
if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq))
|
||||||
die("failed to concatenate notes "
|
die("failed to concatenate notes "
|
||||||
"(combine_notes_cat_sort_uniq)");
|
"(combine_notes_cat_sort_uniq)");
|
||||||
return 0;
|
return 0;
|
||||||
@ -475,20 +477,21 @@ static int merge_changes(struct notes_merge_options *o,
|
|||||||
for (i = 0; i < *num_changes; i++) {
|
for (i = 0; i < *num_changes; i++) {
|
||||||
struct notes_merge_pair *p = changes + i;
|
struct notes_merge_pair *p = changes + i;
|
||||||
trace_printf("\t\t%.7s: %.7s -> %.7s/%.7s\n",
|
trace_printf("\t\t%.7s: %.7s -> %.7s/%.7s\n",
|
||||||
sha1_to_hex(p->obj), sha1_to_hex(p->base),
|
oid_to_hex(&p->obj), oid_to_hex(&p->base),
|
||||||
sha1_to_hex(p->local), sha1_to_hex(p->remote));
|
oid_to_hex(&p->local),
|
||||||
|
oid_to_hex(&p->remote));
|
||||||
|
|
||||||
if (!hashcmp(p->base, p->remote)) {
|
if (!oidcmp(&p->base, &p->remote)) {
|
||||||
/* no remote change; nothing to do */
|
/* no remote change; nothing to do */
|
||||||
trace_printf("\t\t\tskipping (no remote change)\n");
|
trace_printf("\t\t\tskipping (no remote change)\n");
|
||||||
} else if (!hashcmp(p->local, p->remote)) {
|
} else if (!oidcmp(&p->local, &p->remote)) {
|
||||||
/* same change in local and remote; nothing to do */
|
/* same change in local and remote; nothing to do */
|
||||||
trace_printf("\t\t\tskipping (local == remote)\n");
|
trace_printf("\t\t\tskipping (local == remote)\n");
|
||||||
} else if (!hashcmp(p->local, uninitialized) ||
|
} else if (!oidcmp(&p->local, &uninitialized) ||
|
||||||
!hashcmp(p->local, p->base)) {
|
!oidcmp(&p->local, &p->base)) {
|
||||||
/* no local change; adopt remote change */
|
/* no local change; adopt remote change */
|
||||||
trace_printf("\t\t\tno local change, adopted remote\n");
|
trace_printf("\t\t\tno local change, adopted remote\n");
|
||||||
if (add_note(t, p->obj, p->remote,
|
if (add_note(t, p->obj.hash, p->remote.hash,
|
||||||
combine_notes_overwrite))
|
combine_notes_overwrite))
|
||||||
die("BUG: combine_notes_overwrite failed");
|
die("BUG: combine_notes_overwrite failed");
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user