notes: convert for_each_note to struct object_id

Convert for_each_note and each of the callbacks to use 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 490bc83a01acfefa11e98f8852b1f4a9dd962331
4 files changed +21 -21
builtin/notes.c
+3 -3
@@ -109,11 +109,11 @@ static void free_note_data(struct note_data *d)
109 strbuf_release(&d->buf);
110 }
111
112 -static int list_each_note(const unsigned char *object_sha1,
113 - const unsigned char *note_sha1, char *note_path,
112 +static int list_each_note(const struct object_id *object_oid,
113 + const struct object_id *note_oid, char *note_path,
114 void *cb_data)
115 {
116 - printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1));
116 + printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid));
117 return 0;
118 }
119
notes.c
+12 -12
@@ -610,7 +610,7 @@ redo:
610 if (path[path_len - 1] != '/')
611 path[path_len++] = '/';
612 path[path_len] = '\0';
613 - ret = fn(l->key_oid.hash, l->val_oid.hash,
613 + ret = fn(&l->key_oid, &l->val_oid,
614 path,
615 cb_data);
616 }
@@ -627,7 +627,7 @@ redo:
627 l = (struct leaf_node *) CLR_PTR_TYPE(p);
628 construct_path_with_fanout(l->key_oid.hash, fanout,
629 path);
630 - ret = fn(l->key_oid.hash, l->val_oid.hash, path,
630 + ret = fn(&l->key_oid, &l->val_oid, path,
631 cb_data);
632 break;
633 }
@@ -698,7 +698,7 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
698
699 static int write_each_note_helper(struct tree_write_stack *tws,
700 const char *path, unsigned int mode,
701 - const unsigned char *sha1)
701 + const struct object_id *oid)
702 {
703 size_t path_len = strlen(path);
704 unsigned int n = 0;
@@ -728,7 +728,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
728
729 /* Finally add given entry to the current tree object */
730 write_tree_entry(&tws->buf, mode, path + 3 * n, path_len - (3 * n),
731 - sha1);
731 + oid->hash);
732
733 return 0;
734 }
@@ -748,7 +748,7 @@ static int write_each_non_note_until(const char *note_path,
748 ; /* do nothing, prefer note to non-note */
749 else {
750 ret = write_each_note_helper(d->root, n->path, n->mode,
751 - n->oid.hash);
751 + &n->oid);
752 if (ret)
753 return ret;
754 }
@@ -758,8 +758,8 @@ static int write_each_non_note_until(const char *note_path,
758 return 0;
759 }
760
761 -static int write_each_note(const unsigned char *object_sha1,
762 - const unsigned char *note_sha1, char *note_path,
761 +static int write_each_note(const struct object_id *object_oid,
762 + const struct object_id *note_oid, char *note_path,
763 void *cb_data)
764 {
765 struct write_each_note_data *d =
@@ -777,7 +777,7 @@ static int write_each_note(const unsigned char *object_sha1,
777
778 /* Weave non-note entries into note entries */
779 return write_each_non_note_until(note_path, d) ||
780 - write_each_note_helper(d->root, note_path, mode, note_sha1);
780 + write_each_note_helper(d->root, note_path, mode, note_oid);
781 }
782
783 struct note_delete_list {
@@ -785,20 +785,20 @@ struct note_delete_list {
785 const unsigned char *sha1;
786 };
787
788 -static int prune_notes_helper(const unsigned char *object_sha1,
789 - const unsigned char *note_sha1, char *note_path,
788 +static int prune_notes_helper(const struct object_id *object_oid,
789 + const struct object_id *note_oid, char *note_path,
790 void *cb_data)
791 {
792 struct note_delete_list **l = (struct note_delete_list **) cb_data;
793 struct note_delete_list *n;
794
795 - if (has_sha1_file(object_sha1))
795 + if (has_object_file(object_oid))
796 return 0; /* nothing to do for this note */
797
798 /* failed to find object => prune this note */
799 n = (struct note_delete_list *) xmalloc(sizeof(*n));
800 n->next = *l;
801 - n->sha1 = object_sha1;
801 + n->sha1 = object_oid->hash;
802 *l = n;
803 return 0;
804 }
notes.h
+2 -2
@@ -202,8 +202,8 @@ int copy_note(struct notes_tree *t,
202 * - copy_note()
203 * - free_notes()
204 */
205 -typedef int each_note_fn(const unsigned char *object_sha1,
206 - const unsigned char *note_sha1, char *note_path,
205 +typedef int each_note_fn(const struct object_id *object_oid,
206 + const struct object_id *note_oid, char *note_path,
207 void *cb_data);
208 int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
209 void *cb_data);
remote-testsvn.c
+4 -4
@@ -99,8 +99,8 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
99 return -1;
100 }
101
102 -static int note2mark_cb(const unsigned char *object_sha1,
103 - const unsigned char *note_sha1, char *note_path,
102 +static int note2mark_cb(const struct object_id *object_oid,
103 + const struct object_id *note_oid, char *note_path,
104 void *cb_data)
105 {
106 FILE *file = (FILE *)cb_data;
@@ -109,14 +109,14 @@ static int note2mark_cb(const unsigned char *object_sha1,
109 enum object_type type;
110 struct rev_note note;
111
112 - if (!(msg = read_sha1_file(note_sha1, &type, &msglen)) ||
112 + if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) ||
113 !msglen || type != OBJ_BLOB) {
114 free(msg);
115 return 1;
116 }
117 if (parse_rev_note(msg, &note))
118 return 2;
119 - if (fprintf(file, ":%d %s\n", note.rev_nr, sha1_to_hex(object_sha1)) < 1)
119 + if (fprintf(file, ":%d %s\n", note.rev_nr, oid_to_hex(object_oid)) < 1)
120 return 3;
121 return 0;
122 }