git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 09/14] notes: convert combine_notes_* to object_id

From
Patryk Obara <patryk.obara@gmail.com>
Date
Jan 22, 2018, 11:04 UTC
Message-ID
<c9f48766ca447e0f66f32ea00ecfc519cdaef8a2.1516617960.git.patryk.obara@gmail.com>
In-Reply-To
<cover.1516617960.git.patryk.obara@gmail.com>

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>
---
 notes.c | 46 +++++++++++++++++++++++-----------------------
 notes.h | 25 +++++++++++++++----------
 2 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/notes.c b/notes.c
index c7f21fae44..3f4f94507a 100644
--- a/notes.c
+++ b/notes.c
@@ -270,8 +270,8 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
 				if (!oidcmp(&l->val_oid, &entry->val_oid))
 					return 0;
 
-				ret = combine_notes(l->val_oid.hash,
-						    entry->val_oid.hash);
+				ret = combine_notes(&l->val_oid,
+						    &entry->val_oid);
 				if (!ret && is_null_oid(&l->val_oid))
 					note_tree_remove(t, tree, n, entry);
 				free(entry);
@@ -786,8 +786,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
 	return 0;
 }
 
-int combine_notes_concatenate(unsigned char *cur_sha1,
-		const unsigned char *new_sha1)
+int combine_notes_concatenate(struct object_id *cur_oid,
+			      const struct object_id *new_oid)
 {
 	char *cur_msg = NULL, *new_msg = NULL, *buf;
 	unsigned long cur_len, new_len, buf_len;
@@ -795,18 +795,18 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
 	int ret;
 
 	/* read in both note blob objects */
-	if (!is_null_sha1(new_sha1))
-		new_msg = read_sha1_file(new_sha1, &new_type, &new_len);
+	if (!is_null_oid(new_oid))
+		new_msg = read_sha1_file(new_oid->hash, &new_type, &new_len);
 	if (!new_msg || !new_len || new_type != OBJ_BLOB) {
 		free(new_msg);
 		return 0;
 	}
-	if (!is_null_sha1(cur_sha1))
-		cur_msg = read_sha1_file(cur_sha1, &cur_type, &cur_len);
+	if (!is_null_oid(cur_oid))
+		cur_msg = read_sha1_file(cur_oid->hash, &cur_type, &cur_len);
 	if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
 		free(cur_msg);
 		free(new_msg);
-		hashcpy(cur_sha1, new_sha1);
+		oidcpy(cur_oid, new_oid);
 		return 0;
 	}
 
@@ -825,20 +825,20 @@ int combine_notes_concatenate(unsigned char *cur_sha1,
 	free(new_msg);
 
 	/* create a new blob object from buf */
-	ret = write_sha1_file(buf, buf_len, blob_type, cur_sha1);
+	ret = write_sha1_file(buf, buf_len, blob_type, cur_oid->hash);
 	free(buf);
 	return ret;
 }
 
-int combine_notes_overwrite(unsigned char *cur_sha1,
-		const unsigned char *new_sha1)
+int combine_notes_overwrite(struct object_id *cur_oid,
+			    const struct object_id *new_oid)
 {
-	hashcpy(cur_sha1, new_sha1);
+	oidcpy(cur_oid, new_oid);
 	return 0;
 }
 
-int combine_notes_ignore(unsigned char *cur_sha1,
-		const unsigned char *new_sha1)
+int combine_notes_ignore(struct object_id *cur_oid,
+			 const struct object_id *new_oid)
 {
 	return 0;
 }
@@ -848,17 +848,17 @@ int combine_notes_ignore(unsigned char *cur_sha1,
  * newlines removed.
  */
 static int string_list_add_note_lines(struct string_list *list,
-				      const unsigned char *sha1)
+				      const struct object_id *oid)
 {
 	char *data;
 	unsigned long len;
 	enum object_type t;
 
-	if (is_null_sha1(sha1))
+	if (is_null_oid(oid))
 		return 0;
 
 	/* read_sha1_file NUL-terminates */
-	data = read_sha1_file(sha1, &t, &len);
+	data = read_sha1_file(oid->hash, &t, &len);
 	if (t != OBJ_BLOB || !data || !len) {
 		free(data);
 		return t != OBJ_BLOB || !data;
@@ -884,17 +884,17 @@ static int string_list_join_lines_helper(struct string_list_item *item,
 	return 0;
 }
 
-int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
-		const unsigned char *new_sha1)
+int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+				const struct object_id *new_oid)
 {
 	struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	int ret = 1;
 
 	/* read both note blob objects into unique_lines */
-	if (string_list_add_note_lines(&sort_uniq_list, cur_sha1))
+	if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
 		goto out;
-	if (string_list_add_note_lines(&sort_uniq_list, new_sha1))
+	if (string_list_add_note_lines(&sort_uniq_list, new_oid))
 		goto out;
 	string_list_remove_empty_items(&sort_uniq_list, 0);
 	string_list_sort(&sort_uniq_list);
@@ -905,7 +905,7 @@ int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,
 				 string_list_join_lines_helper, &buf))
 		goto out;
 
-	ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_sha1);
+	ret = write_sha1_file(buf.buf, buf.len, blob_type, cur_oid->hash);
 
 out:
 	strbuf_release(&buf);
diff --git a/notes.h b/notes.h
index 3848c2fb3f..88da38b5f4 100644
--- a/notes.h
+++ b/notes.h
@@ -9,27 +9,32 @@
  * When adding a new note annotating the same object as an existing note, it is
  * up to the caller to decide how to combine the two notes. The decision is
  * made by passing in a function of the following form. The function accepts
- * two SHA1s -- of the existing note and the new note, respectively. The
+ * two object_ids -- of the existing note and the new note, respectively. The
  * function then combines the notes in whatever way it sees fit, and writes the
- * resulting SHA1 into the first SHA1 argument (cur_sha1). A non-zero return
+ * resulting oid into the first argument (cur_oid). A non-zero return
  * value indicates failure.
  *
- * The two given SHA1s shall both be non-NULL and different from each other.
- * Either of them (but not both) may be == null_sha1, which indicates an
- * empty/non-existent note. If the resulting SHA1 (cur_sha1) is == null_sha1,
+ * The two given object_ids shall both be non-NULL and different from each
+ * other. Either of them (but not both) may be == null_oid, which indicates an
+ * empty/non-existent note. If the resulting oid (cur_oid) is == null_oid,
  * the note will be removed from the notes tree.
  *
  * The default combine_notes function (you get this when passing NULL) is
  * combine_notes_concatenate(), which appends the contents of the new note to
  * the contents of the existing note.
  */
-typedef int (*combine_notes_fn)(unsigned char *cur_sha1, const unsigned char *new_sha1);
+typedef int (*combine_notes_fn)(struct object_id *cur_oid,
+				const struct object_id *new_oid);
 
 /* Common notes combinators */
-int combine_notes_concatenate(unsigned char *cur_sha1, const unsigned char *new_sha1);
-int combine_notes_overwrite(unsigned char *cur_sha1, const unsigned char *new_sha1);
-int combine_notes_ignore(unsigned char *cur_sha1, const unsigned char *new_sha1);
-int combine_notes_cat_sort_uniq(unsigned char *cur_sha1, const unsigned char *new_sha1);
+int combine_notes_concatenate(struct object_id *cur_oid,
+			      const struct object_id *new_oid);
+int combine_notes_overwrite(struct object_id *cur_oid,
+			    const struct object_id *new_oid);
+int combine_notes_ignore(struct object_id *cur_oid,
+			 const struct object_id *new_oid);
+int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+				const struct object_id *new_oid);
 
 /*
  * Notes tree object
-- 
2.14.3
Previous: Duy NguyenNext: Patryk Obara
Message 25 of 75 in “Some fixes and bunch of object_id conversions”
  1. 00/11 Some fixes and bunch of object_id conversionsPatryk Obara, Jan 18, 2018
  2. 01/11 http-push: improve error logPatryk Obara, Jan 18, 2018
  3. 02/11 clang-format: adjust penalty for return type line breakPatryk Obara, Jan 18, 2018
  4. 04/11 dir: convert struct sha1_stat to use object_idPatryk Obara, Jan 18, 2018
  5. 06/11 cache: clear whole hash buffer with oidclrPatryk Obara, Jan 18, 2018
  6. 07/11 match-trees: convert splice_tree to object_idPatryk Obara, Jan 18, 2018
  7. 09/11 notes: convert combine_notes_* to object_idPatryk Obara, Jan 18, 2018
  8. 08/11 commit: convert commit_tree* to object_idPatryk Obara, Jan 18, 2018
  9. 11/11 sha1_file: convert write_sha1_file to object_idPatryk Obara, Jan 18, 2018
  10. brian m. carlsonJan 20, 2018
  11. Patryk ObaraJan 21, 2018
  12. 10/11 notes: convert write_notes_tree to object_idPatryk Obara, Jan 18, 2018
  13. 05/11 sha1_file: convert hash_sha1_file to object_idPatryk Obara, Jan 18, 2018
  14. 03/11 sha1_file: convert pretend_sha1_file to object_idPatryk Obara, Jan 18, 2018
  15. Jonathan TanJan 18, 2018
  16. brian m. carlsonJan 20, 2018
  17. Patryk ObaraJan 21, 2018
  18. 00/14 Some fixes and bunch of object_id conversionsPatryk Obara, Jan 22, 2018
  19. 02/14 clang-format: adjust penalty for return type line breakPatryk Obara, Jan 22, 2018
  20. 03/14 sha1_file: convert pretend_sha1_file to object_idPatryk Obara, Jan 22, 2018
  21. 07/14 match-trees: convert splice_tree to object_idPatryk Obara, Jan 22, 2018
  22. Duy NguyenJan 22, 2018
  23. Patryk ObaraJan 22, 2018
  24. Duy NguyenJan 23, 2018
  25. 09/14 notes: convert combine_notes_* to object_idPatryk Obara, Jan 22, 2018
  26. 10/14 notes: convert write_notes_tree to object_idPatryk Obara, Jan 22, 2018
  27. Duy NguyenJan 22, 2018
  28. 11/14 sha1_file: convert write_sha1_file to object_idPatryk Obara, Jan 22, 2018
  29. 14/14 sha1_file: rename hash_sha1_file_literallyPatryk Obara, Jan 22, 2018
  30. 12/14 sha1_file: convert force_object_loose to object_idPatryk Obara, Jan 22, 2018
  31. 13/14 sha1_file: convert write_loose_object to object_idPatryk Obara, Jan 22, 2018
  32. 04/14 dir: convert struct sha1_stat to use object_idPatryk Obara, Jan 22, 2018
  33. 05/14 sha1_file: convert hash_sha1_file to object_idPatryk Obara, Jan 22, 2018
  34. Duy NguyenJan 22, 2018
  35. Patryk ObaraJan 22, 2018
  36. Duy NguyenJan 22, 2018
  37. 08/14 commit: convert commit_tree* to object_idPatryk Obara, Jan 22, 2018
  38. 06/14 cache: clear whole hash buffer with oidclrPatryk Obara, Jan 22, 2018
  39. 01/14 http-push: improve error logPatryk Obara, Jan 22, 2018
  40. Duy NguyenJan 22, 2018
  41. Patryk ObaraJan 22, 2018
  42. 00/14 Some fixes and bunch of object_id conversionsPatryk Obara, Jan 24, 2018
  43. 02/14 clang-format: adjust penalty for return type line breakPatryk Obara, Jan 24, 2018
  44. 07/14 match-trees: convert splice_tree to object_idPatryk Obara, Jan 24, 2018
  45. 11/14 sha1_file: convert write_sha1_file to object_idPatryk Obara, Jan 24, 2018
  46. 10/14 notes: convert write_notes_tree to object_idPatryk Obara, Jan 24, 2018
  47. 08/14 commit: convert commit_tree* to object_idPatryk Obara, Jan 24, 2018
  48. 09/14 notes: convert combine_notes_* to object_idPatryk Obara, Jan 24, 2018
  49. 13/14 sha1_file: convert write_loose_object to object_idPatryk Obara, Jan 24, 2018
  50. brian m. carlsonJan 26, 2018
  51. 12/14 sha1_file: convert force_object_loose to object_idPatryk Obara, Jan 24, 2018
  52. 14/14 sha1_file: rename hash_sha1_file_literallyPatryk Obara, Jan 24, 2018
  53. 01/14 http-push: improve error logPatryk Obara, Jan 24, 2018
  54. 05/14 sha1_file: convert hash_sha1_file to object_idPatryk Obara, Jan 24, 2018
  55. 03/14 sha1_file: convert pretend_sha1_file to object_idPatryk Obara, Jan 24, 2018
  56. 04/14 dir: convert struct sha1_stat to use object_idPatryk Obara, Jan 24, 2018
  57. Junio C HamanoJan 24, 2018
  58. 06/14 cache: clear whole hash buffer with oidclrPatryk Obara, Jan 24, 2018
  59. Junio C HamanoJan 24, 2018
  60. Junio C HamanoJan 24, 2018
  61. Duy NguyenJan 25, 2018
  62. brian m. carlsonJan 27, 2018
  63. 00/12 A bunch of object_id conversionsPatryk Obara, Jan 28, 2018
  64. 01/12 sha1_file: convert pretend_sha1_file to object_idPatryk Obara, Jan 28, 2018
  65. 03/12 sha1_file: convert hash_sha1_file to object_idPatryk Obara, Jan 28, 2018
  66. 05/12 match-trees: convert splice_tree to object_idPatryk Obara, Jan 28, 2018
  67. 08/12 notes: convert write_notes_tree to object_idPatryk Obara, Jan 28, 2018
  68. 04/12 cache: clear whole hash buffer with oidclrPatryk Obara, Jan 28, 2018
  69. 09/12 sha1_file: convert write_sha1_file to object_idPatryk Obara, Jan 28, 2018
  70. 07/12 notes: convert combine_notes_* to object_idPatryk Obara, Jan 28, 2018
  71. 10/12 sha1_file: convert force_object_loose to object_idPatryk Obara, Jan 28, 2018
  72. 11/12 sha1_file: convert write_loose_object to object_idPatryk Obara, Jan 28, 2018
  73. 12/12 sha1_file: rename hash_sha1_file_literallyPatryk Obara, Jan 28, 2018
  74. 06/12 commit: convert commit_tree* to object_idPatryk Obara, Jan 28, 2018
  75. 02/12 dir: convert struct sha1_stat to use object_idPatryk Obara, Jan 28, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.