notes: convert some accessor functions to struct object_id
Convert add_note, get_note, and copy_note to take struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 30, 2017 at 10:30 UTC
5ee8a954e0191be2a144afdda6e37ef776730246
7 files changed
+41
-41
builtin/notes.c
+10
-10
@@ -309,7 +309,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
309
if (rewrite_cmd)
310
err = copy_note_for_rewrite(c, &from_obj, &to_obj);
311
else
312
- err = copy_note(t, from_obj.hash, to_obj.hash, force,
312
+ err = copy_note(t, &from_obj, &to_obj, force,
313
combine_notes_overwrite);
314
315
if (err) {
@@ -370,7 +370,7 @@ static int list(int argc, const char **argv, const char *prefix)
370
if (argc) {
371
if (get_oid(argv[0], &object))
372
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
373
- note = get_note(t, object.hash);
373
+ note = get_note(t, &object);
374
if (note) {
375
puts(oid_to_hex(note));
376
retval = 0;
@@ -427,7 +427,7 @@ static int add(int argc, const char **argv, const char *prefix)
427
die(_("failed to resolve '%s' as a valid ref."), object_ref);
428
429
t = init_notes_check("add", NOTES_INIT_WRITABLE);
430
- note = get_note(t, object.hash);
430
+ note = get_note(t, &object);
431
432
if (note) {
433
if (!force) {
@@ -456,7 +456,7 @@ static int add(int argc, const char **argv, const char *prefix)
456
prepare_note_data(&object, &d, note->hash);
457
if (d.buf.len || allow_empty) {
458
write_note_data(&d, new_note.hash);
459
- if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
459
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
460
die("BUG: combine_notes_overwrite failed");
461
commit_notes(t, "Notes added by 'git notes add'");
462
} else {
@@ -518,7 +518,7 @@ static int copy(int argc, const char **argv, const char *prefix)
518
die(_("failed to resolve '%s' as a valid ref."), object_ref);
519
520
t = init_notes_check("copy", NOTES_INIT_WRITABLE);
521
- note = get_note(t, object.hash);
521
+ note = get_note(t, &object);
522
523
if (note) {
524
if (!force) {
@@ -532,14 +532,14 @@ static int copy(int argc, const char **argv, const char *prefix)
532
oid_to_hex(&object));
533
}
534
535
- from_note = get_note(t, from_obj.hash);
535
+ from_note = get_note(t, &from_obj);
536
if (!from_note) {
537
retval = error(_("missing notes on source object %s. Cannot "
538
"copy."), oid_to_hex(&from_obj));
539
goto out;
540
}
541
542
- if (add_note(t, object.hash, from_note->hash, combine_notes_overwrite))
542
+ if (add_note(t, &object, from_note, combine_notes_overwrite))
543
die("BUG: combine_notes_overwrite failed");
544
commit_notes(t, "Notes added by 'git notes copy'");
545
out:
@@ -596,7 +596,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
596
die(_("failed to resolve '%s' as a valid ref."), object_ref);
597
598
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
599
- note = get_note(t, object.hash);
599
+ note = get_note(t, &object);
600
601
prepare_note_data(&object, &d, edit && note ? note->hash : NULL);
602
@@ -616,7 +616,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
616
617
if (d.buf.len || allow_empty) {
618
write_note_data(&d, new_note.hash);
619
- if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
619
+ if (add_note(t, &object, &new_note, combine_notes_overwrite))
620
die("BUG: combine_notes_overwrite failed");
621
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
622
} else {
@@ -658,7 +658,7 @@ static int show(int argc, const char **argv, const char *prefix)
658
die(_("failed to resolve '%s' as a valid ref."), object_ref);
659
660
t = init_notes_check("show", 0);
661
- note = get_note(t, object.hash);
661
+ note = get_note(t, &object);
662
663
if (!note)
664
retval = error(_("no note found for object %s."),
notes-cache.c
+2
-2
@@ -74,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
74
char *value;
75
unsigned long size;
76
77
- value_oid = get_note(&c->tree, key_oid->hash);
77
+ value_oid = get_note(&c->tree, key_oid);
78
if (!value_oid)
79
return NULL;
80
value = read_sha1_file(value_oid->hash, &type, &size);
@@ -90,5 +90,5 @@ int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
90
91
if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
92
return -1;
93
- return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL);
93
+ return add_note(&c->tree, key_oid, &value_oid, NULL);
94
}
notes-merge.c
+9
-9
@@ -444,14 +444,14 @@ static int merge_one_change(struct notes_merge_options *o,
444
if (o->verbosity >= 2)
445
printf("Using remote notes for %s\n",
446
oid_to_hex(&p->obj));
447
- if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))
447
+ if (add_note(t, &p->obj, &p->remote, 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",
453
oid_to_hex(&p->obj));
454
- if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))
454
+ if (add_note(t, &p->obj, &p->remote, combine_notes_concatenate))
455
die("failed to concatenate notes "
456
"(combine_notes_concatenate)");
457
return 0;
@@ -459,7 +459,7 @@ static int merge_one_change(struct notes_merge_options *o,
459
if (o->verbosity >= 2)
460
printf("Concatenating unique lines in local and remote "
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))
462
+ if (add_note(t, &p->obj, &p->remote, combine_notes_cat_sort_uniq))
463
die("failed to concatenate notes "
464
"(combine_notes_cat_sort_uniq)");
465
return 0;
@@ -491,7 +491,7 @@ static int merge_changes(struct notes_merge_options *o,
491
!oidcmp(&p->local, &p->base)) {
492
/* no local change; adopt remote change */
493
trace_printf("\t\t\tno local change, adopted remote\n");
494
- if (add_note(t, p->obj.hash, p->remote.hash,
494
+ if (add_note(t, &p->obj, &p->remote,
495
combine_notes_overwrite))
496
die("BUG: combine_notes_overwrite failed");
497
} else {
@@ -693,12 +693,12 @@ int notes_merge_commit(struct notes_merge_options *o,
693
baselen = path.len;
694
while ((e = readdir(dir)) != NULL) {
695
struct stat st;
696
- unsigned char obj_sha1[20], blob_sha1[20];
696
+ struct object_id obj_oid, blob_oid;
697
698
if (is_dot_or_dotdot(e->d_name))
699
continue;
700
701
- if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) {
701
+ if (get_oid_hex(e->d_name, &obj_oid)) {
702
if (o->verbosity >= 3)
703
printf("Skipping non-SHA1 entry '%s%s'\n",
704
path.buf, e->d_name);
@@ -709,14 +709,14 @@ int notes_merge_commit(struct notes_merge_options *o,
709
/* write file as blob, and add to partial_tree */
710
if (stat(path.buf, &st))
711
die_errno("Failed to stat '%s'", path.buf);
712
- if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT))
712
+ if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT))
713
die("Failed to write blob object from '%s'", path.buf);
714
- if (add_note(partial_tree, obj_sha1, blob_sha1, NULL))
714
+ if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
715
die("Failed to add resolved note '%s' to notes tree",
716
path.buf);
717
if (o->verbosity >= 4)
718
printf("Added resolved note for object %s: %s\n",
719
- sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
719
+ oid_to_hex(&obj_oid), oid_to_hex(&blob_oid));
720
strbuf_setlen(&path, baselen);
721
}
722
notes-utils.c
+1
-1
@@ -160,7 +160,7 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
160
int ret = 0;
161
int i;
162
for (i = 0; c->trees[i]; i++)
163
- ret = copy_note(c->trees[i], from_obj->hash, to_obj->hash, 1, c->combine) || ret;
163
+ ret = copy_note(c->trees[i], from_obj, to_obj, 1, c->combine) || ret;
164
return ret;
165
}
166
notes.c
+10
-10
@@ -1086,8 +1086,8 @@ void init_display_notes(struct display_notes_opt *opt)
1086
string_list_clear(&display_notes_refs, 0);
1087
}
1088
1089
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
1090
- const unsigned char *note_sha1, combine_notes_fn combine_notes)
1089
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
1090
+ const struct object_id *note_oid, combine_notes_fn combine_notes)
1091
{
1092
struct leaf_node *l;
1093
@@ -1098,8 +1098,8 @@ int add_note(struct notes_tree *t, const unsigned char *object_sha1,
1098
if (!combine_notes)
1099
combine_notes = t->combine_notes;
1100
l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
1101
- hashcpy(l->key_oid.hash, object_sha1);
1102
- hashcpy(l->val_oid.hash, note_sha1);
1101
+ oidcpy(&l->key_oid, object_oid);
1102
+ oidcpy(&l->val_oid, note_oid);
1103
return note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
1104
}
1105
@@ -1120,14 +1120,14 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
1120
}
1121
1122
const struct object_id *get_note(struct notes_tree *t,
1123
- const unsigned char *object_sha1)
1123
+ const struct object_id *oid)
1124
{
1125
struct leaf_node *found;
1126
1127
if (!t)
1128
t = &default_notes_tree;
1129
assert(t->initialized);
1130
- found = note_tree_find(t, t->root, 0, object_sha1);
1130
+ found = note_tree_find(t, t->root, 0, oid->hash);
1131
return found ? &found->val_oid : NULL;
1132
}
1133
@@ -1229,7 +1229,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
1229
if (!t->initialized)
1230
init_notes(t, NULL, NULL, 0);
1231
1232
- oid = get_note(t, object_oid->hash);
1232
+ oid = get_note(t, object_oid);
1233
if (!oid)
1234
return;
1235
@@ -1288,7 +1288,7 @@ void format_display_notes(const struct object_id *object_oid,
1288
}
1289
1290
int copy_note(struct notes_tree *t,
1291
- const unsigned char *from_obj, const unsigned char *to_obj,
1291
+ const struct object_id *from_obj, const struct object_id *to_obj,
1292
int force, combine_notes_fn combine_notes)
1293
{
1294
const struct object_id *note = get_note(t, from_obj);
@@ -1298,9 +1298,9 @@ int copy_note(struct notes_tree *t,
1298
return 1;
1299
1300
if (note)
1301
- return add_note(t, to_obj, note->hash, combine_notes);
1301
+ return add_note(t, to_obj, note, combine_notes);
1302
else if (existing_note)
1303
- return add_note(t, to_obj, null_sha1, combine_notes);
1303
+ return add_note(t, to_obj, &null_oid, combine_notes);
1304
1305
return 0;
1306
}
notes.h
+4
-4
@@ -121,8 +121,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
121
* are not persistent until a subsequent call to write_notes_tree() returns
122
* zero.
123
*/
124
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
125
- const unsigned char *note_sha1, combine_notes_fn combine_notes);
124
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
125
+ const struct object_id *note_oid, combine_notes_fn combine_notes);
126
127
/*
128
* Remove the given note object from the given notes_tree structure
@@ -141,7 +141,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1);
141
* Return NULL if the given object has no notes.
142
*/
143
const struct object_id *get_note(struct notes_tree *t,
144
- const unsigned char *object_sha1);
144
+ const struct object_id *object_oid);
145
146
/*
147
* Copy a note from one object to another in the given notes_tree.
@@ -156,7 +156,7 @@ const struct object_id *get_note(struct notes_tree *t,
156
* zero.
157
*/
158
int copy_note(struct notes_tree *t,
159
- const unsigned char *from_obj, const unsigned char *to_obj,
159
+ const struct object_id *from_obj, const struct object_id *to_obj,
160
int force, combine_notes_fn combine_notes);
161
162
/*
remote-testsvn.c
+5
-5
@@ -51,7 +51,7 @@ static void terminate_batch(void)
51
}
52
53
/* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */
54
-static char *read_ref_note(const unsigned char sha1[20])
54
+static char *read_ref_note(const struct object_id *oid)
55
{
56
const struct object_id *note_oid;
57
char *msg = NULL;
@@ -59,7 +59,7 @@ static char *read_ref_note(const unsigned char sha1[20])
59
enum object_type type;
60
61
init_notes(NULL, notes_ref, NULL, 0);
62
- if (!(note_oid = get_note(NULL, sha1)))
62
+ if (!(note_oid = get_note(NULL, oid)))
63
return NULL; /* note tree not found */
64
if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))
65
error("Empty notes tree. %s", notes_ref);
@@ -174,15 +174,15 @@ static int cmd_import(const char *line)
174
int code;
175
int dumpin_fd;
176
char *note_msg;
177
- unsigned char head_sha1[20];
177
+ struct object_id head_oid;
178
unsigned int startrev;
179
struct child_process svndump_proc = CHILD_PROCESS_INIT;
180
const char *command = "svnrdump";
181
182
- if (read_ref(private_ref, head_sha1))
182
+ if (read_ref(private_ref, head_oid.hash))
183
startrev = 0;
184
else {
185
- note_msg = read_ref_note(head_sha1);
185
+ note_msg = read_ref_note(&head_oid);
186
if(note_msg == NULL) {
187
warning("No note found for %s.", private_ref);
188
startrev = 0;