notes: convert combine_notes_* to object_id

Convert the definition and declarations of combine_notes_* functions to struct object_id and adjust usage of these functions. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patryk Obara committed Jan 28, 2018 at 01:13 UTC b7d591d17b0497597c2152ae86bd8aa4220d6961
2 files changed +38 -33
notes.c
+23 -23
@@ -270,8 +270,8 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
270 if (!oidcmp(&l->val_oid, &entry->val_oid))
271 return 0;
272
273 - ret = combine_notes(l->val_oid.hash,
274 - entry->val_oid.hash);
273 + ret = combine_notes(&l->val_oid,
274 + &entry->val_oid);
275 if (!ret && is_null_oid(&l->val_oid))
276 note_tree_remove(t, tree, n, entry);
277 free(entry);
@@ -786,8 +786,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
786 return 0;
787 }
788
789 -int combine_notes_concatenate(unsigned char *cur_sha1,
790 - const unsigned char *new_sha1)
789 +int combine_notes_concatenate(struct object_id *cur_oid,
790 + const struct object_id *new_oid)
791 {
792 char *cur_msg = NULL, *new_msg = NULL, *buf;
793 unsigned long cur_len, new_len, buf_len;
@@ -795,18 +795,18 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
795 int ret;
796
797 /* read in both note blob objects */
798 - if (!is_null_sha1(new_sha1))
799 - new_msg = read_sha1_file(new_sha1, &new_type, &new_len);
798 + if (!is_null_oid(new_oid))
799 + new_msg = read_sha1_file(new_oid->hash, &new_type, &new_len);
800 if (!new_msg || !new_len || new_type != OBJ_BLOB) {
801 free(new_msg);
802 return 0;
803 }
804 - if (!is_null_sha1(cur_sha1))
805 - cur_msg = read_sha1_file(cur_sha1, &cur_type, &cur_len);
804 + if (!is_null_oid(cur_oid))
805 + cur_msg = read_sha1_file(cur_oid->hash, &cur_type, &cur_len);
806 if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
807 free(cur_msg);
808 free(new_msg);
809 - hashcpy(cur_sha1, new_sha1);
809 + oidcpy(cur_oid, new_oid);
810 return 0;
811 }
812
@@ -825,20 +825,20 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
825 free(new_msg);
826
827 /* create a new blob object from buf */
828 - ret = write_sha1_file(buf, buf_len, blob_type, cur_sha1);
828 + ret = write_sha1_file(buf, buf_len, blob_type, cur_oid->hash);
829 free(buf);
830 return ret;
831 }
832
833 -int combine_notes_overwrite(unsigned char *cur_sha1,
834 - const unsigned char *new_sha1)
833 +int combine_notes_overwrite(struct object_id *cur_oid,
834 + const struct object_id *new_oid)
835 {
836 - hashcpy(cur_sha1, new_sha1);
836 + oidcpy(cur_oid, new_oid);
837 return 0;
838 }
839
840 -int combine_notes_ignore(unsigned char *cur_sha1,
841 - const unsigned char *new_sha1)
840 +int combine_notes_ignore(struct object_id *cur_oid,
841 + const struct object_id *new_oid)
842 {
843 return 0;
844 }
@@ -848,17 +848,17 @@ int combine_notes_ignore(unsigned char *cur_sha1,
848 * newlines removed.
849 */
850 static int string_list_add_note_lines(struct string_list *list,
851 - const unsigned char *sha1)
851 + const struct object_id *oid)
852 {
853 char *data;
854 unsigned long len;
855 enum object_type t;
856
857 - if (is_null_sha1(sha1))
857 + if (is_null_oid(oid))
858 return 0;
859
860 /* read_sha1_file NUL-terminates */
861 - data = read_sha1_file(sha1, &t, &len);
861 + data = read_sha1_file(oid->hash, &t, &len);
862 if (t != OBJ_BLOB || !data || !len) {
863 free(data);
864 return t != OBJ_BLOB || !data;
@@ -884,17 +884,17 @@ static int string_list_join_lines_helper(struct string_list_item *item,
884 return 0;
885 }
886
887 -int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
888 - const unsigned char *new_sha1)
887 +int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
888 + const struct object_id *new_oid)
889 {
890 struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
891 struct strbuf buf = STRBUF_INIT;
892 int ret = 1;
893
894 /* read both note blob objects into unique_lines */
895 - if (string_list_add_note_lines(&sort_uniq_list, cur_sha1))
895 + if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
896 goto out;
897 - if (string_list_add_note_lines(&sort_uniq_list, new_sha1))
897 + if (string_list_add_note_lines(&sort_uniq_list, new_oid))
898 goto out;
899 string_list_remove_empty_items(&sort_uniq_list, 0);
900 string_list_sort(&sort_uniq_list);
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
905 string_list_join_lines_helper, &buf))
906 goto out;
907
908 - ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_sha1);
908 + ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_oid->hash);
909
910 out:
911 strbuf_release(&buf);
notes.h
+15 -10
@@ -9,27 +9,32 @@
9 * When adding a new note annotating the same object as an existing note, it is
10 * up to the caller to decide how to combine the two notes. The decision is
11 * made by passing in a function of the following form. The function accepts
12 - * two SHA1s -- of the existing note and the new note, respectively. The
12 + * two object_ids -- of the existing note and the new note, respectively. The
13 * function then combines the notes in whatever way it sees fit, and writes the
14 - * resulting SHA1 into the first SHA1 argument (cur_sha1). A non-zero return
14 + * resulting oid into the first argument (cur_oid). A non-zero return
15 * value indicates failure.
16 *
17 - * The two given SHA1s shall both be non-NULL and different from each other.
18 - * Either of them (but not both) may be == null_sha1, which indicates an
19 - * empty/non-existent note. If the resulting SHA1 (cur_sha1) is == null_sha1,
17 + * The two given object_ids shall both be non-NULL and different from each
18 + * other. Either of them (but not both) may be == null_oid, which indicates an
19 + * empty/non-existent note. If the resulting oid (cur_oid) is == null_oid,
20 * the note will be removed from the notes tree.
21 *
22 * The default combine_notes function (you get this when passing NULL) is
23 * combine_notes_concatenate(), which appends the contents of the new note to
24 * the contents of the existing note.
25 */
26 -typedef int (*combine_notes_fn)(unsigned char *cur_sha1, const unsigned char *new_sha1);
26 +typedef int (*combine_notes_fn)(struct object_id *cur_oid,
27 + const struct object_id *new_oid);
28
29 /* Common notes combinators */
29 -int combine_notes_concatenate(unsigned char *cur_sha1, const unsigned char *new_sha1);
30 -int combine_notes_overwrite(unsigned char *cur_sha1, const unsigned char *new_sha1);
31 -int combine_notes_ignore(unsigned char *cur_sha1, const unsigned char *new_sha1);
32 -int combine_notes_cat_sort_uniq(unsigned char *cur_sha1, const unsigned char *new_sha1);
30 +int combine_notes_concatenate(struct object_id *cur_oid,
31 + const struct object_id *new_oid);
32 +int combine_notes_overwrite(struct object_id *cur_oid,
33 + const struct object_id *new_oid);
34 +int combine_notes_ignore(struct object_id *cur_oid,
35 + const struct object_id *new_oid);
36 +int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
37 + const struct object_id *new_oid);
38
39 /*
40 * Notes tree object