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>

brian m. carlson committed Sep 5, 2016 at 20:08 UTC e910bb1e79d53d43d07013b4d7e58c9f3ec53c8d
1 file changed +65 -62
notes-merge.c
+65 -62
@@ -12,7 +12,7 @@
12 #include "notes-utils.h"
13
14 struct notes_merge_pair {
15 - unsigned char obj[20], base[20], local[20], remote[20];
15 + struct object_id obj, base, local, remote;
16 };
17
18 void init_notes_merge_options(struct notes_merge_options *o)
@@ -75,7 +75,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
75 int i = last_index < len ? last_index : len - 1;
76 int prev_cmp = 0, cmp = -1;
77 while (i >= 0 && i < len) {
78 - cmp = hashcmp(obj, list[i].obj);
78 + cmp = hashcmp(obj, list[i].obj.hash);
79 if (!cmp) /* obj belongs @ i */
80 break;
81 else if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */
@@ -108,9 +108,10 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
108 return list + i;
109 }
110
111 -static unsigned char uninitialized[20] =
111 +static struct object_id uninitialized = {
112 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" \
113 - "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
113 + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
114 +};
115
116 static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
117 const unsigned char *base,
@@ -149,25 +150,25 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
150 mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);
151 if (occupied) {
152 /* We've found an addition/deletion pair */
152 - assert(!hashcmp(mp->obj, obj));
153 + assert(!hashcmp(mp->obj.hash, obj));
154 if (is_null_oid(&p->one->oid)) { /* addition */
154 - assert(is_null_sha1(mp->remote));
155 - hashcpy(mp->remote, p->two->oid.hash);
155 + assert(is_null_oid(&mp->remote));
156 + oidcpy(&mp->remote, &p->two->oid);
157 } else if (is_null_oid(&p->two->oid)) { /* deletion */
157 - assert(is_null_sha1(mp->base));
158 - hashcpy(mp->base, p->one->oid.hash);
158 + assert(is_null_oid(&mp->base));
159 + oidcpy(&mp->base, &p->one->oid);
160 } else
161 assert(!"Invalid existing change recorded");
162 } else {
162 - hashcpy(mp->obj, obj);
163 - hashcpy(mp->base, p->one->oid.hash);
164 - hashcpy(mp->local, uninitialized);
165 - hashcpy(mp->remote, p->two->oid.hash);
163 + hashcpy(mp->obj.hash, obj);
164 + oidcpy(&mp->base, &p->one->oid);
165 + oidcpy(&mp->local, &uninitialized);
166 + oidcpy(&mp->remote, &p->two->oid);
167 len++;
168 }
169 trace_printf("\t\tStored remote change for %s: %.7s -> %.7s\n",
169 - sha1_to_hex(mp->obj), sha1_to_hex(mp->base),
170 - sha1_to_hex(mp->remote));
170 + oid_to_hex(&mp->obj), oid_to_hex(&mp->base),
171 + oid_to_hex(&mp->remote));
172 }
173 diff_flush(&opt);
174 clear_pathspec(&opt.pathspec);
@@ -216,7 +217,7 @@ static void diff_tree_local(struct notes_merge_options *o,
217 continue;
218 }
219
219 - assert(!hashcmp(mp->obj, obj));
220 + assert(!hashcmp(mp->obj.hash, obj));
221 if (is_null_oid(&p->two->oid)) { /* deletion */
222 /*
223 * 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,
228 * (3) mp->local is uninitialized; set it to null_sha1
229 * (will be overwritten by following addition)
230 */
230 - if (!hashcmp(mp->local, uninitialized))
231 - hashclr(mp->local);
231 + if (!oidcmp(&mp->local, &uninitialized))
232 + oidclr(&mp->local);
233 } else if (is_null_oid(&p->one->oid)) { /* addition */
234 /*
235 * 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,
239 * (2) mp->local is uninitialized; set to p->two->sha1
240 * (3) mp->local is null_sha1; set to p->two->sha1
241 */
241 - assert(is_null_sha1(mp->local) ||
242 - !hashcmp(mp->local, uninitialized));
243 - hashcpy(mp->local, p->two->oid.hash);
242 + assert(is_null_oid(&mp->local) ||
243 + !oidcmp(&mp->local, &uninitialized));
244 + oidcpy(&mp->local, &p->two->oid);
245 } else { /* modification */
246 /*
247 * This is a true modification. p->one->sha1 shall
248 * match mp->base, and mp->local shall be uninitialized.
249 * Set mp->local to p->two->sha1.
250 */
250 - assert(!hashcmp(p->one->oid.hash, mp->base));
251 - assert(!hashcmp(mp->local, uninitialized));
252 - hashcpy(mp->local, p->two->oid.hash);
251 + assert(!oidcmp(&p->one->oid, &mp->base));
252 + assert(!oidcmp(&mp->local, &uninitialized));
253 + oidcpy(&mp->local, &p->two->oid);
254 }
255 trace_printf("\t\tStored local change for %s: %.7s -> %.7s\n",
255 - sha1_to_hex(mp->obj), sha1_to_hex(mp->base),
256 - sha1_to_hex(mp->local));
256 + oid_to_hex(&mp->obj), oid_to_hex(&mp->base),
257 + oid_to_hex(&mp->local));
258 }
259 diff_flush(&opt);
260 clear_pathspec(&opt.pathspec);
@@ -343,11 +344,11 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
344 mmfile_t base, local, remote;
345 int status;
346
346 - read_mmblob(&base, p->base);
347 - read_mmblob(&local, p->local);
348 - read_mmblob(&remote, p->remote);
347 + read_mmblob(&base, p->base.hash);
348 + read_mmblob(&local, p->local.hash);
349 + read_mmblob(&remote, p->remote.hash);
350
350 - status = ll_merge(&result_buf, sha1_to_hex(p->obj), &base, NULL,
351 + status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
352 &local, o->local_ref, &remote, o->remote_ref, NULL);
353
354 free(base.ptr);
@@ -357,7 +358,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
358 if ((status < 0) || !result_buf.ptr)
359 die("Failed to execute internal merge");
360
360 - write_buf_to_worktree(p->obj, result_buf.ptr, result_buf.size);
361 + write_buf_to_worktree(p->obj.hash, result_buf.ptr, result_buf.size);
362 free(result_buf.ptr);
363
364 return status;
@@ -372,51 +373,52 @@ static int merge_one_change_manual(struct notes_merge_options *o,
373
374 trace_printf("\t\t\tmerge_one_change_manual(obj = %.7s, base = %.7s, "
375 "local = %.7s, remote = %.7s)\n",
375 - sha1_to_hex(p->obj), sha1_to_hex(p->base),
376 - sha1_to_hex(p->local), sha1_to_hex(p->remote));
376 + oid_to_hex(&p->obj), oid_to_hex(&p->base),
377 + oid_to_hex(&p->local), oid_to_hex(&p->remote));
378
379 /* add "Conflicts:" section to commit message first time through */
380 if (!o->has_worktree)
381 strbuf_addstr(&(o->commit_msg), "\n\nConflicts:\n");
382
382 - strbuf_addf(&(o->commit_msg), "\t%s\n", sha1_to_hex(p->obj));
383 + strbuf_addf(&(o->commit_msg), "\t%s\n", oid_to_hex(&p->obj));
384
385 if (o->verbosity >= 2)
385 - printf("Auto-merging notes for %s\n", sha1_to_hex(p->obj));
386 + printf("Auto-merging notes for %s\n", oid_to_hex(&p->obj));
387 check_notes_merge_worktree(o);
387 - if (is_null_sha1(p->local)) {
388 + if (is_null_oid(&p->local)) {
389 /* D/F conflict, checkout p->remote */
389 - assert(!is_null_sha1(p->remote));
390 + assert(!is_null_oid(&p->remote));
391 if (o->verbosity >= 1)
392 printf("CONFLICT (delete/modify): Notes for object %s "
393 "deleted in %s and modified in %s. Version from %s "
394 "left in tree.\n",
394 - sha1_to_hex(p->obj), lref, rref, rref);
395 - write_note_to_worktree(p->obj, p->remote);
396 - } else if (is_null_sha1(p->remote)) {
395 + oid_to_hex(&p->obj), lref, rref, rref);
396 + write_note_to_worktree(p->obj.hash, p->remote.hash);
397 + } else if (is_null_oid(&p->remote)) {
398 /* D/F conflict, checkout p->local */
398 - assert(!is_null_sha1(p->local));
399 + assert(!is_null_oid(&p->local));
400 if (o->verbosity >= 1)
401 printf("CONFLICT (delete/modify): Notes for object %s "
402 "deleted in %s and modified in %s. Version from %s "
403 "left in tree.\n",
403 - sha1_to_hex(p->obj), rref, lref, lref);
404 - write_note_to_worktree(p->obj, p->local);
404 + oid_to_hex(&p->obj), rref, lref, lref);
405 + write_note_to_worktree(p->obj.hash, p->local.hash);
406 } else {
407 /* "regular" conflict, checkout result of ll_merge() */
408 const char *reason = "content";
408 - if (is_null_sha1(p->base))
409 + if (is_null_oid(&p->base))
410 reason = "add/add";
410 - assert(!is_null_sha1(p->local));
411 - assert(!is_null_sha1(p->remote));
411 + assert(!is_null_oid(&p->local));
412 + assert(!is_null_oid(&p->remote));
413 if (o->verbosity >= 1)
414 printf("CONFLICT (%s): Merge conflict in notes for "
414 - "object %s\n", reason, sha1_to_hex(p->obj));
415 + "object %s\n", reason,
416 + oid_to_hex(&p->obj));
417 ll_merge_in_worktree(o, p);
418 }
419
420 trace_printf("\t\t\tremoving from partial merge result\n");
419 - remove_note(t, p->obj);
421 + remove_note(t, p->obj.hash);
422
423 return 1;
424 }
@@ -435,29 +437,29 @@ static int merge_one_change(struct notes_merge_options *o,
437 case NOTES_MERGE_RESOLVE_OURS:
438 if (o->verbosity >= 2)
439 printf("Using local notes for %s\n",
438 - sha1_to_hex(p->obj));
440 + oid_to_hex(&p->obj));
441 /* nothing to do */
442 return 0;
443 case NOTES_MERGE_RESOLVE_THEIRS:
444 if (o->verbosity >= 2)
445 printf("Using remote notes for %s\n",
444 - sha1_to_hex(p->obj));
445 - if (add_note(t, p->obj, p->remote, combine_notes_overwrite))
446 + oid_to_hex(&p->obj));
447 + if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))
448 die("BUG: combine_notes_overwrite failed");
449 return 0;
450 case NOTES_MERGE_RESOLVE_UNION:
451 if (o->verbosity >= 2)
452 printf("Concatenating local and remote notes for %s\n",
451 - sha1_to_hex(p->obj));
452 - if (add_note(t, p->obj, p->remote, combine_notes_concatenate))
453 + oid_to_hex(&p->obj));
454 + if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))
455 die("failed to concatenate notes "
456 "(combine_notes_concatenate)");
457 return 0;
458 case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
459 if (o->verbosity >= 2)
460 printf("Concatenating unique lines in local and remote "
459 - "notes for %s\n", sha1_to_hex(p->obj));
460 - if (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq))
461 + "notes for %s\n", oid_to_hex(&p->obj));
462 + if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq))
463 die("failed to concatenate notes "
464 "(combine_notes_cat_sort_uniq)");
465 return 0;
@@ -475,20 +477,21 @@ static int merge_changes(struct notes_merge_options *o,
477 for (i = 0; i < *num_changes; i++) {
478 struct notes_merge_pair *p = changes + i;
479 trace_printf("\t\t%.7s: %.7s -> %.7s/%.7s\n",
478 - sha1_to_hex(p->obj), sha1_to_hex(p->base),
479 - sha1_to_hex(p->local), sha1_to_hex(p->remote));
480 + oid_to_hex(&p->obj), oid_to_hex(&p->base),
481 + oid_to_hex(&p->local),
482 + oid_to_hex(&p->remote));
483
481 - if (!hashcmp(p->base, p->remote)) {
484 + if (!oidcmp(&p->base, &p->remote)) {
485 /* no remote change; nothing to do */
486 trace_printf("\t\t\tskipping (no remote change)\n");
484 - } else if (!hashcmp(p->local, p->remote)) {
487 + } else if (!oidcmp(&p->local, &p->remote)) {
488 /* same change in local and remote; nothing to do */
489 trace_printf("\t\t\tskipping (local == remote)\n");
487 - } else if (!hashcmp(p->local, uninitialized) ||
488 - !hashcmp(p->local, p->base)) {
490 + } else if (!oidcmp(&p->local, &uninitialized) ||
491 + !oidcmp(&p->local, &p->base)) {
492 /* no local change; adopt remote change */
493 trace_printf("\t\t\tno local change, adopted remote\n");
491 - if (add_note(t, p->obj, p->remote,
494 + if (add_note(t, p->obj.hash, p->remote.hash,
495 combine_notes_overwrite))
496 die("BUG: combine_notes_overwrite failed");
497 } else {