All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, sandals@crustytoothpaste.net,
	Brandon Williams <bmwill@google.com>
Subject: [PATCH 07/33] notes: convert some accessor functions to struct object_id
Date: Tue, 30 May 2017 10:30:43 -0700	[thread overview]
Message-ID: <20170530173109.54904-8-bmwill@google.com> (raw)
In-Reply-To: <20170530173109.54904-1-bmwill@google.com>

From: "brian m. carlson" <sandals@crustytoothpaste.net>

Convert add_note, get_note, and copy_note to take struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/notes.c  | 20 ++++++++++----------
 notes-cache.c    |  4 ++--
 notes-merge.c    | 18 +++++++++---------
 notes-utils.c    |  2 +-
 notes.c          | 20 ++++++++++----------
 notes.h          |  8 ++++----
 remote-testsvn.c | 10 +++++-----
 7 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 7947a16ed..b13fc8789 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -309,7 +309,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 		if (rewrite_cmd)
 			err = copy_note_for_rewrite(c, &from_obj, &to_obj);
 		else
-			err = copy_note(t, from_obj.hash, to_obj.hash, force,
+			err = copy_note(t, &from_obj, &to_obj, force,
 					combine_notes_overwrite);
 
 		if (err) {
@@ -370,7 +370,7 @@ static int list(int argc, const char **argv, const char *prefix)
 	if (argc) {
 		if (get_oid(argv[0], &object))
 			die(_("failed to resolve '%s' as a valid ref."), argv[0]);
-		note = get_note(t, object.hash);
+		note = get_note(t, &object);
 		if (note) {
 			puts(oid_to_hex(note));
 			retval = 0;
@@ -427,7 +427,7 @@ static int add(int argc, const char **argv, const char *prefix)
 		die(_("failed to resolve '%s' as a valid ref."), object_ref);
 
 	t = init_notes_check("add", NOTES_INIT_WRITABLE);
-	note = get_note(t, object.hash);
+	note = get_note(t, &object);
 
 	if (note) {
 		if (!force) {
@@ -456,7 +456,7 @@ static int add(int argc, const char **argv, const char *prefix)
 	prepare_note_data(&object, &d, note->hash);
 	if (d.buf.len || allow_empty) {
 		write_note_data(&d, new_note.hash);
-		if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
+		if (add_note(t, &object, &new_note, combine_notes_overwrite))
 			die("BUG: combine_notes_overwrite failed");
 		commit_notes(t, "Notes added by 'git notes add'");
 	} else {
@@ -518,7 +518,7 @@ static int copy(int argc, const char **argv, const char *prefix)
 		die(_("failed to resolve '%s' as a valid ref."), object_ref);
 
 	t = init_notes_check("copy", NOTES_INIT_WRITABLE);
-	note = get_note(t, object.hash);
+	note = get_note(t, &object);
 
 	if (note) {
 		if (!force) {
@@ -532,14 +532,14 @@ static int copy(int argc, const char **argv, const char *prefix)
 			oid_to_hex(&object));
 	}
 
-	from_note = get_note(t, from_obj.hash);
+	from_note = get_note(t, &from_obj);
 	if (!from_note) {
 		retval = error(_("missing notes on source object %s. Cannot "
 			       "copy."), oid_to_hex(&from_obj));
 		goto out;
 	}
 
-	if (add_note(t, object.hash, from_note->hash, combine_notes_overwrite))
+	if (add_note(t, &object, from_note, combine_notes_overwrite))
 		die("BUG: combine_notes_overwrite failed");
 	commit_notes(t, "Notes added by 'git notes copy'");
 out:
@@ -596,7 +596,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 		die(_("failed to resolve '%s' as a valid ref."), object_ref);
 
 	t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
-	note = get_note(t, object.hash);
+	note = get_note(t, &object);
 
 	prepare_note_data(&object, &d, edit && note ? note->hash : NULL);
 
@@ -616,7 +616,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 
 	if (d.buf.len || allow_empty) {
 		write_note_data(&d, new_note.hash);
-		if (add_note(t, object.hash, new_note.hash, combine_notes_overwrite))
+		if (add_note(t, &object, &new_note, combine_notes_overwrite))
 			die("BUG: combine_notes_overwrite failed");
 		logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
 	} else {
@@ -658,7 +658,7 @@ static int show(int argc, const char **argv, const char *prefix)
 		die(_("failed to resolve '%s' as a valid ref."), object_ref);
 
 	t = init_notes_check("show", 0);
-	note = get_note(t, object.hash);
+	note = get_note(t, &object);
 
 	if (!note)
 		retval = error(_("no note found for object %s."),
diff --git a/notes-cache.c b/notes-cache.c
index 6e84a748f..29b4cede5 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -74,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
 	char *value;
 	unsigned long size;
 
-	value_oid = get_note(&c->tree, key_oid->hash);
+	value_oid = get_note(&c->tree, key_oid);
 	if (!value_oid)
 		return NULL;
 	value = read_sha1_file(value_oid->hash, &type, &size);
@@ -90,5 +90,5 @@ int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
 
 	if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
 		return -1;
-	return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL);
+	return add_note(&c->tree, key_oid, &value_oid, NULL);
 }
diff --git a/notes-merge.c b/notes-merge.c
index 6244f6af9..9a1a49506 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -444,14 +444,14 @@ static int merge_one_change(struct notes_merge_options *o,
 		if (o->verbosity >= 2)
 			printf("Using remote notes for %s\n",
 						oid_to_hex(&p->obj));
-		if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))
+		if (add_note(t, &p->obj, &p->remote, combine_notes_overwrite))
 			die("BUG: combine_notes_overwrite failed");
 		return 0;
 	case NOTES_MERGE_RESOLVE_UNION:
 		if (o->verbosity >= 2)
 			printf("Concatenating local and remote notes for %s\n",
 							oid_to_hex(&p->obj));
-		if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))
+		if (add_note(t, &p->obj, &p->remote, combine_notes_concatenate))
 			die("failed to concatenate notes "
 			    "(combine_notes_concatenate)");
 		return 0;
@@ -459,7 +459,7 @@ static int merge_one_change(struct notes_merge_options *o,
 		if (o->verbosity >= 2)
 			printf("Concatenating unique lines in local and remote "
 				"notes for %s\n", oid_to_hex(&p->obj));
-		if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq))
+		if (add_note(t, &p->obj, &p->remote, combine_notes_cat_sort_uniq))
 			die("failed to concatenate notes "
 			    "(combine_notes_cat_sort_uniq)");
 		return 0;
@@ -491,7 +491,7 @@ static int merge_changes(struct notes_merge_options *o,
 			   !oidcmp(&p->local, &p->base)) {
 			/* no local change; adopt remote change */
 			trace_printf("\t\t\tno local change, adopted remote\n");
-			if (add_note(t, p->obj.hash, p->remote.hash,
+			if (add_note(t, &p->obj, &p->remote,
 				     combine_notes_overwrite))
 				die("BUG: combine_notes_overwrite failed");
 		} else {
@@ -693,12 +693,12 @@ int notes_merge_commit(struct notes_merge_options *o,
 	baselen = path.len;
 	while ((e = readdir(dir)) != NULL) {
 		struct stat st;
-		unsigned char obj_sha1[20], blob_sha1[20];
+		struct object_id obj_oid, blob_oid;
 
 		if (is_dot_or_dotdot(e->d_name))
 			continue;
 
-		if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) {
+		if (get_oid_hex(e->d_name, &obj_oid)) {
 			if (o->verbosity >= 3)
 				printf("Skipping non-SHA1 entry '%s%s'\n",
 					path.buf, e->d_name);
@@ -709,14 +709,14 @@ int notes_merge_commit(struct notes_merge_options *o,
 		/* write file as blob, and add to partial_tree */
 		if (stat(path.buf, &st))
 			die_errno("Failed to stat '%s'", path.buf);
-		if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT))
+		if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT))
 			die("Failed to write blob object from '%s'", path.buf);
-		if (add_note(partial_tree, obj_sha1, blob_sha1, NULL))
+		if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
 			die("Failed to add resolved note '%s' to notes tree",
 			    path.buf);
 		if (o->verbosity >= 4)
 			printf("Added resolved note for object %s: %s\n",
-				sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
+				oid_to_hex(&obj_oid), oid_to_hex(&blob_oid));
 		strbuf_setlen(&path, baselen);
 	}
 
diff --git a/notes-utils.c b/notes-utils.c
index 7d7c22b43..b2aada90a 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -160,7 +160,7 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 	int ret = 0;
 	int i;
 	for (i = 0; c->trees[i]; i++)
-		ret = copy_note(c->trees[i], from_obj->hash, to_obj->hash, 1, c->combine) || ret;
+		ret = copy_note(c->trees[i], from_obj, to_obj, 1, c->combine) || ret;
 	return ret;
 }
 
diff --git a/notes.c b/notes.c
index b5cabafde..4b3a1adda 100644
--- a/notes.c
+++ b/notes.c
@@ -1086,8 +1086,8 @@ void init_display_notes(struct display_notes_opt *opt)
 	string_list_clear(&display_notes_refs, 0);
 }
 
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
-		const unsigned char *note_sha1, combine_notes_fn combine_notes)
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
+		const struct object_id *note_oid, combine_notes_fn combine_notes)
 {
 	struct leaf_node *l;
 
@@ -1098,8 +1098,8 @@ int add_note(struct notes_tree *t, const unsigned char *object_sha1,
 	if (!combine_notes)
 		combine_notes = t->combine_notes;
 	l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
-	hashcpy(l->key_oid.hash, object_sha1);
-	hashcpy(l->val_oid.hash, note_sha1);
+	oidcpy(&l->key_oid, object_oid);
+	oidcpy(&l->val_oid, note_oid);
 	return note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
 }
 
@@ -1120,14 +1120,14 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
 }
 
 const struct object_id *get_note(struct notes_tree *t,
-		const unsigned char *object_sha1)
+		const struct object_id *oid)
 {
 	struct leaf_node *found;
 
 	if (!t)
 		t = &default_notes_tree;
 	assert(t->initialized);
-	found = note_tree_find(t, t->root, 0, object_sha1);
+	found = note_tree_find(t, t->root, 0, oid->hash);
 	return found ? &found->val_oid : NULL;
 }
 
@@ -1229,7 +1229,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!t->initialized)
 		init_notes(t, NULL, NULL, 0);
 
-	oid = get_note(t, object_oid->hash);
+	oid = get_note(t, object_oid);
 	if (!oid)
 		return;
 
@@ -1288,7 +1288,7 @@ void format_display_notes(const struct object_id *object_oid,
 }
 
 int copy_note(struct notes_tree *t,
-	      const unsigned char *from_obj, const unsigned char *to_obj,
+	      const struct object_id *from_obj, const struct object_id *to_obj,
 	      int force, combine_notes_fn combine_notes)
 {
 	const struct object_id *note = get_note(t, from_obj);
@@ -1298,9 +1298,9 @@ int copy_note(struct notes_tree *t,
 		return 1;
 
 	if (note)
-		return add_note(t, to_obj, note->hash, combine_notes);
+		return add_note(t, to_obj, note, combine_notes);
 	else if (existing_note)
-		return add_note(t, to_obj, null_sha1, combine_notes);
+		return add_note(t, to_obj, &null_oid, combine_notes);
 
 	return 0;
 }
diff --git a/notes.h b/notes.h
index a66532103..3848c2fb3 100644
--- a/notes.h
+++ b/notes.h
@@ -121,8 +121,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
  * are not persistent until a subsequent call to write_notes_tree() returns
  * zero.
  */
-int add_note(struct notes_tree *t, const unsigned char *object_sha1,
-		const unsigned char *note_sha1, combine_notes_fn combine_notes);
+int add_note(struct notes_tree *t, const struct object_id *object_oid,
+		const struct object_id *note_oid, combine_notes_fn combine_notes);
 
 /*
  * Remove the given note object from the given notes_tree structure
@@ -141,7 +141,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1);
  * Return NULL if the given object has no notes.
  */
 const struct object_id *get_note(struct notes_tree *t,
-		const unsigned char *object_sha1);
+		const struct object_id *object_oid);
 
 /*
  * Copy a note from one object to another in the given notes_tree.
@@ -156,7 +156,7 @@ const struct object_id *get_note(struct notes_tree *t,
  * zero.
  */
 int copy_note(struct notes_tree *t,
-	      const unsigned char *from_obj, const unsigned char *to_obj,
+	      const struct object_id *from_obj, const struct object_id *to_obj,
 	      int force, combine_notes_fn combine_notes);
 
 /*
diff --git a/remote-testsvn.c b/remote-testsvn.c
index 017af1bd5..8e8d5c794 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -51,7 +51,7 @@ static void terminate_batch(void)
 }
 
 /* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */
-static char *read_ref_note(const unsigned char sha1[20])
+static char *read_ref_note(const struct object_id *oid)
 {
 	const struct object_id *note_oid;
 	char *msg = NULL;
@@ -59,7 +59,7 @@ static char *read_ref_note(const unsigned char sha1[20])
 	enum object_type type;
 
 	init_notes(NULL, notes_ref, NULL, 0);
-	if (!(note_oid = get_note(NULL, sha1)))
+	if (!(note_oid = get_note(NULL, oid)))
 		return NULL;	/* note tree not found */
 	if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))
 		error("Empty notes tree. %s", notes_ref);
@@ -174,15 +174,15 @@ static int cmd_import(const char *line)
 	int code;
 	int dumpin_fd;
 	char *note_msg;
-	unsigned char head_sha1[20];
+	struct object_id head_oid;
 	unsigned int startrev;
 	struct child_process svndump_proc = CHILD_PROCESS_INIT;
 	const char *command = "svnrdump";
 
-	if (read_ref(private_ref, head_sha1))
+	if (read_ref(private_ref, head_oid.hash))
 		startrev = 0;
 	else {
-		note_msg = read_ref_note(head_sha1);
+		note_msg = read_ref_note(&head_oid);
 		if(note_msg == NULL) {
 			warning("No note found for %s.", private_ref);
 			startrev = 0;
-- 
2.13.0.219.gdb65acc882-goog


  parent reply	other threads:[~2017-05-30 17:31 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 17:30 [PATCH 00/33] object id conversion (grep and diff) Brandon Williams
2017-05-30 17:30 ` [PATCH 01/33] notes: convert internal structures to struct object_id Brandon Williams
2017-05-30 17:30 ` [PATCH 02/33] notes: convert internal parts " Brandon Williams
2017-05-30 17:30 ` [PATCH 03/33] notes: convert for_each_note " Brandon Williams
2017-05-30 17:30 ` [PATCH 04/33] notes: make get_note return pointer " Brandon Williams
2017-07-15 18:15   ` René Scharfe
2017-07-17 17:49     ` Brandon Williams
2017-05-30 17:30 ` [PATCH 05/33] notes: convert format_display_notes " Brandon Williams
2017-05-30 17:30 ` [PATCH 06/33] builtin/notes: convert " Brandon Williams
2017-05-30 17:30 ` Brandon Williams [this message]
2017-05-30 17:30 ` [PATCH 08/33] grep: " Brandon Williams
2017-06-02  1:00   ` Junio C Hamano
2017-05-30 17:30 ` [PATCH 09/33] diff: convert get_stat_data " Brandon Williams
2017-05-30 17:30 ` [PATCH 10/33] diff: convert diff_index_show_file " Brandon Williams
2017-05-30 17:30 ` [PATCH 11/33] diff: convert diff_addremove " Brandon Williams
2017-05-30 17:30 ` [PATCH 12/33] diff: convert run_diff_files " Brandon Williams
2017-05-30 17:30 ` [PATCH 13/33] diff: convert diff_change " Brandon Williams
2017-05-30 17:30 ` [PATCH 14/33] diff: convert fill_filespec " Brandon Williams
2017-05-30 17:30 ` [PATCH 15/33] diff: convert reuse_worktree_file " Brandon Williams
2017-05-30 17:30 ` [PATCH 16/33] diff: finish conversion for prepare_temp_file " Brandon Williams
2017-05-31  0:41   ` Stefan Beller
2017-05-30 17:30 ` [PATCH 17/33] patch-ids: convert " Brandon Williams
2017-05-30 17:30 ` [PATCH 18/33] diff: convert diff_flush_patch_id " Brandon Williams
2017-05-30 17:30 ` [PATCH 19/33] combine-diff: convert diff_tree_combined " Brandon Williams
2017-05-30 17:30 ` [PATCH 20/33] combine-diff: convert find_paths_* " Brandon Williams
2017-05-31 17:49   ` Stefan Beller
2017-06-02  1:37     ` Junio C Hamano
2017-05-30 17:30 ` [PATCH 21/33] tree-diff: convert diff_root_tree_sha1 " Brandon Williams
2017-05-30 17:30 ` [PATCH 22/33] notes-merge: convert notes_merge* " Brandon Williams
2017-05-31 17:54   ` Stefan Beller
2017-05-31 22:00   ` brian m. carlson
2017-06-02  1:13     ` Junio C Hamano
2017-06-02 18:32     ` Brandon Williams
2017-05-30 17:30 ` [PATCH 23/33] notes-merge: convert merge_from_diffs " Brandon Williams
2017-05-31 18:04   ` Stefan Beller
2017-06-02  0:42     ` Junio C Hamano
2017-05-30 17:31 ` [PATCH 24/33] notes-merge: convert find_notes_merge_pair_ps " Brandon Williams
2017-05-30 17:31 ` [PATCH 25/33] notes-merge: convert verify_notes_filepair " Brandon Williams
2017-05-31 18:09   ` Stefan Beller
2017-06-02  0:47   ` Junio C Hamano
2017-06-02 18:55     ` Brandon Williams
2017-06-02 23:49       ` Junio C Hamano
2017-05-30 17:31 ` [PATCH 26/33] notes-merge: convert write_note_to_worktree " Brandon Williams
2017-05-30 17:31 ` [PATCH 27/33] diff-tree: convert diff_tree_sha1 " Brandon Williams
2017-05-30 17:31 ` [PATCH 28/33] builtin/diff-tree: cleanup references to sha1 Brandon Williams
2017-06-02  1:26   ` Junio C Hamano
2017-05-30 17:31 ` [PATCH 29/33] tree-diff: convert try_to_follow_renames to struct object_id Brandon Williams
2017-05-30 17:31 ` [PATCH 30/33] tree-diff: convert diff_tree_paths " Brandon Williams
2017-05-31 18:24   ` Stefan Beller
2017-05-31 21:29     ` Jeff King
2017-05-31 21:39       ` Jeff King
2017-06-02  1:31   ` Junio C Hamano
2017-07-15 17:18   ` René Scharfe
2017-07-15 17:22     ` brian m. carlson
2017-05-30 17:31 ` [PATCH 31/33] tree-diff: convert path_appendnew to object_id Brandon Williams
2017-06-02  1:32   ` Junio C Hamano
2017-05-30 17:31 ` [PATCH 32/33] diffcore-rename: use is_empty_blob_oid Brandon Williams
2017-05-30 17:31 ` [PATCH 33/33] diff: rename diff_fill_sha1_info to diff_fill_oid_info Brandon Williams
2017-05-31 22:06 ` [PATCH 00/33] object id conversion (grep and diff) brian m. carlson
2017-06-02 19:24   ` Brandon Williams
2017-06-02  1:34 ` Junio C Hamano
2017-06-02  5:08   ` Junio C Hamano
2017-06-02  7:19     ` Junio C Hamano
2017-06-02 18:22       ` Brandon Williams
2017-06-02 23:35         ` Junio C Hamano
2017-06-05 19:42           ` Brandon Williams

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=20170530173109.54904-8-bmwill@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.