Skip to content

Commit b7d591d

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5078f34 commit b7d591d

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

notes.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
270270
if (!oidcmp(&l->val_oid, &entry->val_oid))
271271
return 0;
272272

273-
ret = combine_notes(l->val_oid.hash,
274-
entry->val_oid.hash);
273+
ret = combine_notes(&l->val_oid,
274+
&entry->val_oid);
275275
if (!ret && is_null_oid(&l->val_oid))
276276
note_tree_remove(t, tree, n, entry);
277277
free(entry);
@@ -786,27 +786,27 @@ static int prune_notes_helper(const struct object_id *object_oid,
786786
return 0;
787787
}
788788

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)
791791
{
792792
char *cur_msg = NULL, *new_msg = NULL, *buf;
793793
unsigned long cur_len, new_len, buf_len;
794794
enum object_type cur_type, new_type;
795795
int ret;
796796

797797
/* 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);
800800
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
801801
free(new_msg);
802802
return 0;
803803
}
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);
806806
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
807807
free(cur_msg);
808808
free(new_msg);
809-
hashcpy(cur_sha1, new_sha1);
809+
oidcpy(cur_oid, new_oid);
810810
return 0;
811811
}
812812

@@ -825,20 +825,20 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
825825
free(new_msg);
826826

827827
/* 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);
829829
free(buf);
830830
return ret;
831831
}
832832

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)
835835
{
836-
hashcpy(cur_sha1, new_sha1);
836+
oidcpy(cur_oid, new_oid);
837837
return 0;
838838
}
839839

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)
842842
{
843843
return 0;
844844
}
@@ -848,17 +848,17 @@ int combine_notes_ignore(unsigned char *cur_sha1,
848848
* newlines removed.
849849
*/
850850
static int string_list_add_note_lines(struct string_list *list,
851-
const unsigned char *sha1)
851+
const struct object_id *oid)
852852
{
853853
char *data;
854854
unsigned long len;
855855
enum object_type t;
856856

857-
if (is_null_sha1(sha1))
857+
if (is_null_oid(oid))
858858
return 0;
859859

860860
/* read_sha1_file NUL-terminates */
861-
data = read_sha1_file(sha1, &t, &len);
861+
data = read_sha1_file(oid->hash, &t, &len);
862862
if (t != OBJ_BLOB || !data || !len) {
863863
free(data);
864864
return t != OBJ_BLOB || !data;
@@ -884,17 +884,17 @@ static int string_list_join_lines_helper(struct string_list_item *item,
884884
return 0;
885885
}
886886

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)
889889
{
890890
struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
891891
struct strbuf buf = STRBUF_INIT;
892892
int ret = 1;
893893

894894
/* 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))
896896
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))
898898
goto out;
899899
string_list_remove_empty_items(&sort_uniq_list, 0);
900900
string_list_sort(&sort_uniq_list);
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
905905
string_list_join_lines_helper, &buf))
906906
goto out;
907907

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);
909909

910910
out:
911911
strbuf_release(&buf);

notes.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@
99
* When adding a new note annotating the same object as an existing note, it is
1010
* up to the caller to decide how to combine the two notes. The decision is
1111
* 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
1313
* 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
1515
* value indicates failure.
1616
*
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,
2020
* the note will be removed from the notes tree.
2121
*
2222
* The default combine_notes function (you get this when passing NULL) is
2323
* combine_notes_concatenate(), which appends the contents of the new note to
2424
* the contents of the existing note.
2525
*/
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);
2728

2829
/* 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);
3338

3439
/*
3540
* Notes tree object

0 commit comments

Comments
 (0)