From: Patryk Obara <patryk.obara@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
sandals@crustytoothpaste.ath.cx,
Jonathan Tan <jonathantanmy@google.com>
Subject: [PATCH v2 09/14] notes: convert combine_notes_* to object_id
Date: Mon, 22 Jan 2018 12:04:32 +0100 [thread overview]
Message-ID: <c9f48766ca447e0f66f32ea00ecfc519cdaef8a2.1516617960.git.patryk.obara@gmail.com> (raw)
In-Reply-To: <cover.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
next prev parent reply other threads:[~2018-01-22 11:04 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-18 14:50 [PATCH 00/11] Some fixes and bunch of object_id conversions Patryk Obara
2018-01-18 14:50 ` [PATCH 01/11] http-push: improve error log Patryk Obara
2018-01-18 14:50 ` [PATCH 02/11] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-18 14:50 ` [PATCH 03/11] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 04/11] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 05/11] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 06/11] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-18 14:50 ` [PATCH 07/11] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-18 14:51 ` [PATCH 08/11] commit: convert commit_tree* " Patryk Obara
2018-01-18 14:51 ` [PATCH 09/11] notes: convert combine_notes_* " Patryk Obara
2018-01-18 14:51 ` [PATCH 10/11] notes: convert write_notes_tree " Patryk Obara
2018-01-18 14:51 ` [PATCH 11/11] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-20 20:44 ` brian m. carlson
2018-01-21 16:26 ` Patryk Obara
2018-01-18 17:42 ` [PATCH 00/11] Some fixes and bunch of object_id conversions Jonathan Tan
2018-01-20 20:58 ` brian m. carlson
2018-01-21 16:35 ` Patryk Obara
2018-01-22 11:04 ` [PATCH v2 00/14] " Patryk Obara
2018-01-22 11:04 ` [PATCH v2 01/14] http-push: improve error log Patryk Obara
2018-01-22 11:04 ` [PATCH v2 02/14] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-22 11:04 ` [PATCH v2 03/14] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-22 11:04 ` [PATCH v2 04/14] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-22 11:04 ` [PATCH v2 05/14] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-22 11:49 ` Duy Nguyen
2018-01-22 12:44 ` Patryk Obara
2018-01-22 12:52 ` Duy Nguyen
2018-01-22 11:04 ` [PATCH v2 06/14] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-22 11:04 ` [PATCH v2 07/14] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-22 11:56 ` Duy Nguyen
2018-01-22 13:12 ` Patryk Obara
2018-01-23 1:29 ` Duy Nguyen
2018-01-22 11:04 ` [PATCH v2 08/14] commit: convert commit_tree* " Patryk Obara
2018-01-22 11:04 ` Patryk Obara [this message]
2018-01-22 11:04 ` [PATCH v2 10/14] notes: convert write_notes_tree " Patryk Obara
2018-01-22 12:03 ` Duy Nguyen
2018-01-22 11:04 ` [PATCH v2 11/14] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-22 11:04 ` [PATCH v2 12/14] sha1_file: convert force_object_loose " Patryk Obara
2018-01-22 11:04 ` [PATCH v2 13/14] sha1_file: convert write_loose_object " Patryk Obara
2018-01-22 11:04 ` [PATCH v2 14/14] sha1_file: rename hash_sha1_file_literally Patryk Obara
2018-01-22 12:14 ` [PATCH v2 00/14] Some fixes and bunch of object_id conversions Duy Nguyen
2018-01-22 13:26 ` Patryk Obara
2018-01-24 11:11 ` [PATCH v3 " Patryk Obara
2018-01-24 11:11 ` [PATCH v3 01/14] http-push: improve error log Patryk Obara
2018-01-24 11:11 ` [PATCH v3 02/14] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-24 11:11 ` [PATCH v3 03/14] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-24 11:11 ` [PATCH v3 04/14] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-24 21:36 ` Junio C Hamano
2018-01-24 11:11 ` [PATCH v3 05/14] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-24 11:11 ` [PATCH v3 06/14] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-24 11:11 ` [PATCH v3 07/14] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-24 11:12 ` [PATCH v3 08/14] commit: convert commit_tree* " Patryk Obara
2018-01-24 11:12 ` [PATCH v3 09/14] notes: convert combine_notes_* " Patryk Obara
2018-01-24 11:12 ` [PATCH v3 10/14] notes: convert write_notes_tree " Patryk Obara
2018-01-24 11:12 ` [PATCH v3 11/14] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-24 11:12 ` [PATCH v3 12/14] sha1_file: convert force_object_loose " Patryk Obara
2018-01-24 11:12 ` [PATCH v3 13/14] sha1_file: convert write_loose_object " Patryk Obara
2018-01-26 23:14 ` brian m. carlson
2018-01-24 11:12 ` [PATCH v3 14/14] sha1_file: rename hash_sha1_file_literally Patryk Obara
2018-01-24 21:28 ` [PATCH v3 00/14] Some fixes and bunch of object_id conversions Junio C Hamano
2018-01-24 21:41 ` Junio C Hamano
2018-01-25 9:53 ` Duy Nguyen
2018-01-27 0:12 ` brian m. carlson
2018-01-28 0:13 ` [PATCH v4 00/12] A " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 01/12] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-28 0:13 ` [PATCH v4 02/12] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-28 0:13 ` [PATCH v4 03/12] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-28 0:13 ` [PATCH v4 04/12] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-28 0:13 ` [PATCH v4 05/12] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-28 0:13 ` [PATCH v4 06/12] commit: convert commit_tree* " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 07/12] notes: convert combine_notes_* " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 08/12] notes: convert write_notes_tree " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 09/12] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 10/12] sha1_file: convert force_object_loose " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 11/12] sha1_file: convert write_loose_object " Patryk Obara
2018-01-28 0:13 ` [PATCH v4 12/12] sha1_file: rename hash_sha1_file_literally Patryk Obara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9f48766ca447e0f66f32ea00ecfc519cdaef8a2.1516617960.git.patryk.obara@gmail.com \
--to=patryk.obara@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
--cc=sandals@crustytoothpaste.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).