git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* [PATCH v2 00/24] object_id part 10
@ 2017-10-09  1:11 brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 01/24] walker: convert to struct object_id brian m. carlson
                   ` (26 more replies)
  0 siblings, 27 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

This is the tenth in a series of patches to convert from unsigned char
[20] to struct object_id.  This series mostly involves changes to the
refs code.  After these changes, there are almost no references to
unsigned char in the main refs code.

The series has not been rebased on master since the last submission, but
I can do so if that's more convenient.

This series is available from the following URL:
https://github.com/bk2204/git.git object-id-part10

Changes from v1:
* Fix line wrapping in several places.
* Remove empty line.
* Update die messages to refer to "object ID" instead of "sha1".

brian m. carlson (24):
  walker: convert to struct object_id
  refs/files-backend: convert struct ref_to_prune to object_id
  refs: convert delete_ref and refs_delete_ref to struct object_id
  refs: convert update_ref and refs_update_ref to use struct object_id
  refs: update ref transactions to use struct object_id
  Convert check_connected to use struct object_id
  refs: convert resolve_refdup and refs_resolve_refdup to struct
    object_id
  refs: convert read_ref and read_ref_full to object_id
  refs: convert dwim_ref and expand_ref to struct object_id
  builtin/reflog: convert remaining unsigned char uses to object_id
  refs: convert dwim_log to struct object_id
  pack-bitmap: convert traverse_bitmap_commit_list to object_id
  builtin/pack-objects: convert to struct object_id
  refs: convert peel_ref to struct object_id
  refs: convert read_ref_at to struct object_id
  refs: convert reflog_expire parameter to struct object_id
  sha1_file: convert index_path and index_fd to struct object_id
  Convert remaining callers of resolve_gitlink_ref to object_id
  refs: convert resolve_gitlink_ref to struct object_id
  worktree: convert struct worktree to object_id
  refs: convert resolve_ref_unsafe to struct object_id
  refs: convert peel_object to struct object_id
  refs: convert read_raw_ref backends to struct object_id
  refs/files-backend: convert static functions to object_id

 archive.c                   |   2 +-
 bisect.c                    |   5 +-
 blame.c                     |   4 +-
 branch.c                    |   4 +-
 builtin/am.c                |  16 ++--
 builtin/branch.c            |   8 +-
 builtin/checkout.c          |  13 ++-
 builtin/clone.c             |  22 ++---
 builtin/commit.c            |   4 +-
 builtin/describe.c          |   2 +-
 builtin/fast-export.c       |   2 +-
 builtin/fetch.c             |   8 +-
 builtin/fmt-merge-msg.c     |   2 +-
 builtin/fsck.c              |   2 +-
 builtin/log.c               |   2 +-
 builtin/merge-base.c        |   2 +-
 builtin/merge.c             |  17 ++--
 builtin/notes.c             |  12 +--
 builtin/pack-objects.c      | 139 ++++++++++++++-------------
 builtin/pull.c              |   2 +-
 builtin/receive-pack.c      |  16 ++--
 builtin/reflog.c            |  18 ++--
 builtin/remote.c            |   2 +-
 builtin/replace.c           |   8 +-
 builtin/reset.c             |   6 +-
 builtin/rev-list.c          |   4 +-
 builtin/rev-parse.c         |   2 +-
 builtin/show-branch.c       |  12 +--
 builtin/show-ref.c          |   4 +-
 builtin/submodule--helper.c |   2 +-
 builtin/tag.c               |   8 +-
 builtin/update-index.c      |  10 +-
 builtin/update-ref.c        |  12 +--
 builtin/worktree.c          |   6 +-
 bundle.c                    |   4 +-
 combine-diff.c              |   2 +-
 connected.c                 |  18 ++--
 connected.h                 |   4 +-
 diff-lib.c                  |   4 +-
 dir.c                       |   8 +-
 fast-import.c               |   6 +-
 notes-cache.c               |   4 +-
 notes-merge.c               |   2 +-
 notes-utils.c               |   4 +-
 notes.c                     |   2 +-
 pack-bitmap.c               |   8 +-
 pack-bitmap.h               |   2 +-
 read-cache.c                |   6 +-
 ref-filter.c                |   4 +-
 reflog-walk.c               |   6 +-
 refs.c                      | 229 +++++++++++++++++++++-----------------------
 refs.h                      |  75 +++++++--------
 refs/files-backend.c        | 118 +++++++++++------------
 refs/packed-backend.c       |  14 +--
 refs/ref-cache.c            |   2 +-
 refs/refs-internal.h        |  22 ++---
 remote-testsvn.c            |   2 +-
 remote.c                    |   9 +-
 sequencer.c                 |  15 ++-
 sha1_file.c                 |  32 +++----
 sha1_name.c                 |  10 +-
 submodule.c                 |   2 +-
 t/helper/test-ref-store.c   |  28 +++---
 transport-helper.c          |  15 ++-
 transport.c                 |   6 +-
 unpack-trees.c              |   8 +-
 upload-pack.c               |   4 +-
 walker.c                    |  24 ++---
 worktree.c                  |   2 +-
 worktree.h                  |   2 +-
 wt-status.c                 |   4 +-
 71 files changed, 533 insertions(+), 552 deletions(-)

-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 01/24] walker: convert to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
@ 2017-10-09  1:11 ` brian m. carlson
  2017-10-09 22:37   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to " brian m. carlson
                   ` (25 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 walker.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/walker.c b/walker.c
index 274f1a4935..2d83254bc0 100644
--- a/walker.c
+++ b/walker.c
@@ -7,7 +7,7 @@
 #include "blob.h"
 #include "refs.h"
 
-static unsigned char current_commit_sha1[20];
+static struct object_id current_commit_oid;
 
 void walker_say(struct walker *walker, const char *fmt, ...)
 {
@@ -24,9 +24,9 @@ static void report_missing(const struct object *obj)
 	fprintf(stderr, "Cannot obtain needed %s %s\n",
 		obj->type ? typename(obj->type): "object",
 		oid_to_hex(&obj->oid));
-	if (!is_null_sha1(current_commit_sha1))
+	if (!is_null_oid(&current_commit_oid))
 		fprintf(stderr, "while processing commit %s.\n",
-			sha1_to_hex(current_commit_sha1));
+			oid_to_hex(&current_commit_oid));
 }
 
 static int process(struct walker *walker, struct object *obj);
@@ -82,7 +82,7 @@ static int process_commit(struct walker *walker, struct commit *commit)
 	if (commit->object.flags & COMPLETE)
 		return 0;
 
-	hashcpy(current_commit_sha1, commit->object.oid.hash);
+	oidcpy(&current_commit_oid, &commit->object.oid);
 
 	walker_say(walker, "walk %s\n", oid_to_hex(&commit->object.oid));
 
@@ -187,14 +187,14 @@ static int loop(struct walker *walker)
 	return 0;
 }
 
-static int interpret_target(struct walker *walker, char *target, unsigned char *sha1)
+static int interpret_target(struct walker *walker, char *target, struct object_id *oid)
 {
-	if (!get_sha1_hex(target, sha1))
+	if (!get_oid_hex(target, oid))
 		return 0;
 	if (!check_refname_format(target, 0)) {
 		struct ref *ref = alloc_ref(target);
 		if (!walker->fetch_ref(walker, ref)) {
-			hashcpy(sha1, ref->old_oid.hash);
+			oidcpy(oid, &ref->old_oid);
 			free(ref);
 			return 0;
 		}
@@ -259,7 +259,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 	struct strbuf refname = STRBUF_INIT;
 	struct strbuf err = STRBUF_INIT;
 	struct ref_transaction *transaction = NULL;
-	unsigned char *sha1 = xmalloc(targets * 20);
+	struct object_id *oids = xmalloc(targets * sizeof(struct object_id));
 	char *msg = NULL;
 	int i, ret = -1;
 
@@ -279,11 +279,11 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 	}
 
 	for (i = 0; i < targets; i++) {
-		if (interpret_target(walker, target[i], &sha1[20 * i])) {
+		if (interpret_target(walker, target[i], oids + i)) {
 			error("Could not interpret response from server '%s' as something to pull", target[i]);
 			goto done;
 		}
-		if (process(walker, lookup_unknown_object(&sha1[20 * i])))
+		if (process(walker, lookup_unknown_object(oids[i].hash)))
 			goto done;
 	}
 
@@ -304,7 +304,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 		strbuf_reset(&refname);
 		strbuf_addf(&refname, "refs/%s", write_ref[i]);
 		if (ref_transaction_update(transaction, refname.buf,
-					   &sha1[20 * i], NULL, 0,
+					   oids[i].hash, NULL, 0,
 					   msg ? msg : "fetch (unknown)",
 					   &err)) {
 			error("%s", err.buf);
@@ -321,7 +321,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 done:
 	ref_transaction_free(transaction);
 	free(msg);
-	free(sha1);
+	free(oids);
 	strbuf_release(&err);
 	strbuf_release(&refname);
 	return ret;
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 01/24] walker: convert to struct object_id brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 22:38   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct " brian m. carlson
                   ` (24 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Change the member of this struct to be a struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs/files-backend.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index fec77744b4..e3968d4f7c 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -961,7 +961,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 
 struct ref_to_prune {
 	struct ref_to_prune *next;
-	unsigned char sha1[20];
+	struct object_id oid;
 	char name[FLEX_ARRAY];
 };
 
@@ -1029,7 +1029,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
 
 	transaction = ref_store_transaction_begin(&refs->base, &err);
 	if (!transaction ||
-	    ref_transaction_delete(transaction, r->name, r->sha1,
+	    ref_transaction_delete(transaction, r->name, r->oid.hash,
 				   REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		ref_transaction_free(transaction);
@@ -1123,7 +1123,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
 		if ((flags & PACK_REFS_PRUNE)) {
 			struct ref_to_prune *n;
 			FLEX_ALLOC_STR(n, name, iter->refname);
-			hashcpy(n->sha1, iter->oid->hash);
+			oidcpy(&n->oid, iter->oid);
 			n->next = refs_to_prune;
 			refs_to_prune = n;
 		}
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 01/24] walker: convert to struct object_id brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 22:43   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use " brian m. carlson
                   ` (23 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert delete_ref and refs_delete_ref to take a pointer to struct
object_id.  Update the documentation accordingly, including referring to
null_oid in lowercase, as it is not a #define constant.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/branch.c          |  2 +-
 builtin/replace.c         |  2 +-
 builtin/reset.c           |  2 +-
 builtin/tag.c             |  2 +-
 builtin/update-ref.c      |  2 +-
 refs.c                    | 21 +++++++++++----------
 refs.h                    | 12 ++++++------
 refs/files-backend.c      |  2 +-
 t/helper/test-ref-store.c |  6 +++---
 9 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 355f9ef5da..6031b74d68 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -256,7 +256,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 			goto next;
 		}
 
-		if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
+		if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : &oid,
 			       REF_NODEREF)) {
 			error(remote_branch
 			      ? _("Error deleting remote-tracking branch '%s'")
diff --git a/builtin/replace.c b/builtin/replace.c
index 3e71a77152..2854eaa0f3 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -128,7 +128,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
 static int delete_replace_ref(const char *name, const char *ref,
 			      const struct object_id *oid)
 {
-	if (delete_ref(NULL, ref, oid->hash, 0))
+	if (delete_ref(NULL, ref, oid, 0))
 		return 1;
 	printf("Deleted replace ref '%s'\n", name);
 	return 0;
diff --git a/builtin/reset.c b/builtin/reset.c
index 9cd89b2305..5f3632e05b 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -269,7 +269,7 @@ static int reset_refs(const char *rev, const struct object_id *oid)
 		update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
 			   UPDATE_REFS_MSG_ON_ERR);
 	} else if (old_orig)
-		delete_ref(NULL, "ORIG_HEAD", old_orig->hash, 0);
+		delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
 	set_reflog_message(&msg, "updating HEAD", rev);
 	update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
 				       UPDATE_REFS_MSG_ON_ERR);
diff --git a/builtin/tag.c b/builtin/tag.c
index c627794181..46ff4ca736 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -97,7 +97,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 static int delete_tag(const char *name, const char *ref,
 		      const struct object_id *oid, const void *cb_data)
 {
-	if (delete_ref(NULL, ref, oid->hash, 0))
+	if (delete_ref(NULL, ref, oid, 0))
 		return 1;
 	printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
 	return 0;
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6b90c5dead..bf0f80ebae 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -434,7 +434,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 		 * NULL_SHA1 as "don't care" here:
 		 */
 		return delete_ref(msg, refname,
-				  (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
+				  (oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
 				  flags);
 	else
 		return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
diff --git a/refs.c b/refs.c
index 6042645c40..0a5b68d6fb 100644
--- a/refs.c
+++ b/refs.c
@@ -620,25 +620,25 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
 	return ret;
 }
 
-static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1)
+static int delete_pseudoref(const char *pseudoref, const struct object_id *old_oid)
 {
 	static struct lock_file lock;
 	const char *filename;
 
 	filename = git_path("%s", pseudoref);
 
-	if (old_sha1 && !is_null_sha1(old_sha1)) {
+	if (old_oid && !is_null_oid(old_oid)) {
 		int fd;
-		unsigned char actual_old_sha1[20];
+		struct object_id actual_old_oid;
 
 		fd = hold_lock_file_for_update_timeout(
 				&lock, filename, LOCK_DIE_ON_ERROR,
 				get_files_ref_lock_timeout_ms());
 		if (fd < 0)
 			die_errno(_("Could not open '%s' for writing"), filename);
-		if (read_ref(pseudoref, actual_old_sha1))
+		if (read_ref(pseudoref, actual_old_oid.hash))
 			die("could not read ref '%s'", pseudoref);
-		if (hashcmp(actual_old_sha1, old_sha1)) {
+		if (oidcmp(&actual_old_oid, old_oid)) {
 			warning("Unexpected sha1 when deleting %s", pseudoref);
 			rollback_lock_file(&lock);
 			return -1;
@@ -655,7 +655,7 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1
 
 int refs_delete_ref(struct ref_store *refs, const char *msg,
 		    const char *refname,
-		    const unsigned char *old_sha1,
+		    const struct object_id *old_oid,
 		    unsigned int flags)
 {
 	struct ref_transaction *transaction;
@@ -663,12 +663,13 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
 
 	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
 		assert(refs == get_main_ref_store());
-		return delete_pseudoref(refname, old_sha1);
+		return delete_pseudoref(refname, old_oid);
 	}
 
 	transaction = ref_store_transaction_begin(refs, &err);
 	if (!transaction ||
-	    ref_transaction_delete(transaction, refname, old_sha1,
+	    ref_transaction_delete(transaction, refname,
+				   old_oid ? old_oid->hash : NULL,
 				   flags, msg, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		error("%s", err.buf);
@@ -682,10 +683,10 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
 }
 
 int delete_ref(const char *msg, const char *refname,
-	       const unsigned char *old_sha1, unsigned int flags)
+	       const struct object_id *old_oid, unsigned int flags)
 {
 	return refs_delete_ref(get_main_ref_store(), msg, refname,
-			       old_sha1, flags);
+			       old_oid, flags);
 }
 
 int copy_reflog_msg(char *buf, const char *msg)
diff --git a/refs.h b/refs.h
index e1c5803f9a..07e9907b31 100644
--- a/refs.h
+++ b/refs.h
@@ -371,19 +371,19 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname);
 int reflog_exists(const char *refname);
 
 /*
- * Delete the specified reference. If old_sha1 is non-NULL, then
+ * Delete the specified reference. If old_oid is non-NULL, then
  * verify that the current value of the reference is old_sha1 before
- * deleting it. If old_sha1 is NULL, delete the reference if it
- * exists, regardless of its old value. It is an error for old_sha1 to
- * be NULL_SHA1. msg and flags are passed through to
+ * deleting it. If old_oid is NULL, delete the reference if it
+ * exists, regardless of its old value. It is an error for old_oid to
+ * be null_oid. msg and flags are passed through to
  * ref_transaction_delete().
  */
 int refs_delete_ref(struct ref_store *refs, const char *msg,
 		    const char *refname,
-		    const unsigned char *old_sha1,
+		    const struct object_id *old_oid,
 		    unsigned int flags);
 int delete_ref(const char *msg, const char *refname,
-	       const unsigned char *old_sha1, unsigned int flags);
+	       const struct object_id *old_oid, unsigned int flags);
 
 /*
  * Delete the specified references. If there are any problems, emit
diff --git a/refs/files-backend.c b/refs/files-backend.c
index e3968d4f7c..0c641f0ad0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1308,7 +1308,7 @@ static int files_rename_ref(struct ref_store *ref_store,
 	}
 
 	if (refs_delete_ref(&refs->base, logmsg, oldrefname,
-			    orig_oid.hash, REF_NODEREF)) {
+			    &orig_oid, REF_NODEREF)) {
 		error("unable to delete old %s", oldrefname);
 		goto rollback;
 	}
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 05d8c4d8af..4624238641 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -218,12 +218,12 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv)
 	const char *refname = notnull(*argv++, "refname");
 	const char *sha1_buf = notnull(*argv++, "old-sha1");
 	unsigned int flags = arg_flags(*argv++, "flags");
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 
-	if (get_sha1_hex(sha1_buf, old_sha1))
+	if (get_oid_hex(sha1_buf, &old_oid))
 		die("not sha-1");
 
-	return refs_delete_ref(refs, msg, refname, old_sha1, flags);
+	return refs_delete_ref(refs, msg, refname, &old_oid, flags);
 }
 
 static int cmd_update_ref(struct ref_store *refs, const char **argv)
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (2 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 22:57   ` Jonathan Nieder
  2017-10-11  6:33   ` Michael Haggerty
  2017-10-09  1:11 ` [PATCH v2 05/24] refs: update ref transactions " brian m. carlson
                   ` (22 subsequent siblings)
  26 siblings, 2 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert update_ref, refs_update_ref, and write_pseudoref to use struct
object_id.  Update the existing callers as well.  Remove update_ref_oid,
as it is no longer needed.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 bisect.c                  |  5 +++--
 builtin/am.c              | 14 +++++++-------
 builtin/checkout.c        |  3 +--
 builtin/clone.c           | 14 +++++++-------
 builtin/merge.c           | 13 ++++++-------
 builtin/notes.c           | 10 +++++-----
 builtin/pull.c            |  2 +-
 builtin/reset.c           |  4 ++--
 builtin/update-ref.c      |  2 +-
 notes-cache.c             |  2 +-
 notes-utils.c             |  2 +-
 refs.c                    | 40 ++++++++++++++++------------------------
 refs.h                    |  5 +----
 sequencer.c               |  9 +++------
 t/helper/test-ref-store.c | 10 +++++-----
 transport-helper.c        |  3 ++-
 transport.c               |  4 ++--
 17 files changed, 64 insertions(+), 78 deletions(-)

diff --git a/bisect.c b/bisect.c
index 96beeb5d13..c09f7bbbcb 100644
--- a/bisect.c
+++ b/bisect.c
@@ -685,11 +685,12 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
 	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 
 	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
-	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
 	argv_checkout[2] = bisect_rev_hex;
 	if (no_checkout) {
-		update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
+			   UPDATE_REFS_DIE_ON_ERR);
 	} else {
 		int res;
 		res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
diff --git a/builtin/am.c b/builtin/am.c
index d7513f5375..32120f42df 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1068,8 +1068,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
 	if (!get_oid("HEAD", &curr_head)) {
 		write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
 		if (!state->rebasing)
-			update_ref_oid("am", "ORIG_HEAD", &curr_head, NULL, 0,
-					UPDATE_REFS_DIE_ON_ERR);
+			update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
+				   UPDATE_REFS_DIE_ON_ERR);
 	} else {
 		write_state_text(state, "abort-safety", "");
 		if (!state->rebasing)
@@ -1686,8 +1686,8 @@ static void do_commit(const struct am_state *state)
 	strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
 			state->msg);
 
-	update_ref_oid(sb.buf, "HEAD", &commit, old_oid, 0,
-			UPDATE_REFS_DIE_ON_ERR);
+	update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
+		   UPDATE_REFS_DIE_ON_ERR);
 
 	if (state->rebasing) {
 		FILE *fp = xfopen(am_path(state, "rewritten"), "a");
@@ -2147,9 +2147,9 @@ static void am_abort(struct am_state *state)
 	clean_index(&curr_head, &orig_head);
 
 	if (has_orig_head)
-		update_ref_oid("am --abort", "HEAD", &orig_head,
-				has_curr_head ? &curr_head : NULL, 0,
-				UPDATE_REFS_DIE_ON_ERR);
+		update_ref("am --abort", "HEAD", &orig_head,
+			   has_curr_head ? &curr_head : NULL, 0,
+			   UPDATE_REFS_DIE_ON_ERR);
 	else if (curr_branch)
 		delete_ref(NULL, curr_branch, NULL, REF_NODEREF);
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 3345a0d16f..fd0dec401e 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -664,8 +664,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 	if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
 		/* Nothing to do. */
 	} else if (opts->force_detach || !new->path) {	/* No longer on any branch. */
-		update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
-			   REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
 		if (!opts->quiet) {
 			if (old->path &&
 			    advice_detached_head && !opts->force_detach)
diff --git a/builtin/clone.c b/builtin/clone.c
index dbddd98f80..4135621aa3 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -610,8 +610,8 @@ static void write_followtags(const struct ref *refs, const char *msg)
 			continue;
 		if (!has_object_file(&ref->old_oid))
 			continue;
-		update_ref(msg, ref->name, ref->old_oid.hash,
-			   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
+			   UPDATE_REFS_DIE_ON_ERR);
 	}
 }
 
@@ -682,23 +682,23 @@ static void update_head(const struct ref *our, const struct ref *remote,
 		if (create_symref("HEAD", our->name, NULL) < 0)
 			die(_("unable to update HEAD"));
 		if (!option_bare) {
-			update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
+			update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
 				   UPDATE_REFS_DIE_ON_ERR);
 			install_branch_config(0, head, option_origin, our->name);
 		}
 	} else if (our) {
 		struct commit *c = lookup_commit_reference(&our->old_oid);
 		/* --branch specifies a non-branch (i.e. tags), detach HEAD */
-		update_ref(msg, "HEAD", c->object.oid.hash,
-			   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NODEREF,
+			   UPDATE_REFS_DIE_ON_ERR);
 	} else if (remote) {
 		/*
 		 * We know remote HEAD points to a non-branch, or
 		 * HEAD points to a branch but we don't know which one.
 		 * Detach HEAD in all these cases.
 		 */
-		update_ref(msg, "HEAD", remote->old_oid.hash,
-			   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NODEREF,
+			   UPDATE_REFS_DIE_ON_ERR);
 	}
 }
 
diff --git a/builtin/merge.c b/builtin/merge.c
index ab5ffe85e8..99d4b873f0 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -405,9 +405,8 @@ static void finish(struct commit *head_commit,
 			printf(_("No merge message -- not updating HEAD\n"));
 		else {
 			const char *argv_gc_auto[] = { "gc", "--auto", NULL };
-			update_ref(reflog_message.buf, "HEAD",
-				new_head->hash, head->hash, 0,
-				UPDATE_REFS_DIE_ON_ERR);
+			update_ref(reflog_message.buf, "HEAD", new_head, head,
+				   0, UPDATE_REFS_DIE_ON_ERR);
 			/*
 			 * We ignore errors in 'gc --auto', since the
 			 * user should see them.
@@ -1261,8 +1260,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			die(_("Can merge only exactly one commit into empty head"));
 		remote_head_oid = &remoteheads->item->object.oid;
 		read_empty(remote_head_oid->hash, 0);
-		update_ref("initial pull", "HEAD", remote_head_oid->hash,
-			   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+		update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
+			   UPDATE_REFS_DIE_ON_ERR);
 		goto done;
 	}
 
@@ -1357,8 +1356,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		free(list);
 	}
 
-	update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.oid.hash,
-		   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+	update_ref("updating ORIG_HEAD", "ORIG_HEAD",
+		   &head_commit->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
 	if (remoteheads && !common) {
 		/* No common ancestors found. */
diff --git a/builtin/notes.c b/builtin/notes.c
index 8e54f2d146..8276af419b 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -736,8 +736,8 @@ static int merge_commit(struct notes_merge_options *o)
 	format_commit_message(partial, "%s", &msg, &pretty_ctx);
 	strbuf_trim(&msg);
 	strbuf_insert(&msg, 0, "notes: ", 7);
-	update_ref(msg.buf, o->local_ref, oid.hash,
-		   is_null_oid(&parent_oid) ? NULL : parent_oid.hash,
+	update_ref(msg.buf, o->local_ref, &oid,
+		   is_null_oid(&parent_oid) ? NULL : &parent_oid,
 		   0, UPDATE_REFS_DIE_ON_ERR);
 
 	free_notes(t);
@@ -850,12 +850,12 @@ static int merge(int argc, const char **argv, const char *prefix)
 
 	if (result >= 0) /* Merge resulted (trivially) in result_oid */
 		/* Update default notes ref with new commit */
-		update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL,
-			   0, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(msg.buf, default_notes_ref(), &result_oid, NULL, 0,
+			   UPDATE_REFS_DIE_ON_ERR);
 	else { /* Merge has unresolved conflicts */
 		const struct worktree *wt;
 		/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
-		update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_oid.hash, NULL,
+		update_ref(msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL,
 			   0, UPDATE_REFS_DIE_ON_ERR);
 		/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
 		wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
diff --git a/builtin/pull.c b/builtin/pull.c
index 6f772e8a22..9b2d67fe43 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -544,7 +544,7 @@ static int pull_into_void(const struct object_id *merge_head,
 	if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
 		return 1;
 
-	if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
+	if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
 		return 1;
 
 	return 0;
diff --git a/builtin/reset.c b/builtin/reset.c
index 5f3632e05b..d4003f76ab 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -266,12 +266,12 @@ static int reset_refs(const char *rev, const struct object_id *oid)
 	if (!get_oid("HEAD", &oid_orig)) {
 		orig = &oid_orig;
 		set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
-		update_ref_oid(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
+		update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
 			   UPDATE_REFS_MSG_ON_ERR);
 	} else if (old_orig)
 		delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
 	set_reflog_message(&msg, "updating HEAD", rev);
-	update_ref_status = update_ref_oid(msg.buf, "HEAD", oid, orig, 0,
+	update_ref_status = update_ref(msg.buf, "HEAD", oid, orig, 0,
 				       UPDATE_REFS_MSG_ON_ERR);
 	strbuf_release(&msg);
 	return update_ref_status;
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index bf0f80ebae..f491cf1a92 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -437,7 +437,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 				  (oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
 				  flags);
 	else
-		return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
+		return update_ref(msg, refname, &oid, oldval ? &oldoid : NULL,
 				  flags | create_reflog_flag,
 				  UPDATE_REFS_DIE_ON_ERR);
 }
diff --git a/notes-cache.c b/notes-cache.c
index 29b4cede5f..a1969ab052 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -59,7 +59,7 @@ int notes_cache_write(struct notes_cache *c)
 	if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
 			commit_oid.hash, NULL, NULL) < 0)
 		return -1;
-	if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash,
+	if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
 		       NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
 		return -1;
 
diff --git a/notes-utils.c b/notes-utils.c
index 9765deb41a..3a7008948c 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -49,7 +49,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
 
 	create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
 	strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
-	update_ref(buf.buf, t->update_ref, commit_oid.hash, NULL, 0,
+	update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
 		   UPDATE_REFS_DIE_ON_ERR);
 
 	strbuf_release(&buf);
diff --git a/refs.c b/refs.c
index 0a5b68d6fb..51942df7b3 100644
--- a/refs.c
+++ b/refs.c
@@ -574,8 +574,8 @@ long get_files_ref_lock_timeout_ms(void)
 	return timeout_ms;
 }
 
-static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
-			   const unsigned char *old_sha1, struct strbuf *err)
+static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
+			   const struct object_id *old_oid, struct strbuf *err)
 {
 	const char *filename;
 	int fd;
@@ -583,7 +583,7 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
 	struct strbuf buf = STRBUF_INIT;
 	int ret = -1;
 
-	strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1));
+	strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
 
 	filename = git_path("%s", pseudoref);
 	fd = hold_lock_file_for_update_timeout(&lock, filename,
@@ -595,12 +595,12 @@ static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
 		goto done;
 	}
 
-	if (old_sha1) {
-		unsigned char actual_old_sha1[20];
+	if (old_oid) {
+		struct object_id actual_old_oid;
 
-		if (read_ref(pseudoref, actual_old_sha1))
+		if (read_ref(pseudoref, actual_old_oid.hash))
 			die("could not read ref '%s'", pseudoref);
-		if (hashcmp(actual_old_sha1, old_sha1)) {
+		if (oidcmp(&actual_old_oid, old_oid)) {
 			strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
 			rollback_lock_file(&lock);
 			goto done;
@@ -985,17 +985,9 @@ int ref_transaction_verify(struct ref_transaction *transaction,
 				      flags, NULL, err);
 }
 
-int update_ref_oid(const char *msg, const char *refname,
-	       const struct object_id *new_oid, const struct object_id *old_oid,
-	       unsigned int flags, enum action_on_err onerr)
-{
-	return update_ref(msg, refname, new_oid ? new_oid->hash : NULL,
-		old_oid ? old_oid->hash : NULL, flags, onerr);
-}
-
 int refs_update_ref(struct ref_store *refs, const char *msg,
-		    const char *refname, const unsigned char *new_sha1,
-		    const unsigned char *old_sha1, unsigned int flags,
+		    const char *refname, const struct object_id *new_oid,
+		    const struct object_id *old_oid, unsigned int flags,
 		    enum action_on_err onerr)
 {
 	struct ref_transaction *t = NULL;
@@ -1003,12 +995,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
 	int ret = 0;
 
 	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
-		assert(refs == get_main_ref_store());
-		ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
+		ret = write_pseudoref(refname, new_oid, old_oid, &err);
 	} else {
 		t = ref_store_transaction_begin(refs, &err);
 		if (!t ||
-		    ref_transaction_update(t, refname, new_sha1, old_sha1,
+		    ref_transaction_update(t, refname, new_oid ? new_oid->hash : NULL,
+					   old_oid ? old_oid->hash : NULL,
 					   flags, msg, &err) ||
 		    ref_transaction_commit(t, &err)) {
 			ret = 1;
@@ -1038,12 +1030,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
 }
 
 int update_ref(const char *msg, const char *refname,
-	       const unsigned char *new_sha1,
-	       const unsigned char *old_sha1,
+	       const struct object_id *new_oid,
+	       const struct object_id *old_oid,
 	       unsigned int flags, enum action_on_err onerr)
 {
-	return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1,
-			       old_sha1, flags, onerr);
+	return refs_update_ref(get_main_ref_store(), msg, refname, new_oid,
+			       old_oid, flags, onerr);
 }
 
 char *shorten_unambiguous_ref(const char *refname, int strict)
diff --git a/refs.h b/refs.h
index 07e9907b31..369614d392 100644
--- a/refs.h
+++ b/refs.h
@@ -636,12 +636,9 @@ void ref_transaction_free(struct ref_transaction *transaction);
  * argument.
  */
 int refs_update_ref(struct ref_store *refs, const char *msg, const char *refname,
-		    const unsigned char *new_sha1, const unsigned char *old_sha1,
+		    const struct object_id *new_oid, const struct object_id *old_oid,
 		    unsigned int flags, enum action_on_err onerr);
 int update_ref(const char *msg, const char *refname,
-	       const unsigned char *new_sha1, const unsigned char *old_sha1,
-	       unsigned int flags, enum action_on_err onerr);
-int update_ref_oid(const char *msg, const char *refname,
 	       const struct object_id *new_oid, const struct object_id *old_oid,
 	       unsigned int flags, enum action_on_err onerr);
 
diff --git a/sequencer.c b/sequencer.c
index 60636ce54b..b349474bd3 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1114,12 +1114,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 	 * write it at all.
 	 */
 	if (command == TODO_PICK && !opts->no_commit && (res == 0 || res == 1) &&
-	    update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.oid.hash, NULL,
-		       REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
+	    update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
 		res = -1;
 	if (command == TODO_REVERT && ((opts->no_commit && res == 0) || res == 1) &&
-	    update_ref(NULL, "REVERT_HEAD", commit->object.oid.hash, NULL,
-		       REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
+	    update_ref(NULL, "REVERT_HEAD", &commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
 		res = -1;
 
 	if (res) {
@@ -2123,8 +2121,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 			}
 			msg = reflog_message(opts, "finish", "%s onto %s",
 				head_ref.buf, buf.buf);
-			if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
-					REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
+			if (update_ref(msg, head_ref.buf, &head, &orig, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
 				res = error(_("could not update %s"),
 					head_ref.buf);
 				goto cleanup_head_ref;
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4624238641..af8dba9560 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -233,15 +233,15 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
 	const char *new_sha1_buf = notnull(*argv++, "old-sha1");
 	const char *old_sha1_buf = notnull(*argv++, "old-sha1");
 	unsigned int flags = arg_flags(*argv++, "flags");
-	unsigned char old_sha1[20];
-	unsigned char new_sha1[20];
+	struct object_id old_oid;
+	struct object_id new_oid;
 
-	if (get_sha1_hex(old_sha1_buf, old_sha1) ||
-	    get_sha1_hex(new_sha1_buf, new_sha1))
+	if (get_oid_hex(old_sha1_buf, &old_oid) ||
+	    get_oid_hex(new_sha1_buf, &new_oid))
 		die("not sha-1");
 
 	return refs_update_ref(refs, msg, refname,
-			       new_sha1, old_sha1,
+			       &new_oid, &old_oid,
 			       flags, UPDATE_REFS_DIE_ON_ERR);
 }
 
diff --git a/transport-helper.c b/transport-helper.c
index c948d5215c..f183601261 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -795,7 +795,8 @@ static int push_update_refs_status(struct helper_data *data,
 		private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
 		if (!private)
 			continue;
-		update_ref("update by helper", private, ref->new_oid.hash, NULL, 0, 0);
+		update_ref("update by helper", private, &ref->new_oid, NULL,
+			   0, 0);
 		free(private);
 	}
 	strbuf_release(&buf);
diff --git a/transport.c b/transport.c
index fb8c01e57a..09bd06e6e5 100644
--- a/transport.c
+++ b/transport.c
@@ -305,8 +305,8 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
 		if (ref->deletion) {
 			delete_ref(NULL, rs.dst, NULL, 0);
 		} else
-			update_ref("update by push", rs.dst,
-					ref->new_oid.hash, NULL, 0, 0);
+			update_ref("update by push", rs.dst, &ref->new_oid,
+				   NULL, 0, 0);
 		free(rs.dst);
 	}
 }
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 05/24] refs: update ref transactions to use struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (3 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 23:13   ` Jonathan Nieder
  2017-10-11  6:58   ` Michael Haggerty
  2017-10-09  1:11 ` [PATCH v2 06/24] Convert check_connected " brian m. carlson
                   ` (21 subsequent siblings)
  26 siblings, 2 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Update the ref transaction code to use struct object_id.  Remove one
NULL pointer check which was previously inserted around a dereference;
since we now pass a pointer to struct object_id directly through, the
code we're calling handles this for us.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 branch.c               |  2 +-
 builtin/clone.c        |  2 +-
 builtin/commit.c       |  4 ++--
 builtin/fetch.c        |  4 ++--
 builtin/receive-pack.c |  4 ++--
 builtin/replace.c      |  2 +-
 builtin/tag.c          |  2 +-
 builtin/update-ref.c   |  8 ++++----
 fast-import.c          |  4 ++--
 refs.c                 | 44 +++++++++++++++++++++-----------------------
 refs.h                 | 24 ++++++++++++------------
 refs/files-backend.c   | 12 ++++++------
 refs/refs-internal.h   |  4 ++--
 sequencer.c            |  2 +-
 walker.c               |  2 +-
 15 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/branch.c b/branch.c
index 4377ce2fb1..45029ea142 100644
--- a/branch.c
+++ b/branch.c
@@ -305,7 +305,7 @@ void create_branch(const char *name, const char *start_name,
 		transaction = ref_transaction_begin(&err);
 		if (!transaction ||
 		    ref_transaction_update(transaction, ref.buf,
-					   oid.hash, forcing ? NULL : null_sha1,
+					   &oid, forcing ? NULL : &null_oid,
 					   0, msg, &err) ||
 		    ref_transaction_commit(transaction, &err))
 			die("%s", err.buf);
diff --git a/builtin/clone.c b/builtin/clone.c
index 4135621aa3..665a0e2673 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -588,7 +588,7 @@ static void write_remote_refs(const struct ref *local_refs)
 	for (r = local_refs; r; r = r->next) {
 		if (!r->peer_ref)
 			continue;
-		if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash,
+		if (ref_transaction_create(t, r->peer_ref->name, &r->old_oid,
 					   0, NULL, &err))
 			die("%s", err.buf);
 	}
diff --git a/builtin/commit.c b/builtin/commit.c
index 0f8ddb6866..d5fbf404f4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1785,9 +1785,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
-	    ref_transaction_update(transaction, "HEAD", oid.hash,
+	    ref_transaction_update(transaction, "HEAD", &oid,
 				   current_head
-				   ? current_head->object.oid.hash : null_sha1,
+				   ? &current_head->object.oid : &null_oid,
 				   0, sb.buf, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		rollback_index_files();
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 225c734924..859be91d6c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -457,8 +457,8 @@ static int s_update_ref(const char *action,
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
 	    ref_transaction_update(transaction, ref->name,
-				   ref->new_oid.hash,
-				   check_old ? ref->old_oid.hash : NULL,
+				   &ref->new_oid,
+				   check_old ? &ref->old_oid : NULL,
 				   0, msg, &err))
 		goto fail;
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 29a0f3b75f..39defd4e3c 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1139,7 +1139,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 		}
 		if (ref_transaction_delete(transaction,
 					   namespaced_name,
-					   old_oid ? old_oid->hash : NULL,
+					   old_oid,
 					   0, "push", &err)) {
 			rp_error("%s", err.buf);
 			strbuf_release(&err);
@@ -1156,7 +1156,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 
 		if (ref_transaction_update(transaction,
 					   namespaced_name,
-					   new_oid->hash, old_oid->hash,
+					   new_oid, old_oid,
 					   0, "push",
 					   &err)) {
 			rp_error("%s", err.buf);
diff --git a/builtin/replace.c b/builtin/replace.c
index 2854eaa0f3..3099e55307 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -175,7 +175,7 @@ static int replace_object_oid(const char *object_ref,
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
-	    ref_transaction_update(transaction, ref.buf, repl->hash, prev.hash,
+	    ref_transaction_update(transaction, ref.buf, repl, &prev,
 				   0, NULL, &err) ||
 	    ref_transaction_commit(transaction, &err))
 		die("%s", err.buf);
diff --git a/builtin/tag.c b/builtin/tag.c
index 46ff4ca736..2ededc3fb1 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -543,7 +543,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
-	    ref_transaction_update(transaction, ref.buf, object.hash, prev.hash,
+	    ref_transaction_update(transaction, ref.buf, &object, &prev,
 				   create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
 				   reflog_msg.buf, &err) ||
 	    ref_transaction_commit(transaction, &err))
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index f491cf1a92..cf1552b478 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -200,7 +200,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
 		die("update %s: extra input: %s", refname, next);
 
 	if (ref_transaction_update(transaction, refname,
-				   new_oid.hash, have_old ? old_oid.hash : NULL,
+				   &new_oid, have_old ? &old_oid : NULL,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -232,7 +232,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
 	if (*next != line_termination)
 		die("create %s: extra input: %s", refname, next);
 
-	if (ref_transaction_create(transaction, refname, new_oid.hash,
+	if (ref_transaction_create(transaction, refname, &new_oid,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -269,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
 		die("delete %s: extra input: %s", refname, next);
 
 	if (ref_transaction_delete(transaction, refname,
-				   have_old ? old_oid.hash : NULL,
+				   have_old ? &old_oid : NULL,
 				   update_flags, msg, &err))
 		die("%s", err.buf);
 
@@ -298,7 +298,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
 	if (*next != line_termination)
 		die("verify %s: extra input: %s", refname, next);
 
-	if (ref_transaction_verify(transaction, refname, old_oid.hash,
+	if (ref_transaction_verify(transaction, refname, &old_oid,
 				   update_flags, &err))
 		die("%s", err.buf);
 
diff --git a/fast-import.c b/fast-import.c
index 35bf671f12..2d2d0d98f0 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1778,7 +1778,7 @@ static int update_branch(struct branch *b)
 	}
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
-	    ref_transaction_update(transaction, b->name, b->oid.hash, old_oid.hash,
+	    ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
 				   0, msg, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		ref_transaction_free(transaction);
@@ -1820,7 +1820,7 @@ static void dump_tags(void)
 		strbuf_addf(&ref_name, "refs/tags/%s", t->name);
 
 		if (ref_transaction_update(transaction, ref_name.buf,
-					   t->oid.hash, NULL, 0, msg, &err)) {
+					   &t->oid, NULL, 0, msg, &err)) {
 			failure |= error("%s", err.buf);
 			goto cleanup;
 		}
diff --git a/refs.c b/refs.c
index 51942df7b3..1e6dec4046 100644
--- a/refs.c
+++ b/refs.c
@@ -668,8 +668,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
 
 	transaction = ref_store_transaction_begin(refs, &err);
 	if (!transaction ||
-	    ref_transaction_delete(transaction, refname,
-				   old_oid ? old_oid->hash : NULL,
+	    ref_transaction_delete(transaction, refname, old_oid,
 				   flags, msg, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		error("%s", err.buf);
@@ -895,8 +894,8 @@ void ref_transaction_free(struct ref_transaction *transaction)
 struct ref_update *ref_transaction_add_update(
 		struct ref_transaction *transaction,
 		const char *refname, unsigned int flags,
-		const unsigned char *new_sha1,
-		const unsigned char *old_sha1,
+		const struct object_id *new_oid,
+		const struct object_id *old_oid,
 		const char *msg)
 {
 	struct ref_update *update;
@@ -914,23 +913,23 @@ struct ref_update *ref_transaction_add_update(
 	update->flags = flags;
 
 	if (flags & REF_HAVE_NEW)
-		hashcpy(update->new_oid.hash, new_sha1);
+		oidcpy(&update->new_oid, new_oid);
 	if (flags & REF_HAVE_OLD)
-		hashcpy(update->old_oid.hash, old_sha1);
+		oidcpy(&update->old_oid, old_oid);
 	update->msg = xstrdup_or_null(msg);
 	return update;
 }
 
 int ref_transaction_update(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *new_sha1,
-			   const unsigned char *old_sha1,
+			   const struct object_id *new_oid,
+			   const struct object_id *old_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err)
 {
 	assert(err);
 
-	if ((new_sha1 && !is_null_sha1(new_sha1)) ?
+	if ((new_oid && !is_null_oid(new_oid)) ?
 	    check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
 	    !refname_is_safe(refname)) {
 		strbuf_addf(err, "refusing to update ref with bad name '%s'",
@@ -940,48 +939,48 @@ int ref_transaction_update(struct ref_transaction *transaction,
 
 	flags &= REF_TRANSACTION_UPDATE_ALLOWED_FLAGS;
 
-	flags |= (new_sha1 ? REF_HAVE_NEW : 0) | (old_sha1 ? REF_HAVE_OLD : 0);
+	flags |= (new_oid ? REF_HAVE_NEW : 0) | (old_oid ? REF_HAVE_OLD : 0);
 
 	ref_transaction_add_update(transaction, refname, flags,
-				   new_sha1, old_sha1, msg);
+				   new_oid, old_oid, msg);
 	return 0;
 }
 
 int ref_transaction_create(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *new_sha1,
+			   const struct object_id *new_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err)
 {
-	if (!new_sha1 || is_null_sha1(new_sha1))
+	if (!new_oid || is_null_oid(new_oid))
 		die("BUG: create called without valid new_sha1");
-	return ref_transaction_update(transaction, refname, new_sha1,
-				      null_sha1, flags, msg, err);
+	return ref_transaction_update(transaction, refname, new_oid,
+				      &null_oid, flags, msg, err);
 }
 
 int ref_transaction_delete(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *old_sha1,
+			   const struct object_id *old_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err)
 {
-	if (old_sha1 && is_null_sha1(old_sha1))
+	if (old_oid && is_null_oid(old_oid))
 		die("BUG: delete called with old_sha1 set to zeros");
 	return ref_transaction_update(transaction, refname,
-				      null_sha1, old_sha1,
+				      &null_oid, old_oid,
 				      flags, msg, err);
 }
 
 int ref_transaction_verify(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *old_sha1,
+			   const struct object_id *old_oid,
 			   unsigned int flags,
 			   struct strbuf *err)
 {
-	if (!old_sha1)
+	if (!old_oid)
 		die("BUG: verify called with old_sha1 set to NULL");
 	return ref_transaction_update(transaction, refname,
-				      NULL, old_sha1,
+				      NULL, old_oid,
 				      flags, NULL, err);
 }
 
@@ -999,8 +998,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
 	} else {
 		t = ref_store_transaction_begin(refs, &err);
 		if (!t ||
-		    ref_transaction_update(t, refname, new_oid ? new_oid->hash : NULL,
-					   old_oid ? old_oid->hash : NULL,
+		    ref_transaction_update(t, refname, new_oid, old_oid,
 					   flags, msg, &err) ||
 		    ref_transaction_commit(t, &err)) {
 			ret = 1;
diff --git a/refs.h b/refs.h
index 369614d392..543dcc5956 100644
--- a/refs.h
+++ b/refs.h
@@ -519,15 +519,15 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
  */
 int ref_transaction_update(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *new_sha1,
-			   const unsigned char *old_sha1,
+			   const struct object_id *new_oid,
+			   const struct object_id *old_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err);
 
 /*
- * Add a reference creation to transaction. new_sha1 is the value that
+ * Add a reference creation to transaction. new_oid is the value that
  * the reference should have after the update; it must not be
- * null_sha1. It is verified that the reference does not exist
+ * null_oid. It is verified that the reference does not exist
  * already.
  *
  * See the above comment "Reference transaction updates" for more
@@ -535,35 +535,35 @@ int ref_transaction_update(struct ref_transaction *transaction,
  */
 int ref_transaction_create(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *new_sha1,
+			   const struct object_id *new_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err);
 
 /*
- * Add a reference deletion to transaction. If old_sha1 is non-NULL,
+ * Add a reference deletion to transaction. If old_oid is non-NULL,
  * then it holds the value that the reference should have had before
- * the update (which must not be null_sha1).
+ * the update (which must not be null_oid).
  *
  * See the above comment "Reference transaction updates" for more
  * information.
  */
 int ref_transaction_delete(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *old_sha1,
+			   const struct object_id *old_oid,
 			   unsigned int flags, const char *msg,
 			   struct strbuf *err);
 
 /*
- * Verify, within a transaction, that refname has the value old_sha1,
- * or, if old_sha1 is null_sha1, then verify that the reference
- * doesn't exist. old_sha1 must be non-NULL.
+ * Verify, within a transaction, that refname has the value old_oid,
+ * or, if old_oid is null_oid, then verify that the reference
+ * doesn't exist. old_oid must be non-NULL.
  *
  * See the above comment "Reference transaction updates" for more
  * information.
  */
 int ref_transaction_verify(struct ref_transaction *transaction,
 			   const char *refname,
-			   const unsigned char *old_sha1,
+			   const struct object_id *old_oid,
 			   unsigned int flags,
 			   struct strbuf *err);
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0c641f0ad0..46dbcda6a6 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1029,7 +1029,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
 
 	transaction = ref_store_transaction_begin(&refs->base, &err);
 	if (!transaction ||
-	    ref_transaction_delete(transaction, r->name, r->oid.hash,
+	    ref_transaction_delete(transaction, r->name, &r->oid,
 				   REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		ref_transaction_free(transaction);
@@ -1114,7 +1114,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
 		 * packed-refs transaction:
 		 */
 		if (ref_transaction_update(transaction, iter->refname,
-					   iter->oid->hash, NULL,
+					   iter->oid, NULL,
 					   REF_NODEREF, NULL, &err))
 			die("failure preparing to create packed reference %s: %s",
 			    iter->refname, err.buf);
@@ -2153,7 +2153,7 @@ static int split_head_update(struct ref_update *update,
 	new_update = ref_transaction_add_update(
 			transaction, "HEAD",
 			update->flags | REF_LOG_ONLY | REF_NODEREF,
-			update->new_oid.hash, update->old_oid.hash,
+			&update->new_oid, &update->old_oid,
 			update->msg);
 
 	/*
@@ -2217,7 +2217,7 @@ static int split_symref_update(struct files_ref_store *refs,
 
 	new_update = ref_transaction_add_update(
 			transaction, referent, new_flags,
-			update->new_oid.hash, update->old_oid.hash,
+			&update->new_oid, &update->old_oid,
 			update->msg);
 
 	new_update->parent_update = update;
@@ -2600,7 +2600,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 			ref_transaction_add_update(
 					packed_transaction, update->refname,
 					update->flags & ~REF_HAVE_OLD,
-					update->new_oid.hash, update->old_oid.hash,
+					&update->new_oid, &update->old_oid,
 					NULL);
 		}
 	}
@@ -2853,7 +2853,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
 		 */
 		ref_transaction_add_update(packed_transaction, update->refname,
 					   update->flags & ~REF_HAVE_OLD,
-					   update->new_oid.hash, update->old_oid.hash,
+					   &update->new_oid, &update->old_oid,
 					   NULL);
 	}
 
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index d7d344de73..6636a13a62 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -202,8 +202,8 @@ int ref_update_reject_duplicates(struct string_list *refnames,
 struct ref_update *ref_transaction_add_update(
 		struct ref_transaction *transaction,
 		const char *refname, unsigned int flags,
-		const unsigned char *new_sha1,
-		const unsigned char *old_sha1,
+		const struct object_id *new_oid,
+		const struct object_id *old_oid,
 		const char *msg);
 
 /*
diff --git a/sequencer.c b/sequencer.c
index b349474bd3..43a6f14eb3 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -392,7 +392,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
 	    ref_transaction_update(transaction, "HEAD",
-				   to->hash, unborn ? null_sha1 : from->hash,
+				   to, unborn ? &null_oid : from,
 				   0, sb.buf, &err) ||
 	    ref_transaction_commit(transaction, &err)) {
 		ref_transaction_free(transaction);
diff --git a/walker.c b/walker.c
index 2d83254bc0..5d4d3733f7 100644
--- a/walker.c
+++ b/walker.c
@@ -304,7 +304,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
 		strbuf_reset(&refname);
 		strbuf_addf(&refname, "refs/%s", write_ref[i]);
 		if (ref_transaction_update(transaction, refname.buf,
-					   oids[i].hash, NULL, 0,
+					   oids + i, NULL, 0,
 					   msg ? msg : "fetch (unknown)",
 					   &err)) {
 			error("%s", err.buf);
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 06/24] Convert check_connected to use struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (4 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 05/24] refs: update ref transactions " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 23:20   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to " brian m. carlson
                   ` (20 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert check_connected and the callbacks it takes to use struct
object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/clone.c        |  4 ++--
 builtin/fetch.c        |  4 ++--
 builtin/receive-pack.c | 10 +++++-----
 connected.c            | 18 +++++++++---------
 connected.h            |  4 ++--
 5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 665a0e2673..5cd1b02d53 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -615,7 +615,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
 	}
 }
 
-static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
+static int iterate_ref_map(void *cb_data, struct object_id *oid)
 {
 	struct ref **rm = cb_data;
 	struct ref *ref = *rm;
@@ -630,7 +630,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
 	if (!ref)
 		return -1;
 
-	hashcpy(sha1, ref->old_oid.hash);
+	oidcpy(oid, &ref->old_oid);
 	*rm = ref->next;
 	return 0;
 }
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 859be91d6c..e705237fa9 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -727,7 +727,7 @@ static int update_local_ref(struct ref *ref,
 	}
 }
 
-static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
+static int iterate_ref_map(void *cb_data, struct object_id *oid)
 {
 	struct ref **rm = cb_data;
 	struct ref *ref = *rm;
@@ -737,7 +737,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
 	if (!ref)
 		return -1; /* end of the list */
 	*rm = ref->next;
-	hashcpy(sha1, ref->old_oid.hash);
+	oidcpy(oid, &ref->old_oid);
 	return 0;
 }
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 39defd4e3c..046b600b11 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -870,7 +870,7 @@ static void refuse_unconfigured_deny_delete_current(void)
 	rp_error("%s", _(refuse_unconfigured_deny_delete_current_msg));
 }
 
-static int command_singleton_iterator(void *cb_data, unsigned char sha1[20]);
+static int command_singleton_iterator(void *cb_data, struct object_id *oid);
 static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
 {
 	static struct lock_file shallow_lock;
@@ -1270,7 +1270,7 @@ static void check_aliased_updates(struct command *commands)
 	string_list_clear(&ref_list, 0);
 }
 
-static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
+static int command_singleton_iterator(void *cb_data, struct object_id *oid)
 {
 	struct command **cmd_list = cb_data;
 	struct command *cmd = *cmd_list;
@@ -1278,7 +1278,7 @@ static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
 	if (!cmd || is_null_oid(&cmd->new_oid))
 		return -1; /* end of list */
 	*cmd_list = NULL; /* this returns only one */
-	hashcpy(sha1, cmd->new_oid.hash);
+	oidcpy(oid, &cmd->new_oid);
 	return 0;
 }
 
@@ -1309,7 +1309,7 @@ struct iterate_data {
 	struct shallow_info *si;
 };
 
-static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
+static int iterate_receive_command_list(void *cb_data, struct object_id *oid)
 {
 	struct iterate_data *data = cb_data;
 	struct command **cmd_list = &data->cmds;
@@ -1320,7 +1320,7 @@ static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
 			/* to be checked in update_shallow_ref() */
 			continue;
 		if (!is_null_oid(&cmd->new_oid) && !cmd->skip_update) {
-			hashcpy(sha1, cmd->new_oid.hash);
+			oidcpy(oid, &cmd->new_oid);
 			*cmd_list = cmd->next;
 			return 0;
 		}
diff --git a/connected.c b/connected.c
index f416b05051..4a47f33270 100644
--- a/connected.c
+++ b/connected.c
@@ -16,13 +16,13 @@
  *
  * Returns 0 if everything is connected, non-zero otherwise.
  */
-int check_connected(sha1_iterate_fn fn, void *cb_data,
+int check_connected(oid_iterate_fn fn, void *cb_data,
 		    struct check_connected_options *opt)
 {
 	struct child_process rev_list = CHILD_PROCESS_INIT;
 	struct check_connected_options defaults = CHECK_CONNECTED_INIT;
-	char commit[41];
-	unsigned char sha1[20];
+	char commit[GIT_MAX_HEXSZ + 1];
+	struct object_id oid;
 	int err = 0;
 	struct packed_git *new_pack = NULL;
 	struct transport *transport;
@@ -32,7 +32,7 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
 		opt = &defaults;
 	transport = opt->transport;
 
-	if (fn(cb_data, sha1)) {
+	if (fn(cb_data, &oid)) {
 		if (opt->err_fd)
 			close(opt->err_fd);
 		return err;
@@ -77,7 +77,7 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
 
 	sigchain_push(SIGPIPE, SIG_IGN);
 
-	commit[40] = '\n';
+	commit[GIT_SHA1_HEXSZ] = '\n';
 	do {
 		/*
 		 * If index-pack already checked that:
@@ -87,17 +87,17 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
 		 * are sure the ref is good and not sending it to
 		 * rev-list for verification.
 		 */
-		if (new_pack && find_pack_entry_one(sha1, new_pack))
+		if (new_pack && find_pack_entry_one(oid.hash, new_pack))
 			continue;
 
-		memcpy(commit, sha1_to_hex(sha1), 40);
-		if (write_in_full(rev_list.in, commit, 41) < 0) {
+		memcpy(commit, oid_to_hex(&oid), GIT_SHA1_HEXSZ);
+		if (write_in_full(rev_list.in, commit, GIT_SHA1_HEXSZ + 1) < 0) {
 			if (errno != EPIPE && errno != EINVAL)
 				error_errno(_("failed write to rev-list"));
 			err = -1;
 			break;
 		}
-	} while (!fn(cb_data, sha1));
+	} while (!fn(cb_data, &oid));
 
 	if (close(rev_list.in))
 		err = error_errno(_("failed to close rev-list's stdin"));
diff --git a/connected.h b/connected.h
index 4ca325f79d..a53f03a61a 100644
--- a/connected.h
+++ b/connected.h
@@ -8,7 +8,7 @@ struct transport;
  * When called after returning the name for the last object, return -1
  * to signal EOF, otherwise return 0.
  */
-typedef int (*sha1_iterate_fn)(void *, unsigned char [20]);
+typedef int (*oid_iterate_fn)(void *, struct object_id *oid);
 
 /*
  * Named-arguments struct for check_connected. All arguments are
@@ -51,7 +51,7 @@ struct check_connected_options {
  *
  * If "opt" is NULL, behaves as if CHECK_CONNECTED_INIT was passed.
  */
-int check_connected(sha1_iterate_fn fn, void *cb_data,
+int check_connected(oid_iterate_fn fn, void *cb_data,
 		    struct check_connected_options *opt);
 
 #endif /* CONNECTED_H */
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (5 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 06/24] Convert check_connected " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09 23:36   ` Jonathan Nieder
  2017-10-10  1:16   ` Junio C Hamano
  2017-10-09  1:11 ` [PATCH v2 08/24] refs: convert read_ref and read_ref_full to " brian m. carlson
                   ` (19 subsequent siblings)
  26 siblings, 2 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

All of the callers already pass the hash member of struct object_id, so
update them to pass a pointer to the struct directly,

This transformation was done with an update to declaration and
definition and the following semantic patch:

@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3.hash, E4)
+ resolve_refdup(E1, E2, &E3, E4)

@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3->hash, E4)
+ resolve_refdup(E1, E2, E3, E4)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/am.c                | 2 +-
 builtin/branch.c            | 6 +++---
 builtin/checkout.c          | 4 ++--
 builtin/clone.c             | 2 +-
 builtin/fmt-merge-msg.c     | 2 +-
 builtin/merge.c             | 2 +-
 builtin/notes.c             | 2 +-
 builtin/receive-pack.c      | 2 +-
 builtin/show-branch.c       | 6 +++---
 builtin/submodule--helper.c | 2 +-
 ref-filter.c                | 4 ++--
 reflog-walk.c               | 4 ++--
 refs.c                      | 8 ++++----
 refs.h                      | 4 ++--
 refs/files-backend.c        | 2 +-
 submodule.c                 | 2 +-
 transport.c                 | 2 +-
 wt-status.c                 | 2 +-
 18 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 32120f42df..c9bb14a6c2 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2135,7 +2135,7 @@ static void am_abort(struct am_state *state)
 
 	am_rerere_clear();
 
-	curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
+	curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
 	has_curr_head = curr_branch && !is_null_oid(&curr_head);
 	if (!has_curr_head)
 		hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
diff --git a/builtin/branch.c b/builtin/branch.c
index 6031b74d68..75dadd3d93 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -124,7 +124,7 @@ static int branch_merged(int kind, const char *name,
 		if (upstream &&
 		    (reference_name = reference_name_to_free =
 		     resolve_refdup(upstream, RESOLVE_REF_READING,
-				    oid.hash, NULL)) != NULL)
+				    &oid, NULL)) != NULL)
 			reference_rev = lookup_commit_reference(&oid);
 	}
 	if (!reference_rev)
@@ -240,7 +240,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 					RESOLVE_REF_READING
 					| RESOLVE_REF_NO_RECURSE
 					| RESOLVE_REF_ALLOW_BAD_NAME,
-					oid.hash, &flags);
+					&oid, &flags);
 		if (!target) {
 			error(remote_branch
 			      ? _("remote-tracking branch '%s' not found.")
@@ -613,7 +613,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
 	track = git_branch_track;
 
-	head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
+	head = resolve_refdup("HEAD", 0, &head_oid, NULL);
 	if (!head)
 		die(_("Failed to resolve HEAD as a valid ref."));
 	if (!strcmp(head, "HEAD"))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index fd0dec401e..b803425bc4 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -826,7 +826,7 @@ static int switch_branches(const struct checkout_opts *opts,
 	struct object_id rev;
 	int flag, writeout_error = 0;
 	memset(&old, 0, sizeof(old));
-	old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
+	old.path = path_to_free = resolve_refdup("HEAD", 0, &rev, &flag);
 	if (old.path)
 		old.commit = lookup_commit_reference_gently(&rev, 1);
 	if (!(flag & REF_ISSYMREF))
@@ -1125,7 +1125,7 @@ static int checkout_branch(struct checkout_opts *opts,
 	    !opts->ignore_other_worktrees) {
 		struct object_id oid;
 		int flag;
-		char *head_ref = resolve_refdup("HEAD", 0, oid.hash, &flag);
+		char *head_ref = resolve_refdup("HEAD", 0, &oid, &flag);
 		if (head_ref &&
 		    (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
 			die_if_checked_out(new->path, 1);
diff --git a/builtin/clone.c b/builtin/clone.c
index 5cd1b02d53..695bdd7046 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -715,7 +715,7 @@ static int checkout(int submodule_progress)
 	if (option_no_checkout)
 		return 0;
 
-	head = resolve_refdup("HEAD", RESOLVE_REF_READING, oid.hash, NULL);
+	head = resolve_refdup("HEAD", RESOLVE_REF_READING, &oid, NULL);
 	if (!head) {
 		warning(_("remote HEAD refers to nonexistent ref, "
 			  "unable to checkout.\n"));
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index e99b5ddbf9..b69f7d3be2 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -603,7 +603,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 
 	/* get current branch */
 	current_branch = current_branch_to_free =
-		resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
+		resolve_refdup("HEAD", RESOLVE_REF_READING, &head_oid, NULL);
 	if (!current_branch)
 		die("No current branch");
 	if (starts_with(current_branch, "refs/heads/"))
diff --git a/builtin/merge.c b/builtin/merge.c
index 99d4b873f0..99d2df965f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1142,7 +1142,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
 	 * current branch.
 	 */
-	branch = branch_to_free = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
+	branch = branch_to_free = resolve_refdup("HEAD", 0, &head_oid, NULL);
 	if (branch)
 		skip_prefix(branch, "refs/heads/", &branch);
 	if (!branch || is_null_oid(&head_oid))
diff --git a/builtin/notes.c b/builtin/notes.c
index 8276af419b..12afdf1907 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -724,7 +724,7 @@ static int merge_commit(struct notes_merge_options *o)
 	init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
 
 	o->local_ref = local_ref_to_free =
-		resolve_refdup("NOTES_MERGE_REF", 0, oid.hash, NULL);
+		resolve_refdup("NOTES_MERGE_REF", 0, &oid, NULL);
 	if (!o->local_ref)
 		die(_("failed to resolve NOTES_MERGE_REF"));
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 046b600b11..313b224fad 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1515,7 +1515,7 @@ static void execute_commands(struct command *commands,
 	check_aliased_updates(commands);
 
 	free(head_name_to_free);
-	head_name = head_name_to_free = resolve_refdup("HEAD", 0, oid.hash, NULL);
+	head_name = head_name_to_free = resolve_refdup("HEAD", 0, &oid, NULL);
 
 	if (use_atomic)
 		execute_commands_atomic(commands, si);
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 84547d6fba..0237be4975 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -705,8 +705,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			static const char *fake_av[2];
 
 			fake_av[0] = resolve_refdup("HEAD",
-						    RESOLVE_REF_READING,
-						    oid.hash, NULL);
+						    RESOLVE_REF_READING, &oid,
+						    NULL);
 			fake_av[1] = NULL;
 			av = fake_av;
 			ac = 1;
@@ -775,7 +775,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 	}
 
 	head = resolve_refdup("HEAD", RESOLVE_REF_READING,
-			      head_oid.hash, NULL);
+			      &head_oid, NULL);
 
 	if (with_current_branch && head) {
 		int has_head = 0;
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 06ed02f994..5946a7ca93 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1144,7 +1144,7 @@ static int push_check(int argc, const char **argv, const char *prefix)
 	argv++;
 	argc--;
 	/* Get the submodule's head ref and determine if it is detached */
-	head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
+	head = resolve_refdup("HEAD", 0, &head_oid, NULL);
 	if (!head)
 		die(_("Failed to resolve HEAD as a valid ref."));
 	if (!strcmp(head, "HEAD"))
diff --git a/ref-filter.c b/ref-filter.c
index bc591f4f3d..24f3ca1ea3 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -297,7 +297,7 @@ static void head_atom_parser(const struct ref_format *format, struct used_atom *
 {
 	struct object_id unused;
 
-	atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, unused.hash, NULL);
+	atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, &unused, NULL);
 }
 
 static struct {
@@ -1319,7 +1319,7 @@ static void populate_value(struct ref_array_item *ref)
 	if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
 		struct object_id unused1;
 		ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
-					     unused1.hash, NULL);
+					     &unused1, NULL);
 		if (!ref->symref)
 			ref->symref = "";
 	}
diff --git a/reflog-walk.c b/reflog-walk.c
index 74ebe5148f..1a602a214d 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -65,7 +65,7 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
 		const char *name;
 		void *name_to_free;
 		name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
-						     oid.hash, NULL);
+						     &oid, NULL);
 		if (name) {
 			for_each_reflog_ent(name, read_one_reflog, reflogs);
 			free(name_to_free);
@@ -153,7 +153,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
 		if (*branch == '\0') {
 			struct object_id oid;
 			free(branch);
-			branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
+			branch = resolve_refdup("HEAD", 0, &oid, NULL);
 			if (!branch)
 				die ("No current branch");
 
diff --git a/refs.c b/refs.c
index 1e6dec4046..4919a5ad3d 100644
--- a/refs.c
+++ b/refs.c
@@ -194,21 +194,21 @@ int ref_resolves_to_object(const char *refname,
 
 char *refs_resolve_refdup(struct ref_store *refs,
 			  const char *refname, int resolve_flags,
-			  unsigned char *sha1, int *flags)
+			  struct object_id *oid, int *flags)
 {
 	const char *result;
 
 	result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
-					 sha1, flags);
+					 oid->hash, flags);
 	return xstrdup_or_null(result);
 }
 
 char *resolve_refdup(const char *refname, int resolve_flags,
-		     unsigned char *sha1, int *flags)
+		     struct object_id *oid, int *flags)
 {
 	return refs_resolve_refdup(get_main_ref_store(),
 				   refname, resolve_flags,
-				   sha1, flags);
+				   oid, flags);
 }
 
 /* The argument to filter_refs */
diff --git a/refs.h b/refs.h
index 543dcc5956..9a573a4092 100644
--- a/refs.h
+++ b/refs.h
@@ -69,9 +69,9 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
 
 char *refs_resolve_refdup(struct ref_store *refs,
 			  const char *refname, int resolve_flags,
-			  unsigned char *sha1, int *flags);
+			  struct object_id *oid, int *flags);
 char *resolve_refdup(const char *refname, int resolve_flags,
-		     unsigned char *sha1, int *flags);
+		     struct object_id *oid, int *flags);
 
 int refs_read_ref_full(struct ref_store *refs, const char *refname,
 		       int resolve_flags, unsigned char *sha1, int *flags);
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 46dbcda6a6..1ab91fd346 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2556,7 +2556,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	 */
 	head_ref = refs_resolve_refdup(ref_store, "HEAD",
 				       RESOLVE_REF_NO_RECURSE,
-				       head_oid.hash, &head_type);
+				       &head_oid, &head_type);
 
 	if (head_ref && !(head_type & REF_ISSYMREF)) {
 		FREE_AND_NULL(head_ref);
diff --git a/submodule.c b/submodule.c
index f2f30bb488..c4af15c148 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1016,7 +1016,7 @@ int push_unpushed_submodules(struct oid_array *commits,
 		char *head;
 		struct object_id head_oid;
 
-		head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
+		head = resolve_refdup("HEAD", 0, &head_oid, NULL);
 		if (!head)
 			die(_("Failed to resolve HEAD as a valid ref."));
 
diff --git a/transport.c b/transport.c
index 09bd06e6e5..093d334e96 100644
--- a/transport.c
+++ b/transport.c
@@ -475,7 +475,7 @@ void transport_print_push_status(const char *dest, struct ref *refs,
 	char *head;
 	int summary_width = transport_summary_width(refs);
 
-	head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
+	head = resolve_refdup("HEAD", RESOLVE_REF_READING, &head_oid, NULL);
 
 	if (verbose) {
 		for (ref = refs; ref; ref = ref->next)
diff --git a/wt-status.c b/wt-status.c
index 6f730ee8f2..6d7d675a5b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -129,7 +129,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 	s->use_color = -1;
 	s->relative_paths = 1;
-	s->branch = resolve_refdup("HEAD", 0, oid.hash, NULL);
+	s->branch = resolve_refdup("HEAD", 0, &oid, NULL);
 	s->reference = "HEAD";
 	s->fp = stdout;
 	s->index_file = get_index_file();
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 08/24] refs: convert read_ref and read_ref_full to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (6 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  1:35   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct " brian m. carlson
                   ` (18 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

All but two of the call sites already had parameters using the hash
parameter of struct object_id, so convert them to take a pointer to the
struct directly.  Also convert refs_read_refs_full, the underlying
implementation.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/checkout.c     |  6 +++---
 builtin/remote.c       |  2 +-
 builtin/replace.c      |  4 ++--
 builtin/show-ref.c     |  2 +-
 builtin/tag.c          |  4 ++--
 builtin/update-index.c |  6 +++---
 bundle.c               |  2 +-
 fast-import.c          |  2 +-
 notes-cache.c          |  2 +-
 notes-merge.c          |  2 +-
 notes-utils.c          |  2 +-
 notes.c                |  2 +-
 refs.c                 | 20 ++++++++++----------
 refs.h                 |  6 +++---
 refs/files-backend.c   | 16 ++++++++--------
 remote-testsvn.c       |  2 +-
 remote.c               |  6 +++---
 sequencer.c            |  2 +-
 transport-helper.c     |  5 ++---
 19 files changed, 46 insertions(+), 47 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index b803425bc4..20d2bca007 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -379,7 +379,7 @@ static int checkout_paths(const struct checkout_opts *opts,
 	if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
 		die(_("unable to write new index file"));
 
-	read_ref_full("HEAD", 0, rev.hash, NULL);
+	read_ref_full("HEAD", 0, &rev, NULL);
 	head = lookup_commit_reference_gently(&rev, 1);
 
 	errs |= post_checkout_hook(head, head, 0);
@@ -1037,7 +1037,7 @@ static int parse_branchname_arg(int argc, const char **argv,
 	setup_branch_path(new);
 
 	if (!check_refname_format(new->path, 0) &&
-	    !read_ref(new->path, branch_rev.hash))
+	    !read_ref(new->path, &branch_rev))
 		oidcpy(rev, &branch_rev);
 	else
 		new->path = NULL; /* not an existing branch */
@@ -1136,7 +1136,7 @@ static int checkout_branch(struct checkout_opts *opts,
 		struct object_id rev;
 		int flag;
 
-		if (!read_ref_full("HEAD", 0, rev.hash, &flag) &&
+		if (!read_ref_full("HEAD", 0, &rev, &flag) &&
 		    (flag & REF_ISSYMREF) && is_null_oid(&rev))
 			return switch_unborn_to_new_branch(opts);
 	}
diff --git a/builtin/remote.c b/builtin/remote.c
index 4f5cac96b0..0fddc64461 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -690,7 +690,7 @@ static int mv(int argc, const char **argv)
 		int flag = 0;
 		struct object_id oid;
 
-		read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag);
+		read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag);
 		if (!(flag & REF_ISSYMREF))
 			continue;
 		if (delete_ref(NULL, item->string, NULL, REF_NODEREF))
diff --git a/builtin/replace.c b/builtin/replace.c
index 3099e55307..10078ae371 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -113,7 +113,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
 		strbuf_addstr(&ref, oid_to_hex(&oid));
 		full_hex = ref.buf + base_len;
 
-		if (read_ref(ref.buf, oid.hash)) {
+		if (read_ref(ref.buf, &oid)) {
 			error("replace ref '%s' not found.", full_hex);
 			had_error = 1;
 			continue;
@@ -144,7 +144,7 @@ static void check_ref_valid(struct object_id *object,
 	if (check_refname_format(ref->buf, 0))
 		die("'%s' is not a valid ref name.", ref->buf);
 
-	if (read_ref(ref->buf, prev->hash))
+	if (read_ref(ref->buf, prev))
 		oidclr(prev);
 	else if (!force)
 		die("replace ref '%s' already exists", ref->buf);
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 013d241abc..cbb8cfc7d2 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -197,7 +197,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
 			struct object_id oid;
 
 			if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
-			    !read_ref(*pattern, oid.hash)) {
+			    !read_ref(*pattern, &oid)) {
 				show_one(*pattern, &oid);
 			}
 			else if (!quiet)
diff --git a/builtin/tag.c b/builtin/tag.c
index 2ededc3fb1..c36d2f115c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -82,7 +82,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 	for (p = argv; *p; p++) {
 		strbuf_reset(&ref);
 		strbuf_addf(&ref, "refs/tags/%s", *p);
-		if (read_ref(ref.buf, oid.hash)) {
+		if (read_ref(ref.buf, &oid)) {
 			error(_("tag '%s' not found."), *p);
 			had_error = 1;
 			continue;
@@ -517,7 +517,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (strbuf_check_tag_ref(&ref, tag))
 		die(_("'%s' is not a valid tag name."), tag);
 
-	if (read_ref(ref.buf, prev.hash))
+	if (read_ref(ref.buf, &prev))
 		oidclr(&prev);
 	else if (!force)
 		die(_("tag '%s' already exists"), tag);
diff --git a/builtin/update-index.c b/builtin/update-index.c
index bf7420b808..24f4b28951 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -679,9 +679,9 @@ static int unresolve_one(const char *path)
 
 static void read_head_pointers(void)
 {
-	if (read_ref("HEAD", head_oid.hash))
+	if (read_ref("HEAD", &head_oid))
 		die("No HEAD -- no initial commit yet?");
-	if (read_ref("MERGE_HEAD", merge_head_oid.hash)) {
+	if (read_ref("MERGE_HEAD", &merge_head_oid)) {
 		fprintf(stderr, "Not in the middle of a merge.\n");
 		exit(0);
 	}
@@ -721,7 +721,7 @@ static int do_reupdate(int ac, const char **av,
 		       PATHSPEC_PREFER_CWD,
 		       prefix, av + 1);
 
-	if (read_ref("HEAD", head_oid.hash))
+	if (read_ref("HEAD", &head_oid))
 		/* If there is no HEAD, that means it is an initial
 		 * commit.  Update everything in the index.
 		 */
diff --git a/bundle.c b/bundle.c
index c092d5d68f..12658c5c9f 100644
--- a/bundle.c
+++ b/bundle.c
@@ -340,7 +340,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 			continue;
 		if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
 			goto skip_write_ref;
-		if (read_ref_full(e->name, RESOLVE_REF_READING, oid.hash, &flag))
+		if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
 			flag = 0;
 		display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
 
diff --git a/fast-import.c b/fast-import.c
index 2d2d0d98f0..479e300aa3 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1758,7 +1758,7 @@ static int update_branch(struct branch *b)
 			delete_ref(NULL, b->name, NULL, 0);
 		return 0;
 	}
-	if (read_ref(b->name, old_oid.hash))
+	if (read_ref(b->name, &old_oid))
 		oidclr(&old_oid);
 	if (!force_update && !is_null_oid(&old_oid)) {
 		struct commit *old_cmit, *new_cmit;
diff --git a/notes-cache.c b/notes-cache.c
index a1969ab052..17ee8602b3 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -11,7 +11,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
 	struct strbuf msg = STRBUF_INIT;
 	int ret;
 
-	if (read_ref(ref, oid.hash) < 0)
+	if (read_ref(ref, &oid) < 0)
 		return 0;
 
 	commit = lookup_commit_reference_gently(&oid, 1);
diff --git a/notes-merge.c b/notes-merge.c
index 597d43f65c..edc6acdd92 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -549,7 +549,7 @@ int notes_merge(struct notes_merge_options *o,
 	       o->local_ref, o->remote_ref);
 
 	/* Dereference o->local_ref into local_sha1 */
-	if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
+	if (read_ref_full(o->local_ref, 0, &local_oid, NULL))
 		die("Failed to resolve local notes ref '%s'", o->local_ref);
 	else if (!check_refname_format(o->local_ref, 0) &&
 		is_null_oid(&local_oid))
diff --git a/notes-utils.c b/notes-utils.c
index 3a7008948c..5c8e70c98f 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
 	if (!parents) {
 		/* Deduce parent commit from t->ref */
 		struct object_id parent_oid;
-		if (!read_ref(t->ref, parent_oid.hash)) {
+		if (!read_ref(t->ref, &parent_oid)) {
 			struct commit *parent = lookup_commit(&parent_oid);
 			if (parse_commit(parent))
 				die("Failed to find/parse commit %s", t->ref);
diff --git a/notes.c b/notes.c
index 5c62862574..d273822b28 100644
--- a/notes.c
+++ b/notes.c
@@ -1027,7 +1027,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	if (flags & NOTES_INIT_EMPTY || !notes_ref ||
 	    get_oid_treeish(notes_ref, &object_oid))
 		return;
-	if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
+	if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
 		die("Cannot use notes ref %s", notes_ref);
 	if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
 		die("Failed to read notes tree referenced by %s (%s)",
diff --git a/refs.c b/refs.c
index 4919a5ad3d..05e01d8116 100644
--- a/refs.c
+++ b/refs.c
@@ -219,22 +219,22 @@ struct ref_filter {
 };
 
 int refs_read_ref_full(struct ref_store *refs, const char *refname,
-		       int resolve_flags, unsigned char *sha1, int *flags)
+		       int resolve_flags, struct object_id *oid, int *flags)
 {
-	if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, sha1, flags))
+	if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
 		return 0;
 	return -1;
 }
 
-int read_ref_full(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
+int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
 {
 	return refs_read_ref_full(get_main_ref_store(), refname,
-				  resolve_flags, sha1, flags);
+				  resolve_flags, oid, flags);
 }
 
-int read_ref(const char *refname, unsigned char *sha1)
+int read_ref(const char *refname, struct object_id *oid)
 {
-	return read_ref_full(refname, RESOLVE_REF_READING, sha1, NULL);
+	return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
 }
 
 int ref_exists(const char *refname)
@@ -362,7 +362,7 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
 	int flag;
 
 	strbuf_addf(&buf, "%sHEAD", get_git_namespace());
-	if (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag))
+	if (!read_ref_full(buf.buf, RESOLVE_REF_READING, &oid, &flag))
 		ret = fn(buf.buf, &oid, flag, cb_data);
 	strbuf_release(&buf);
 
@@ -598,7 +598,7 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid,
 	if (old_oid) {
 		struct object_id actual_old_oid;
 
-		if (read_ref(pseudoref, actual_old_oid.hash))
+		if (read_ref(pseudoref, &actual_old_oid))
 			die("could not read ref '%s'", pseudoref);
 		if (oidcmp(&actual_old_oid, old_oid)) {
 			strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
@@ -636,7 +636,7 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o
 				get_files_ref_lock_timeout_ms());
 		if (fd < 0)
 			die_errno(_("Could not open '%s' for writing"), filename);
-		if (read_ref(pseudoref, actual_old_oid.hash))
+		if (read_ref(pseudoref, &actual_old_oid))
 			die("could not read ref '%s'", pseudoref);
 		if (oidcmp(&actual_old_oid, old_oid)) {
 			warning("Unexpected sha1 when deleting %s", pseudoref);
@@ -1245,7 +1245,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 	int flag;
 
 	if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
-				oid.hash, &flag))
+				&oid, &flag))
 		return fn("HEAD", &oid, flag, cb_data);
 
 	return 0;
diff --git a/refs.h b/refs.h
index 9a573a4092..a2032b8397 100644
--- a/refs.h
+++ b/refs.h
@@ -74,10 +74,10 @@ char *resolve_refdup(const char *refname, int resolve_flags,
 		     struct object_id *oid, int *flags);
 
 int refs_read_ref_full(struct ref_store *refs, const char *refname,
-		       int resolve_flags, unsigned char *sha1, int *flags);
+		       int resolve_flags, struct object_id *oid, int *flags);
 int read_ref_full(const char *refname, int resolve_flags,
-		  unsigned char *sha1, int *flags);
-int read_ref(const char *refname, unsigned char *sha1);
+		  struct object_id *oid, int *flags);
+int read_ref(const char *refname, struct object_id *oid);
 
 /*
  * Return 0 if a reference named refname could be created without
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 1ab91fd346..148b98490f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -648,7 +648,7 @@ static int files_peel_ref(struct ref_store *ref_store,
 		files_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
 			       "peel_ref");
 	int flag;
-	unsigned char base[20];
+	struct object_id base;
 
 	if (current_ref_iter && current_ref_iter->refname == refname) {
 		struct object_id peeled;
@@ -660,7 +660,7 @@ static int files_peel_ref(struct ref_store *ref_store,
 	}
 
 	if (refs_read_ref_full(ref_store, refname,
-			       RESOLVE_REF_READING, base, &flag))
+			       RESOLVE_REF_READING, &base, &flag))
 		return -1;
 
 	/*
@@ -675,7 +675,7 @@ static int files_peel_ref(struct ref_store *ref_store,
 	    !refs_peel_ref(refs->packed_ref_store, refname, sha1))
 		return 0;
 
-	return peel_object(base, sha1);
+	return peel_object(base.hash, sha1);
 }
 
 struct files_ref_iterator {
@@ -817,7 +817,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 
 	if (refs_read_ref_full(ref_store, lock->ref_name,
 			       mustexist ? RESOLVE_REF_READING : 0,
-			       lock->old_oid.hash, NULL)) {
+			       &lock->old_oid, NULL)) {
 		if (old_sha1) {
 			int save_errno = errno;
 			strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
@@ -1322,7 +1322,7 @@ static int files_rename_ref(struct ref_store *ref_store,
 	 */
 	if (!refs_read_ref_full(&refs->base, newrefname,
 				RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
-				oid.hash, NULL) &&
+				&oid, NULL) &&
 	    refs_delete_ref(&refs->base, NULL, newrefname,
 			    NULL, REF_NODEREF)) {
 		if (errno == EISDIR) {
@@ -1727,7 +1727,7 @@ static void update_symref_reflog(struct files_ref_store *refs,
 	struct object_id new_oid;
 	if (logmsg &&
 	    !refs_read_ref_full(&refs->base, target,
-				RESOLVE_REF_READING, new_oid.hash, NULL) &&
+				RESOLVE_REF_READING, &new_oid, NULL) &&
 	    files_log_ref_write(refs, refname, &lock->old_oid,
 				&new_oid, logmsg, 0, &err)) {
 		error("%s", err.buf);
@@ -2016,7 +2016,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
 
 		if (refs_read_ref_full(iter->ref_store,
 				       diter->relative_path, 0,
-				       iter->oid.hash, &flags)) {
+				       &iter->oid, &flags)) {
 			error("bad ref for %s", diter->path.buf);
 			continue;
 		}
@@ -2352,7 +2352,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 			 */
 			if (refs_read_ref_full(&refs->base,
 					       referent.buf, 0,
-					       lock->old_oid.hash, NULL)) {
+					       &lock->old_oid, NULL)) {
 				if (update->flags & REF_HAVE_OLD) {
 					strbuf_addf(err, "cannot lock ref '%s': "
 						    "error reading reference",
diff --git a/remote-testsvn.c b/remote-testsvn.c
index 0ff4a31262..bcebb4c789 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -174,7 +174,7 @@ static int cmd_import(const char *line)
 	struct child_process svndump_proc = CHILD_PROCESS_INIT;
 	const char *command = "svnrdump";
 
-	if (read_ref(private_ref, head_oid.hash))
+	if (read_ref(private_ref, &head_oid))
 		startrev = 0;
 	else {
 		note_msg = read_ref_note(&head_oid);
diff --git a/remote.c b/remote.c
index b220f0dfc6..698a890a83 100644
--- a/remote.c
+++ b/remote.c
@@ -2002,13 +2002,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		return -1;
 
 	/* Cannot stat if what we used to build on no longer exists */
-	if (read_ref(base, oid.hash))
+	if (read_ref(base, &oid))
 		return -1;
 	theirs = lookup_commit_reference(&oid);
 	if (!theirs)
 		return -1;
 
-	if (read_ref(branch->refname, oid.hash))
+	if (read_ref(branch->refname, &oid))
 		return -1;
 	ours = lookup_commit_reference(&oid);
 	if (!ours)
@@ -2327,7 +2327,7 @@ static int remote_tracking(struct remote *remote, const char *refname,
 	dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
 	if (!dst)
 		return -1; /* no tracking ref for refname at remote */
-	if (read_ref(dst, oid->hash))
+	if (read_ref(dst, oid))
 		return -1; /* we know what the tracking ref is but we cannot read it */
 	return 0;
 }
diff --git a/sequencer.c b/sequencer.c
index 43a6f14eb3..f1f895774a 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1627,7 +1627,7 @@ static int rollback_single_pick(void)
 	if (!file_exists(git_path_cherry_pick_head()) &&
 	    !file_exists(git_path_revert_head()))
 		return error(_("no cherry-pick or revert in progress"));
-	if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
+	if (read_ref_full("HEAD", 0, &head_oid, NULL))
 		return error(_("cannot resolve HEAD"));
 	if (is_null_oid(&head_oid))
 		return error(_("cannot abort from a branch yet to be born"));
diff --git a/transport-helper.c b/transport-helper.c
index f183601261..640ce5a492 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -535,7 +535,7 @@ static int fetch_with_import(struct transport *transport,
 		else
 			private = xstrdup(name);
 		if (private) {
-			if (read_ref(private, posn->old_oid.hash) < 0)
+			if (read_ref(private, &posn->old_oid) < 0)
 				die("Could not read ref %s", private);
 			free(private);
 		}
@@ -1067,8 +1067,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
 		if (eon) {
 			if (has_attribute(eon + 1, "unchanged")) {
 				(*tail)->status |= REF_STATUS_UPTODATE;
-				if (read_ref((*tail)->name,
-					     (*tail)->old_oid.hash) < 0)
+				if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
 					die(_("Could not read ref %s"),
 					    (*tail)->name);
 			}
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (7 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 08/24] refs: convert read_ref and read_ref_full to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  2:03   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to " brian m. carlson
                   ` (17 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

All of the callers of these functions just pass the hash member of a
struct object_id, so convert them to use a pointer to struct object_id
directly.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 archive.c             |  2 +-
 branch.c              |  2 +-
 builtin/fast-export.c |  2 +-
 builtin/log.c         |  2 +-
 builtin/merge-base.c  |  2 +-
 builtin/merge.c       |  2 +-
 builtin/rev-parse.c   |  2 +-
 builtin/show-branch.c |  2 +-
 bundle.c              |  2 +-
 refs.c                | 14 +++++++-------
 refs.h                |  4 ++--
 remote.c              |  3 +--
 sha1_name.c           |  6 +++---
 upload-pack.c         |  2 +-
 wt-status.c           |  2 +-
 15 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/archive.c b/archive.c
index 1e41f4bbeb..0b7b62af0c 100644
--- a/archive.c
+++ b/archive.c
@@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
 		const char *colon = strchrnul(name, ':');
 		int refnamelen = colon - name;
 
-		if (!dwim_ref(name, refnamelen, oid.hash, &ref))
+		if (!dwim_ref(name, refnamelen, &oid, &ref))
 			die("no such ref: %.*s", refnamelen, name);
 		free(ref);
 	}
diff --git a/branch.c b/branch.c
index 45029ea142..62f7b0d8c2 100644
--- a/branch.c
+++ b/branch.c
@@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
 		die(_("Not a valid object name: '%s'."), start_name);
 	}
 
-	switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) {
+	switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref)) {
 	case 0:
 		/* Not branching from any existing branch */
 		if (explicit_tracking)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 2fb60d6d48..d74c73f777 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
 		if (e->flags & UNINTERESTING)
 			continue;
 
-		if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
+		if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
 			continue;
 
 		if (refspecs) {
diff --git a/builtin/log.c b/builtin/log.c
index d81a09051e..ba9d4cd786 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
 		return NULL;
 	ref = rev->cmdline.rev[positive].name;
 	tip_oid = &rev->cmdline.rev[positive].item->oid;
-	if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
+	if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
 	    skip_prefix(full_ref, "refs/heads/", &v) &&
 	    !oidcmp(tip_oid, &branch_oid))
 		branch = xstrdup(v);
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 6dbd167d3b..e99f5405ce 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
 	struct commit_list *bases;
 	int i, ret = 0;
 
-	switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
+	switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
 	case 0:
 		die("No such ref: '%s'", argv[0]);
 	case 1:
diff --git a/builtin/merge.c b/builtin/merge.c
index 99d2df965f..6071dbfe34 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -454,7 +454,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
 	if (!remote_head)
 		die(_("'%s' does not point to a commit"), remote);
 
-	if (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {
+	if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref) > 0) {
 		if (starts_with(found_ref, "refs/heads/")) {
 			strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
 				    oid_to_hex(&branch_head), remote);
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index b9c13d3d9d..ad20a948f0 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -133,7 +133,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
 			struct object_id discard;
 			char *full;
 
-			switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
+			switch (dwim_ref(name, strlen(name), &discard, &full)) {
 			case 0:
 				/*
 				 * Not found -- not a ref.  We could
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 0237be4975..722a7f4bec 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -720,7 +720,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			die(Q_("only %d entry can be shown at one time.",
 			       "only %d entries can be shown at one time.",
 			       MAX_REVS), MAX_REVS);
-		if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
+		if (!dwim_ref(*av, strlen(*av), &oid, &ref))
 			die(_("no such ref %s"), *av);
 
 		/* Has the base been specified? */
diff --git a/bundle.c b/bundle.c
index 12658c5c9f..93290962c9 100644
--- a/bundle.c
+++ b/bundle.c
@@ -338,7 +338,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
 
 		if (e->item->flags & UNINTERESTING)
 			continue;
-		if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
+		if (dwim_ref(e->name, strlen(e->name), &oid, &ref) != 1)
 			goto skip_write_ref;
 		if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
 			flag = 0;
diff --git a/refs.c b/refs.c
index 05e01d8116..14a700ade6 100644
--- a/refs.c
+++ b/refs.c
@@ -456,15 +456,15 @@ static char *substitute_branch_name(const char **string, int *len)
 	return NULL;
 }
 
-int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	char *last_branch = substitute_branch_name(&str, &len);
-	int   refs_found  = expand_ref(str, len, sha1, ref);
+	int   refs_found  = expand_ref(str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
-int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
+int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -472,15 +472,15 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
 
 	*ref = NULL;
 	for (p = ref_rev_parse_rules; *p; p++) {
-		unsigned char sha1_from_ref[20];
-		unsigned char *this_result;
+		struct object_id oid_from_ref;
+		struct object_id *this_result;
 		int flag;
 
-		this_result = refs_found ? sha1_from_ref : sha1;
+		this_result = refs_found ? &oid_from_ref : oid;
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
 		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result, &flag);
+				       this_result->hash, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
diff --git a/refs.h b/refs.h
index a2032b8397..832a77183c 100644
--- a/refs.h
+++ b/refs.h
@@ -139,8 +139,8 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
  */
 int refname_match(const char *abbrev_name, const char *full_name);
 
-int expand_ref(const char *str, int len, unsigned char *sha1, char **ref);
-int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
+int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
 
 /*
diff --git a/remote.c b/remote.c
index 698a890a83..439d3b32f2 100644
--- a/remote.c
+++ b/remote.c
@@ -1628,8 +1628,7 @@ static void set_merge(struct branch *ret)
 		if (!remote_find_tracking(remote, ret->merge[i]) ||
 		    strcmp(ret->remote_name, "."))
 			continue;
-		if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
-			     oid.hash, &ref) == 1)
+		if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]), &oid, &ref) == 1)
 			ret->merge[i]->dst = ref;
 		else
 			ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
diff --git a/sha1_name.c b/sha1_name.c
index 134ac9742f..28bad3e74b 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -603,7 +603,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
+			refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -654,11 +654,11 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
+		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
 		refs_found = dwim_log(str, len, oid->hash, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, oid->hash, &real_ref);
+		refs_found = dwim_ref(str, len, oid, &real_ref);
 
 	if (!refs_found)
 		return -1;
diff --git a/upload-pack.c b/upload-pack.c
index e25f725c0f..030eba5a0c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -787,7 +787,7 @@ static void receive_needs(void)
 		if (skip_prefix(line, "deepen-not ", &arg)) {
 			char *ref = NULL;
 			struct object_id oid;
-			if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1)
+			if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
 				die("git upload-pack: ambiguous deepen-not: %s", line);
 			string_list_append(&deepen_not, ref);
 			free(ref);
diff --git a/wt-status.c b/wt-status.c
index 6d7d675a5b..280518a89b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1451,7 +1451,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
 		return;
 	}
 
-	if (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&
+	if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
 	    /* sha1 is a commit? match without further lookup */
 	    (!oidcmp(&cb.noid, &oid) ||
 	     /* perhaps sha1 is a tag, try to dereference to a commit */
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (8 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  2:15   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 11/24] refs: convert dwim_log to struct " brian m. carlson
                   ` (16 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert the remaining uses of unsigned char [20] to struct object_id.
This conversion is needed for dwim_log.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/reflog.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 2067cca5b1..302fafbeef 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -42,7 +42,7 @@ struct expire_reflog_policy_cb {
 };
 
 struct collected_reflog {
-	unsigned char sha1[20];
+	struct object_id oid;
 	char reflog[FLEX_ARRAY];
 };
 
@@ -385,7 +385,7 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unus
 	struct collect_reflog_cb *cb = cb_data;
 
 	FLEX_ALLOC_STR(e, reflog, ref);
-	hashcpy(e->sha1, oid->hash);
+	oidcpy(&e->oid, oid);
 	ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
 	cb->e[cb->nr++] = e;
 	return 0;
@@ -589,7 +589,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 		for (i = 0; i < collected.nr; i++) {
 			struct collected_reflog *e = collected.e[i];
 			set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog);
-			status |= reflog_expire(e->reflog, e->sha1, flags,
+			status |= reflog_expire(e->reflog, e->oid.hash, flags,
 						reflog_expiry_prepare,
 						should_expire_reflog_ent,
 						reflog_expiry_cleanup,
@@ -601,13 +601,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 
 	for (; i < argc; i++) {
 		char *ref;
-		unsigned char sha1[20];
-		if (!dwim_log(argv[i], strlen(argv[i]), sha1, &ref)) {
+		struct object_id oid;
+		if (!dwim_log(argv[i], strlen(argv[i]), oid.hash, &ref)) {
 			status |= error("%s points nowhere!", argv[i]);
 			continue;
 		}
 		set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref);
-		status |= reflog_expire(ref, sha1, flags,
+		status |= reflog_expire(ref, oid.hash, flags,
 					reflog_expiry_prepare,
 					should_expire_reflog_ent,
 					reflog_expiry_cleanup,
@@ -659,7 +659,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 
 	for ( ; i < argc; i++) {
 		const char *spec = strstr(argv[i], "@{");
-		unsigned char sha1[20];
+		struct object_id oid;
 		char *ep, *ref;
 		int recno;
 
@@ -668,7 +668,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
-		if (!dwim_log(argv[i], spec - argv[i], sha1, &ref)) {
+		if (!dwim_log(argv[i], spec - argv[i], oid.hash, &ref)) {
 			status |= error("no reflog for '%s'", argv[i]);
 			continue;
 		}
@@ -683,7 +683,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 			cb.cmd.expire_total = 0;
 		}
 
-		status |= reflog_expire(ref, sha1, flags,
+		status |= reflog_expire(ref, oid.hash, flags,
 					reflog_expiry_prepare,
 					should_expire_reflog_ent,
 					reflog_expiry_cleanup,
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 11/24] refs: convert dwim_log to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (9 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  2:18   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to " brian m. carlson
                   ` (15 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/reflog.c | 4 ++--
 reflog-walk.c    | 2 +-
 refs.c           | 8 ++++----
 refs.h           | 2 +-
 sha1_name.c      | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 302fafbeef..cd4c4847b7 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -602,7 +602,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 	for (; i < argc; i++) {
 		char *ref;
 		struct object_id oid;
-		if (!dwim_log(argv[i], strlen(argv[i]), oid.hash, &ref)) {
+		if (!dwim_log(argv[i], strlen(argv[i]), &oid, &ref)) {
 			status |= error("%s points nowhere!", argv[i]);
 			continue;
 		}
@@ -668,7 +668,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
-		if (!dwim_log(argv[i], spec - argv[i], oid.hash, &ref)) {
+		if (!dwim_log(argv[i], spec - argv[i], &oid, &ref)) {
 			status |= error("no reflog for '%s'", argv[i]);
 			continue;
 		}
diff --git a/reflog-walk.c b/reflog-walk.c
index 1a602a214d..65f8a6b340 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -163,7 +163,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
 			struct object_id oid;
 			char *b;
 			int ret = dwim_log(branch, strlen(branch),
-					   oid.hash, &b);
+					   &oid, &b);
 			if (ret > 1)
 				free(b);
 			else if (ret == 1) {
diff --git a/refs.c b/refs.c
index 14a700ade6..40f07296e9 100644
--- a/refs.c
+++ b/refs.c
@@ -496,7 +496,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 	return refs_found;
 }
 
-int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 {
 	char *last_branch = substitute_branch_name(&str, &len);
 	const char **p;
@@ -505,13 +505,13 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 
 	*log = NULL;
 	for (p = ref_rev_parse_rules; *p; p++) {
-		unsigned char hash[20];
+		struct object_id hash;
 		const char *ref, *it;
 
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
 		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 hash, NULL);
+					 hash.hash, NULL);
 		if (!ref)
 			continue;
 		if (reflog_exists(path.buf))
@@ -522,7 +522,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 			continue;
 		if (!logs_found++) {
 			*log = xstrdup(it);
-			hashcpy(sha1, hash);
+			oidcpy(oid, &hash);
 		}
 		if (!warn_ambiguous_refs)
 			break;
diff --git a/refs.h b/refs.h
index 832a77183c..8159b7b067 100644
--- a/refs.h
+++ b/refs.h
@@ -141,7 +141,7 @@ int refname_match(const char *abbrev_name, const char *full_name);
 
 int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
-int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
+int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
 /*
  * A ref_transaction represents a collection of reference updates that
diff --git a/sha1_name.c b/sha1_name.c
index 28bad3e74b..7de12743f3 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -656,7 +656,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		/* allow "@{...}" to mean the current branch reflog */
 		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, oid->hash, &real_ref);
+		refs_found = dwim_log(str, len, oid, &real_ref);
 	else
 		refs_found = dwim_ref(str, len, oid, &real_ref);
 
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (10 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 11/24] refs: convert dwim_log to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  2:19   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 13/24] builtin/pack-objects: convert to struct " brian m. carlson
                   ` (14 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert traverse_bitmap_commit_list and the callbacks it takes to use a
pointer to struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/pack-objects.c | 8 ++++----
 builtin/rev-list.c     | 4 ++--
 pack-bitmap.c          | 8 ++++----
 pack-bitmap.h          | 2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 5ee2c48ffb..180c17904b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1097,20 +1097,20 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
 	return 1;
 }
 
-static int add_object_entry_from_bitmap(const unsigned char *sha1,
+static int add_object_entry_from_bitmap(const struct object_id *oid,
 					enum object_type type,
 					int flags, uint32_t name_hash,
 					struct packed_git *pack, off_t offset)
 {
 	uint32_t index_pos;
 
-	if (have_duplicate_entry(sha1, 0, &index_pos))
+	if (have_duplicate_entry(oid->hash, 0, &index_pos))
 		return 0;
 
-	if (!want_object_in_pack(sha1, 0, &pack, &offset))
+	if (!want_object_in_pack(oid->hash, 0, &pack, &offset))
 		return 0;
 
-	create_object_entry(sha1, type, name_hash, 0, 0, index_pos, pack, offset);
+	create_object_entry(oid->hash, type, name_hash, 0, 0, index_pos, pack, offset);
 
 	display_progress(progress_state, nr_result);
 	return 1;
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index c1c74d4a79..9bf8d5991c 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -258,14 +258,14 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 }
 
 static int show_object_fast(
-	const unsigned char *sha1,
+	const struct object_id *oid,
 	enum object_type type,
 	int exclude,
 	uint32_t name_hash,
 	struct packed_git *found_pack,
 	off_t found_offset)
 {
-	fprintf(stdout, "%s\n", sha1_to_hex(sha1));
+	fprintf(stdout, "%s\n", oid_to_hex(oid));
 	return 1;
 }
 
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 42e3d5f4f2..9270983e5f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -587,7 +587,7 @@ static void show_extended_objects(struct bitmap *objects,
 			continue;
 
 		obj = eindex->objects[i];
-		show_reach(obj->oid.hash, obj->type, 0, eindex->hashes[i], NULL, 0);
+		show_reach(&obj->oid, obj->type, 0, eindex->hashes[i], NULL, 0);
 	}
 }
 
@@ -612,7 +612,7 @@ static void show_objects_for_type(
 		eword_t word = objects->words[i] & filter;
 
 		for (offset = 0; offset < BITS_IN_EWORD; ++offset) {
-			const unsigned char *sha1;
+			struct object_id oid;
 			struct revindex_entry *entry;
 			uint32_t hash = 0;
 
@@ -625,12 +625,12 @@ static void show_objects_for_type(
 				continue;
 
 			entry = &bitmap_git.pack->revindex[pos + offset];
-			sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);
+			nth_packed_object_oid(&oid, bitmap_git.pack, entry->nr);
 
 			if (bitmap_git.hashes)
 				hash = get_be32(bitmap_git.hashes + entry->nr);
 
-			show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset);
+			show_reach(&oid, object_type, 0, hash, bitmap_git.pack, entry->offset);
 		}
 
 		pos += BITS_IN_EWORD;
diff --git a/pack-bitmap.h b/pack-bitmap.h
index 0adcef77b5..3742a00e14 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -27,7 +27,7 @@ enum pack_bitmap_flags {
 };
 
 typedef int (*show_reachable_fn)(
-	const unsigned char *sha1,
+	const struct object_id *oid,
 	enum object_type type,
 	int flags,
 	uint32_t hash,
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 13/24] builtin/pack-objects: convert to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (11 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-10  2:24   ` Jonathan Nieder
  2017-10-09  1:11 ` [PATCH v2 14/24] refs: convert peel_ref " brian m. carlson
                   ` (13 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

This is one of the last unconverted callers to peel_ref.  While we're
fixing that, convert the rest of the file, since it will need to be
converted at some point anyway.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/pack-objects.c | 135 +++++++++++++++++++++++++------------------------
 1 file changed, 68 insertions(+), 67 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 180c17904b..3f61512242 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -151,7 +151,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
 }
 
 static unsigned long write_large_blob_data(struct git_istream *st, struct sha1file *f,
-					   const unsigned char *sha1)
+					   const struct object_id *oid)
 {
 	git_zstream stream;
 	unsigned char ibuf[1024 * 16];
@@ -165,7 +165,7 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi
 		int zret = Z_OK;
 		readlen = read_istream(st, ibuf, sizeof(ibuf));
 		if (readlen == -1)
-			die(_("unable to read %s"), sha1_to_hex(sha1));
+			die(_("unable to read %s"), oid_to_hex(oid));
 
 		stream.next_in = ibuf;
 		stream.avail_in = readlen;
@@ -339,7 +339,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
 		sha1write(f, header, hdrlen);
 	}
 	if (st) {
-		datalen = write_large_blob_data(st, f, entry->idx.oid.hash);
+		datalen = write_large_blob_data(st, f, &entry->idx.oid);
 		close_istream(st);
 	} else {
 		sha1write(f, buf, datalen);
@@ -557,13 +557,13 @@ static enum write_one_status write_one(struct sha1file *f,
 static int mark_tagged(const char *path, const struct object_id *oid, int flag,
 		       void *cb_data)
 {
-	unsigned char peeled[20];
+	struct object_id peeled;
 	struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);
 
 	if (entry)
 		entry->tagged = 1;
-	if (!peel_ref(path, peeled)) {
-		entry = packlist_find(&to_pack, peeled, NULL);
+	if (!peel_ref(path, peeled.hash)) {
+		entry = packlist_find(&to_pack, peeled.hash, NULL);
 		if (entry)
 			entry->tagged = 1;
 	}
@@ -792,7 +792,7 @@ static void write_pack_file(void)
 	write_order = compute_write_order();
 
 	do {
-		unsigned char sha1[20];
+		struct object_id oid;
 		char *pack_tmp_name = NULL;
 
 		if (pack_to_stdout)
@@ -823,13 +823,13 @@ static void write_pack_file(void)
 		 * If so, rewrite it like in fast-import
 		 */
 		if (pack_to_stdout) {
-			sha1close(f, sha1, CSUM_CLOSE);
+			sha1close(f, oid.hash, CSUM_CLOSE);
 		} else if (nr_written == nr_remaining) {
-			sha1close(f, sha1, CSUM_FSYNC);
+			sha1close(f, oid.hash, CSUM_FSYNC);
 		} else {
-			int fd = sha1close(f, sha1, 0);
-			fixup_pack_header_footer(fd, sha1, pack_tmp_name,
-						 nr_written, sha1, offset);
+			int fd = sha1close(f, oid.hash, 0);
+			fixup_pack_header_footer(fd, oid.hash, pack_tmp_name,
+						 nr_written, oid.hash, offset);
 			close(fd);
 			if (write_bitmap_index) {
 				warning(_(no_split_warning));
@@ -863,16 +863,16 @@ static void write_pack_file(void)
 			strbuf_addf(&tmpname, "%s-", base_name);
 
 			if (write_bitmap_index) {
-				bitmap_writer_set_checksum(sha1);
+				bitmap_writer_set_checksum(oid.hash);
 				bitmap_writer_build_type_index(written_list, nr_written);
 			}
 
 			finish_tmp_packfile(&tmpname, pack_tmp_name,
 					    written_list, nr_written,
-					    &pack_idx_opts, sha1);
+					    &pack_idx_opts, oid.hash);
 
 			if (write_bitmap_index) {
-				strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1));
+				strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid));
 
 				stop_progress(&progress_state);
 
@@ -887,7 +887,7 @@ static void write_pack_file(void)
 
 			strbuf_release(&tmpname);
 			free(pack_tmp_name);
-			puts(sha1_to_hex(sha1));
+			puts(oid_to_hex(&oid));
 		}
 
 		/* mark written objects as written to previous pack */
@@ -928,13 +928,13 @@ static int no_try_delta(const char *path)
  * found the item, since that saves us from having to look it up again a
  * few lines later when we want to add the new entry.
  */
-static int have_duplicate_entry(const unsigned char *sha1,
+static int have_duplicate_entry(const struct object_id *oid,
 				int exclude,
 				uint32_t *index_pos)
 {
 	struct object_entry *entry;
 
-	entry = packlist_find(&to_pack, sha1, index_pos);
+	entry = packlist_find(&to_pack, oid->hash, index_pos);
 	if (!entry)
 		return 0;
 
@@ -990,7 +990,7 @@ static int want_found_object(int exclude, struct packed_git *p)
  * function finds if there is any pack that has the object and returns the pack
  * and its offset in these variables.
  */
-static int want_object_in_pack(const unsigned char *sha1,
+static int want_object_in_pack(const struct object_id *oid,
 			       int exclude,
 			       struct packed_git **found_pack,
 			       off_t *found_offset)
@@ -998,7 +998,7 @@ static int want_object_in_pack(const unsigned char *sha1,
 	struct mru_entry *entry;
 	int want;
 
-	if (!exclude && local && has_loose_object_nonlocal(sha1))
+	if (!exclude && local && has_loose_object_nonlocal(oid->hash))
 		return 0;
 
 	/*
@@ -1019,7 +1019,7 @@ static int want_object_in_pack(const unsigned char *sha1,
 		if (p == *found_pack)
 			offset = *found_offset;
 		else
-			offset = find_pack_entry_one(sha1, p);
+			offset = find_pack_entry_one(oid->hash, p);
 
 		if (offset) {
 			if (!*found_pack) {
@@ -1039,7 +1039,7 @@ static int want_object_in_pack(const unsigned char *sha1,
 	return 1;
 }
 
-static void create_object_entry(const unsigned char *sha1,
+static void create_object_entry(const struct object_id *oid,
 				enum object_type type,
 				uint32_t hash,
 				int exclude,
@@ -1050,7 +1050,7 @@ static void create_object_entry(const unsigned char *sha1,
 {
 	struct object_entry *entry;
 
-	entry = packlist_alloc(&to_pack, sha1, index_pos);
+	entry = packlist_alloc(&to_pack, oid->hash, index_pos);
 	entry->hash = hash;
 	if (type)
 		entry->type = type;
@@ -1070,17 +1070,17 @@ static const char no_closure_warning[] = N_(
 "disabling bitmap writing, as some objects are not being packed"
 );
 
-static int add_object_entry(const unsigned char *sha1, enum object_type type,
+static int add_object_entry(const struct object_id *oid, enum object_type type,
 			    const char *name, int exclude)
 {
 	struct packed_git *found_pack = NULL;
 	off_t found_offset = 0;
 	uint32_t index_pos;
 
-	if (have_duplicate_entry(sha1, exclude, &index_pos))
+	if (have_duplicate_entry(oid, exclude, &index_pos))
 		return 0;
 
-	if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
+	if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) {
 		/* The pack is missing an object, so it will not have closure */
 		if (write_bitmap_index) {
 			warning(_(no_closure_warning));
@@ -1089,7 +1089,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
 		return 0;
 	}
 
-	create_object_entry(sha1, type, pack_name_hash(name),
+	create_object_entry(oid, type, pack_name_hash(name),
 			    exclude, name && no_try_delta(name),
 			    index_pos, found_pack, found_offset);
 
@@ -1104,20 +1104,20 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
 {
 	uint32_t index_pos;
 
-	if (have_duplicate_entry(oid->hash, 0, &index_pos))
+	if (have_duplicate_entry(oid, 0, &index_pos))
 		return 0;
 
-	if (!want_object_in_pack(oid->hash, 0, &pack, &offset))
+	if (!want_object_in_pack(oid, 0, &pack, &offset))
 		return 0;
 
-	create_object_entry(oid->hash, type, name_hash, 0, 0, index_pos, pack, offset);
+	create_object_entry(oid, type, name_hash, 0, 0, index_pos, pack, offset);
 
 	display_progress(progress_state, nr_result);
 	return 1;
 }
 
 struct pbase_tree_cache {
-	unsigned char sha1[20];
+	struct object_id oid;
 	int ref;
 	int temporary;
 	void *tree_data;
@@ -1125,9 +1125,9 @@ struct pbase_tree_cache {
 };
 
 static struct pbase_tree_cache *(pbase_tree_cache[256]);
-static int pbase_tree_cache_ix(const unsigned char *sha1)
+static int pbase_tree_cache_ix(const struct object_id *oid)
 {
-	return sha1[0] % ARRAY_SIZE(pbase_tree_cache);
+	return oid->hash[0] % ARRAY_SIZE(pbase_tree_cache);
 }
 static int pbase_tree_cache_ix_incr(int ix)
 {
@@ -1144,14 +1144,14 @@ static struct pbase_tree {
 	struct pbase_tree_cache pcache;
 } *pbase_tree;
 
-static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
+static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
 {
 	struct pbase_tree_cache *ent, *nent;
 	void *data;
 	unsigned long size;
 	enum object_type type;
 	int neigh;
-	int my_ix = pbase_tree_cache_ix(sha1);
+	int my_ix = pbase_tree_cache_ix(oid);
 	int available_ix = -1;
 
 	/* pbase-tree-cache acts as a limited hashtable.
@@ -1160,7 +1160,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
 	 */
 	for (neigh = 0; neigh < 8; neigh++) {
 		ent = pbase_tree_cache[my_ix];
-		if (ent && !hashcmp(ent->sha1, sha1)) {
+		if (ent && !oidcmp(&ent->oid, oid)) {
 			ent->ref++;
 			return ent;
 		}
@@ -1176,7 +1176,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
 	/* Did not find one.  Either we got a bogus request or
 	 * we need to read and perhaps cache.
 	 */
-	data = read_sha1_file(sha1, &type, &size);
+	data = read_sha1_file(oid->hash, &type, &size);
 	if (!data)
 		return NULL;
 	if (type != OBJ_TREE) {
@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
 		free(ent->tree_data);
 		nent = ent;
 	}
-	hashcpy(nent->sha1, sha1);
+	oidcpy(&nent->oid, oid);
 	nent->tree_data = data;
 	nent->tree_size = size;
 	nent->ref = 1;
@@ -1247,7 +1247,7 @@ static void add_pbase_object(struct tree_desc *tree,
 		if (cmp < 0)
 			return;
 		if (name[cmplen] != '/') {
-			add_object_entry(entry.oid->hash,
+			add_object_entry(entry.oid,
 					 object_type(entry.mode),
 					 fullname, 1);
 			return;
@@ -1258,7 +1258,7 @@ static void add_pbase_object(struct tree_desc *tree,
 			const char *down = name+cmplen+1;
 			int downlen = name_cmp_len(down);
 
-			tree = pbase_tree_get(entry.oid->hash);
+			tree = pbase_tree_get(entry.oid);
 			if (!tree)
 				return;
 			init_tree_desc(&sub, tree->tree_data, tree->tree_size);
@@ -1317,7 +1317,7 @@ static void add_preferred_base_object(const char *name)
 	cmplen = name_cmp_len(name);
 	for (it = pbase_tree; it; it = it->next) {
 		if (cmplen == 0) {
-			add_object_entry(it->pcache.sha1, OBJ_TREE, NULL, 1);
+			add_object_entry(&it->pcache.oid, OBJ_TREE, NULL, 1);
 		}
 		else {
 			struct tree_desc tree;
@@ -1327,22 +1327,22 @@ static void add_preferred_base_object(const char *name)
 	}
 }
 
-static void add_preferred_base(unsigned char *sha1)
+static void add_preferred_base(struct object_id *oid)
 {
 	struct pbase_tree *it;
 	void *data;
 	unsigned long size;
-	unsigned char tree_sha1[20];
+	struct object_id tree_oid;
 
 	if (window <= num_preferred_base++)
 		return;
 
-	data = read_object_with_reference(sha1, tree_type, &size, tree_sha1);
+	data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash);
 	if (!data)
 		return;
 
 	for (it = pbase_tree; it; it = it->next) {
-		if (!hashcmp(it->pcache.sha1, tree_sha1)) {
+		if (!oidcmp(&it->pcache.oid, &tree_oid)) {
 			free(data);
 			return;
 		}
@@ -1352,7 +1352,7 @@ static void add_preferred_base(unsigned char *sha1)
 	it->next = pbase_tree;
 	pbase_tree = it;
 
-	hashcpy(it->pcache.sha1, tree_sha1);
+	oidcpy(&it->pcache.oid, &tree_oid);
 	it->pcache.tree_data = data;
 	it->pcache.tree_size = size;
 }
@@ -2357,7 +2357,7 @@ static void add_tag_chain(const struct object_id *oid)
 			die("unable to pack objects reachable from tag %s",
 			    oid_to_hex(oid));
 
-		add_object_entry(tag->object.oid.hash, OBJ_TAG, NULL, 0);
+		add_object_entry(&tag->object.oid, OBJ_TAG, NULL, 0);
 
 		if (tag->tagged->type != OBJ_TAG)
 			return;
@@ -2505,8 +2505,9 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 
 static void read_object_list_from_stdin(void)
 {
-	char line[40 + 1 + PATH_MAX + 2];
-	unsigned char sha1[20];
+	char line[GIT_MAX_HEXSZ + 1 + PATH_MAX + 2];
+	struct object_id oid;
+	const char *p;
 
 	for (;;) {
 		if (!fgets(line, sizeof(line), stdin)) {
@@ -2520,17 +2521,17 @@ static void read_object_list_from_stdin(void)
 			continue;
 		}
 		if (line[0] == '-') {
-			if (get_sha1_hex(line+1, sha1))
-				die("expected edge sha1, got garbage:\n %s",
+			if (get_oid_hex(line+1, &oid))
+				die("expected edge object ID, got garbage:\n %s",
 				    line);
-			add_preferred_base(sha1);
+			add_preferred_base(&oid);
 			continue;
 		}
-		if (get_sha1_hex(line, sha1))
-			die("expected sha1, got garbage:\n %s", line);
+		if (parse_oid_hex(line, &oid, &p))
+			die("expected object ID, got garbage:\n %s", line);
 
-		add_preferred_base_object(line+41);
-		add_object_entry(sha1, 0, line+41, 0);
+		add_preferred_base_object(p + 1);
+		add_object_entry(&oid, 0, p + 1, 0);
 	}
 }
 
@@ -2538,7 +2539,7 @@ static void read_object_list_from_stdin(void)
 
 static void show_commit(struct commit *commit, void *data)
 {
-	add_object_entry(commit->object.oid.hash, OBJ_COMMIT, NULL, 0);
+	add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0);
 	commit->object.flags |= OBJECT_ADDED;
 
 	if (write_bitmap_index)
@@ -2548,13 +2549,13 @@ static void show_commit(struct commit *commit, void *data)
 static void show_object(struct object *obj, const char *name, void *data)
 {
 	add_preferred_base_object(name);
-	add_object_entry(obj->oid.hash, obj->type, name, 0);
+	add_object_entry(&obj->oid, obj->type, name, 0);
 	obj->flags |= OBJECT_ADDED;
 }
 
 static void show_edge(struct commit *commit)
 {
-	add_preferred_base(commit->object.oid.hash);
+	add_preferred_base(&commit->object.oid);
 }
 
 struct in_pack_object {
@@ -2601,7 +2602,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 	memset(&in_pack, 0, sizeof(in_pack));
 
 	for (p = packed_git; p; p = p->next) {
-		const unsigned char *sha1;
+		struct object_id oid;
 		struct object *o;
 
 		if (!p->pack_local || p->pack_keep)
@@ -2614,8 +2615,8 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 			   in_pack.alloc);
 
 		for (i = 0; i < p->num_objects; i++) {
-			sha1 = nth_packed_object_sha1(p, i);
-			o = lookup_unknown_object(sha1);
+			nth_packed_object_oid(&oid, p, i);
+			o = lookup_unknown_object(oid.hash);
 			if (!(o->flags & OBJECT_ADDED))
 				mark_in_pack_object(o, p, &in_pack);
 			o->flags |= OBJECT_ADDED;
@@ -2626,7 +2627,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
 		QSORT(in_pack.array, in_pack.nr, ofscmp);
 		for (i = 0; i < in_pack.nr; i++) {
 			struct object *o = in_pack.array[i].object;
-			add_object_entry(o->oid.hash, o->type, "", 0);
+			add_object_entry(&o->oid, o->type, "", 0);
 		}
 	}
 	free(in_pack.array);
@@ -2642,7 +2643,7 @@ static int add_loose_object(const struct object_id *oid, const char *path,
 		return 0;
 	}
 
-	add_object_entry(oid->hash, type, "", 0);
+	add_object_entry(oid, type, "", 0);
 	return 0;
 }
 
@@ -2658,7 +2659,7 @@ static void add_unreachable_loose_objects(void)
 				      NULL, NULL, NULL);
 }
 
-static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
+static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
 {
 	static struct packed_git *last_found = (void *)1;
 	struct packed_git *p;
@@ -2667,7 +2668,7 @@ static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
 
 	while (p) {
 		if ((!p->pack_local || p->pack_keep) &&
-			find_pack_entry_one(sha1, p)) {
+			find_pack_entry_one(oid->hash, p)) {
 			last_found = p;
 			return 1;
 		}
@@ -2718,7 +2719,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
 		for (i = 0; i < p->num_objects; i++) {
 			nth_packed_object_oid(&oid, p, i);
 			if (!packlist_find(&to_pack, oid.hash, NULL) &&
-			    !has_sha1_pack_kept_or_nonlocal(oid.hash) &&
+			    !has_sha1_pack_kept_or_nonlocal(&oid) &&
 			    !loosened_object_can_be_discarded(&oid, p->mtime))
 				if (force_object_loose(oid.hash, p->mtime))
 					die("unable to force loose object");
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 14/24] refs: convert peel_ref to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (12 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 13/24] builtin/pack-objects: convert to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-11  8:00   ` Michael Haggerty
  2017-10-09  1:11 ` [PATCH v2 15/24] refs: convert read_ref_at " brian m. carlson
                   ` (12 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert peel_ref (and its corresponding backend) to struct object_id.

This transformation was done with an update to the declaration,
definition, and test helper and the following semantic patch:

@@
expression E1, E2;
@@
- peel_ref(E1, E2.hash)
+ peel_ref(E1, &E2)

@@
expression E1, E2;
@@
- peel_ref(E1, E2->hash)
+ peel_ref(E1, E2)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/describe.c        | 2 +-
 builtin/pack-objects.c    | 4 ++--
 builtin/show-ref.c        | 2 +-
 refs.c                    | 8 ++++----
 refs.h                    | 4 ++--
 refs/files-backend.c      | 8 ++++----
 refs/packed-backend.c     | 4 ++--
 refs/refs-internal.h      | 2 +-
 t/helper/test-ref-store.c | 6 +++---
 upload-pack.c             | 2 +-
 10 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/builtin/describe.c b/builtin/describe.c
index 29075dbd0f..352f8821fd 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -181,7 +181,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
 	}
 
 	/* Is it annotated? */
-	if (!peel_ref(path, peeled.hash)) {
+	if (!peel_ref(path, &peeled)) {
 		is_annotated = !!oidcmp(oid, &peeled);
 	} else {
 		oidcpy(&peeled, oid);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 3f61512242..dbfb2e111d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -562,7 +562,7 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
 
 	if (entry)
 		entry->tagged = 1;
-	if (!peel_ref(path, peeled.hash)) {
+	if (!peel_ref(path, &peeled)) {
 		entry = packlist_find(&to_pack, peeled.hash, NULL);
 		if (entry)
 			entry->tagged = 1;
@@ -2371,7 +2371,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
 	struct object_id peeled;
 
 	if (starts_with(path, "refs/tags/") && /* is a tag? */
-	    !peel_ref(path, peeled.hash)    && /* peelable? */
+	    !peel_ref(path, &peeled)    && /* peelable? */
 	    packlist_find(&to_pack, peeled.hash, NULL))      /* object packed? */
 		add_tag_chain(oid);
 	return 0;
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index cbb8cfc7d2..41e5e71cad 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -38,7 +38,7 @@ static void show_one(const char *refname, const struct object_id *oid)
 	if (!deref_tags)
 		return;
 
-	if (!peel_ref(refname, peeled.hash)) {
+	if (!peel_ref(refname, &peeled)) {
 		hex = find_unique_abbrev(peeled.hash, abbrev);
 		printf("%s %s^{}\n", hex, refname);
 	}
diff --git a/refs.c b/refs.c
index 40f07296e9..0a3754f6da 100644
--- a/refs.c
+++ b/refs.c
@@ -1675,14 +1675,14 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags)
 }
 
 int refs_peel_ref(struct ref_store *refs, const char *refname,
-		  unsigned char *sha1)
+		  struct object_id *oid)
 {
-	return refs->be->peel_ref(refs, refname, sha1);
+	return refs->be->peel_ref(refs, refname, oid);
 }
 
-int peel_ref(const char *refname, unsigned char *sha1)
+int peel_ref(const char *refname, struct object_id *oid)
 {
-	return refs_peel_ref(get_main_ref_store(), refname, sha1);
+	return refs_peel_ref(get_main_ref_store(), refname, oid);
 }
 
 int refs_create_symref(struct ref_store *refs,
diff --git a/refs.h b/refs.h
index 8159b7b067..832ade2b13 100644
--- a/refs.h
+++ b/refs.h
@@ -120,8 +120,8 @@ extern int refs_init_db(struct strbuf *err);
  * ultimately resolve to a peelable tag.
  */
 int refs_peel_ref(struct ref_store *refs, const char *refname,
-		  unsigned char *sha1);
-int peel_ref(const char *refname, unsigned char *sha1);
+		  struct object_id *oid);
+int peel_ref(const char *refname, struct object_id *oid);
 
 /**
  * Resolve refname in the nested "gitlink" repository in the specified
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 148b98490f..a7e4b9e1e9 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -642,7 +642,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
 }
 
 static int files_peel_ref(struct ref_store *ref_store,
-			  const char *refname, unsigned char *sha1)
+			  const char *refname, struct object_id *oid)
 {
 	struct files_ref_store *refs =
 		files_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
@@ -655,7 +655,7 @@ static int files_peel_ref(struct ref_store *ref_store,
 
 		if (ref_iterator_peel(current_ref_iter, &peeled))
 			return -1;
-		hashcpy(sha1, peeled.hash);
+		oidcpy(oid, &peeled);
 		return 0;
 	}
 
@@ -672,10 +672,10 @@ static int files_peel_ref(struct ref_store *ref_store,
 	 * have REF_KNOWS_PEELED.
 	 */
 	if (flag & REF_ISPACKED &&
-	    !refs_peel_ref(refs->packed_ref_store, refname, sha1))
+	    !refs_peel_ref(refs->packed_ref_store, refname, oid))
 		return 0;
 
-	return peel_object(base.hash, sha1);
+	return peel_object(base.hash, oid->hash);
 }
 
 struct files_ref_iterator {
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 3bc47ffd5e..d4bb4ba357 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -341,7 +341,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store,
 }
 
 static int packed_peel_ref(struct ref_store *ref_store,
-			   const char *refname, unsigned char *sha1)
+			   const char *refname, struct object_id *oid)
 {
 	struct packed_ref_store *refs =
 		packed_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
@@ -351,7 +351,7 @@ static int packed_peel_ref(struct ref_store *ref_store,
 	if (!r || peel_entry(r, 0))
 		return -1;
 
-	hashcpy(sha1, r->u.value.peeled.hash);
+	oidcpy(oid, &r->u.value.peeled);
 	return 0;
 }
 
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 6636a13a62..f0bedbd80b 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -549,7 +549,7 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
 
 typedef int pack_refs_fn(struct ref_store *ref_store, unsigned int flags);
 typedef int peel_ref_fn(struct ref_store *ref_store,
-			const char *refname, unsigned char *sha1);
+			const char *refname, struct object_id *oid);
 typedef int create_symref_fn(struct ref_store *ref_store,
 			     const char *ref_target,
 			     const char *refs_heads_master,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index af8dba9560..cea3285ada 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -72,12 +72,12 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
 static int cmd_peel_ref(struct ref_store *refs, const char **argv)
 {
 	const char *refname = notnull(*argv++, "refname");
-	unsigned char sha1[20];
+	struct object_id oid;
 	int ret;
 
-	ret = refs_peel_ref(refs, refname, sha1);
+	ret = refs_peel_ref(refs, refname, &oid);
 	if (!ret)
-		puts(sha1_to_hex(sha1));
+		puts(oid_to_hex(&oid));
 	return ret;
 }
 
diff --git a/upload-pack.c b/upload-pack.c
index 030eba5a0c..6d5f3c0d39 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -955,7 +955,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
 	}
 	capabilities = NULL;
-	if (!peel_ref(refname, peeled.hash))
+	if (!peel_ref(refname, &peeled))
 		packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
 	return 0;
 }
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 15/24] refs: convert read_ref_at to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (13 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 14/24] refs: convert peel_ref " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 16/24] refs: convert reflog_expire parameter " brian m. carlson
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert the callers and internals, including struct read_ref_at_cb, of
read_ref_at to use struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/show-branch.c |  4 ++--
 refs.c                | 34 +++++++++++++++++-----------------
 refs.h                |  2 +-
 sha1_name.c           |  2 +-
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 722a7f4bec..8bf42e529d 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -731,7 +731,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, oid.hash, NULL,
+				read_ref_at(ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -743,7 +743,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
+			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index 0a3754f6da..b781acc8b1 100644
--- a/refs.c
+++ b/refs.c
@@ -734,11 +734,11 @@ struct read_ref_at_cb {
 	timestamp_t at_time;
 	int cnt;
 	int reccnt;
-	unsigned char *sha1;
+	struct object_id *oid;
 	int found_it;
 
-	unsigned char osha1[20];
-	unsigned char nsha1[20];
+	struct object_id ooid;
+	struct object_id noid;
 	int tz;
 	timestamp_t date;
 	char **msg;
@@ -770,25 +770,25 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		 * we have not yet updated cb->[n|o]sha1 so they still
 		 * hold the values for the previous record.
 		 */
-		if (!is_null_sha1(cb->osha1)) {
-			hashcpy(cb->sha1, noid->hash);
-			if (hashcmp(cb->osha1, noid->hash))
+		if (!is_null_oid(&cb->ooid)) {
+			oidcpy(cb->oid, noid);
+			if (oidcmp(&cb->ooid, noid))
 				warning("Log for ref %s has gap after %s.",
 					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
 		}
 		else if (cb->date == cb->at_time)
-			hashcpy(cb->sha1, noid->hash);
-		else if (hashcmp(noid->hash, cb->sha1))
+			oidcpy(cb->oid, noid);
+		else if (oidcmp(noid, cb->oid))
 			warning("Log for ref %s unexpectedly ended on %s.",
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
-		hashcpy(cb->osha1, ooid->hash);
-		hashcpy(cb->nsha1, noid->hash);
+		oidcpy(&cb->ooid, ooid);
+		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
 		return 1;
 	}
-	hashcpy(cb->osha1, ooid->hash);
-	hashcpy(cb->nsha1, noid->hash);
+	oidcpy(&cb->ooid, ooid);
+	oidcpy(&cb->noid, noid);
 	if (cb->cnt > 0)
 		cb->cnt--;
 	return 0;
@@ -808,15 +808,15 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 		*cb->cutoff_tz = tz;
 	if (cb->cutoff_cnt)
 		*cb->cutoff_cnt = cb->reccnt;
-	hashcpy(cb->sha1, ooid->hash);
-	if (is_null_sha1(cb->sha1))
-		hashcpy(cb->sha1, noid->hash);
+	oidcpy(cb->oid, ooid);
+	if (is_null_oid(cb->oid))
+		oidcpy(cb->oid, noid);
 	/* We just want the first entry */
 	return 1;
 }
 
 int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
-		unsigned char *sha1, char **msg,
+		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
 	struct read_ref_at_cb cb;
@@ -829,7 +829,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_time = cutoff_time;
 	cb.cutoff_tz = cutoff_tz;
 	cb.cutoff_cnt = cutoff_cnt;
-	cb.sha1 = sha1;
+	cb.oid = oid;
 
 	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
 
diff --git a/refs.h b/refs.h
index 832ade2b13..3afecd2e8a 100644
--- a/refs.h
+++ b/refs.h
@@ -363,7 +363,7 @@ int safe_create_reflog(const char *refname, int force_create, struct strbuf *err
 /** Reads log for the value of ref during at_time. **/
 int read_ref_at(const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
-		unsigned char *sha1, char **msg,
+		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
 
 /** Check if a particular reflog exists */
diff --git a/sha1_name.c b/sha1_name.c
index 7de12743f3..9b806104a4 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -697,7 +697,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
+		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 16/24] refs: convert reflog_expire parameter to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (14 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 15/24] refs: convert read_ref_at " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 17/24] sha1_file: convert index_path and index_fd " brian m. carlson
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

reflog_expire already used struct object_id internally, but it did not
take it as a parameter.  Adjust the parameter (and the callers) to pass
a pointer to struct object_id instead of a pointer to unsigned char.
Remove the temporary inserted earlier as it is no longer required.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/reflog.c      | 6 +++---
 refs.c                | 8 ++++----
 refs.h                | 6 +++---
 refs/files-backend.c  | 9 +++------
 refs/packed-backend.c | 2 +-
 refs/refs-internal.h  | 2 +-
 6 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index cd4c4847b7..ab31a3b6aa 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -589,7 +589,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 		for (i = 0; i < collected.nr; i++) {
 			struct collected_reflog *e = collected.e[i];
 			set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog);
-			status |= reflog_expire(e->reflog, e->oid.hash, flags,
+			status |= reflog_expire(e->reflog, &e->oid, flags,
 						reflog_expiry_prepare,
 						should_expire_reflog_ent,
 						reflog_expiry_cleanup,
@@ -607,7 +607,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref);
-		status |= reflog_expire(ref, oid.hash, flags,
+		status |= reflog_expire(ref, &oid, flags,
 					reflog_expiry_prepare,
 					should_expire_reflog_ent,
 					reflog_expiry_cleanup,
@@ -683,7 +683,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 			cb.cmd.expire_total = 0;
 		}
 
-		status |= reflog_expire(ref, oid.hash, flags,
+		status |= reflog_expire(ref, &oid, flags,
 					reflog_expiry_prepare,
 					should_expire_reflog_ent,
 					reflog_expiry_cleanup,
diff --git a/refs.c b/refs.c
index b781acc8b1..9ddf7fcf7d 100644
--- a/refs.c
+++ b/refs.c
@@ -1972,19 +1972,19 @@ int delete_reflog(const char *refname)
 }
 
 int refs_reflog_expire(struct ref_store *refs,
-		       const char *refname, const unsigned char *sha1,
+		       const char *refname, const struct object_id *oid,
 		       unsigned int flags,
 		       reflog_expiry_prepare_fn prepare_fn,
 		       reflog_expiry_should_prune_fn should_prune_fn,
 		       reflog_expiry_cleanup_fn cleanup_fn,
 		       void *policy_cb_data)
 {
-	return refs->be->reflog_expire(refs, refname, sha1, flags,
+	return refs->be->reflog_expire(refs, refname, oid, flags,
 				       prepare_fn, should_prune_fn,
 				       cleanup_fn, policy_cb_data);
 }
 
-int reflog_expire(const char *refname, const unsigned char *sha1,
+int reflog_expire(const char *refname, const struct object_id *oid,
 		  unsigned int flags,
 		  reflog_expiry_prepare_fn prepare_fn,
 		  reflog_expiry_should_prune_fn should_prune_fn,
@@ -1992,7 +1992,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
 		  void *policy_cb_data)
 {
 	return refs_reflog_expire(get_main_ref_store(),
-				  refname, sha1, flags,
+				  refname, oid, flags,
 				  prepare_fn, should_prune_fn,
 				  cleanup_fn, policy_cb_data);
 }
diff --git a/refs.h b/refs.h
index 3afecd2e8a..1bc241424d 100644
--- a/refs.h
+++ b/refs.h
@@ -696,20 +696,20 @@ typedef int reflog_expiry_should_prune_fn(struct object_id *ooid,
 typedef void reflog_expiry_cleanup_fn(void *cb_data);
 
 /*
- * Expire reflog entries for the specified reference. sha1 is the old
+ * Expire reflog entries for the specified reference. oid is the old
  * value of the reference. flags is a combination of the constants in
  * enum expire_reflog_flags. The three function pointers are described
  * above. On success, return zero.
  */
 int refs_reflog_expire(struct ref_store *refs,
 		       const char *refname,
-		       const unsigned char *sha1,
+		       const struct object_id *oid,
 		       unsigned int flags,
 		       reflog_expiry_prepare_fn prepare_fn,
 		       reflog_expiry_should_prune_fn should_prune_fn,
 		       reflog_expiry_cleanup_fn cleanup_fn,
 		       void *policy_cb_data);
-int reflog_expire(const char *refname, const unsigned char *sha1,
+int reflog_expire(const char *refname, const struct object_id *oid,
 		  unsigned int flags,
 		  reflog_expiry_prepare_fn prepare_fn,
 		  reflog_expiry_should_prune_fn should_prune_fn,
diff --git a/refs/files-backend.c b/refs/files-backend.c
index a7e4b9e1e9..4400e18eee 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2914,7 +2914,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
 }
 
 static int files_reflog_expire(struct ref_store *ref_store,
-			       const char *refname, const unsigned char *sha1,
+			       const char *refname, const struct object_id *oid,
 			       unsigned int flags,
 			       reflog_expiry_prepare_fn prepare_fn,
 			       reflog_expiry_should_prune_fn should_prune_fn,
@@ -2931,7 +2931,6 @@ static int files_reflog_expire(struct ref_store *ref_store,
 	int status = 0;
 	int type;
 	struct strbuf err = STRBUF_INIT;
-	struct object_id oid;
 
 	memset(&cb, 0, sizeof(cb));
 	cb.flags = flags;
@@ -2943,7 +2942,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
 	 * reference itself, plus we might need to update the
 	 * reference if --updateref was specified:
 	 */
-	lock = lock_ref_sha1_basic(refs, refname, sha1,
+	lock = lock_ref_sha1_basic(refs, refname, oid->hash,
 				   NULL, NULL, REF_NODEREF,
 				   &type, &err);
 	if (!lock) {
@@ -2981,9 +2980,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
 		}
 	}
 
-	hashcpy(oid.hash, sha1);
-
-	(*prepare_fn)(refname, &oid, cb.policy_cb);
+	(*prepare_fn)(refname, oid, cb.policy_cb);
 	refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
 	(*cleanup_fn)(cb.policy_cb);
 
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index d4bb4ba357..a450efd21e 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1006,7 +1006,7 @@ static int packed_delete_reflog(struct ref_store *ref_store,
 }
 
 static int packed_reflog_expire(struct ref_store *ref_store,
-				const char *refname, const unsigned char *sha1,
+				const char *refname, const struct object_id *oid,
 				unsigned int flags,
 				reflog_expiry_prepare_fn prepare_fn,
 				reflog_expiry_should_prune_fn should_prune_fn,
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index f0bedbd80b..0cbce76f21 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -592,7 +592,7 @@ typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname,
 			     int force_create, struct strbuf *err);
 typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname);
 typedef int reflog_expire_fn(struct ref_store *ref_store,
-			     const char *refname, const unsigned char *sha1,
+			     const char *refname, const struct object_id *oid,
 			     unsigned int flags,
 			     reflog_expiry_prepare_fn prepare_fn,
 			     reflog_expiry_should_prune_fn should_prune_fn,
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 17/24] sha1_file: convert index_path and index_fd to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (15 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 16/24] refs: convert reflog_expire parameter " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 18/24] Convert remaining callers of resolve_gitlink_ref to " brian m. carlson
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert these two functions and the functions that underlie them to take
pointers to struct object_id.  This is a prerequisite to convert
resolve_gitlink_ref.  Fix a stray tab in the middle of the index_mem
call in index_pipe by converting it to a space.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sha1_file.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 5a2014811f..793fd2d194 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1660,7 +1660,7 @@ static void check_tag(const void *buf, size_t size)
 		die("corrupt tag");
 }
 
-static int index_mem(unsigned char *sha1, void *buf, size_t size,
+static int index_mem(struct object_id *oid, void *buf, size_t size,
 		     enum object_type type,
 		     const char *path, unsigned flags)
 {
@@ -1691,15 +1691,15 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
 	}
 
 	if (write_object)
-		ret = write_sha1_file(buf, size, typename(type), sha1);
+		ret = write_sha1_file(buf, size, typename(type), oid->hash);
 	else
-		ret = hash_sha1_file(buf, size, typename(type), sha1);
+		ret = hash_sha1_file(buf, size, typename(type), oid->hash);
 	if (re_allocated)
 		free(buf);
 	return ret;
 }
 
-static int index_stream_convert_blob(unsigned char *sha1, int fd,
+static int index_stream_convert_blob(struct object_id *oid, int fd,
 				     const char *path, unsigned flags)
 {
 	int ret;
@@ -1714,22 +1714,22 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,
 
 	if (write_object)
 		ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
-				      sha1);
+				      oid->hash);
 	else
 		ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
-				     sha1);
+				     oid->hash);
 	strbuf_release(&sbuf);
 	return ret;
 }
 
-static int index_pipe(unsigned char *sha1, int fd, enum object_type type,
+static int index_pipe(struct object_id *oid, int fd, enum object_type type,
 		      const char *path, unsigned flags)
 {
 	struct strbuf sbuf = STRBUF_INIT;
 	int ret;
 
 	if (strbuf_read(&sbuf, fd, 4096) >= 0)
-		ret = index_mem(sha1, sbuf.buf, sbuf.len, type,	path, flags);
+		ret = index_mem(oid, sbuf.buf, sbuf.len, type, path, flags);
 	else
 		ret = -1;
 	strbuf_release(&sbuf);
@@ -1738,24 +1738,24 @@ static int index_pipe(unsigned char *sha1, int fd, enum object_type type,
 
 #define SMALL_FILE_SIZE (32*1024)
 
-static int index_core(unsigned char *sha1, int fd, size_t size,
+static int index_core(struct object_id *oid, int fd, size_t size,
 		      enum object_type type, const char *path,
 		      unsigned flags)
 {
 	int ret;
 
 	if (!size) {
-		ret = index_mem(sha1, "", size, type, path, flags);
+		ret = index_mem(oid, "", size, type, path, flags);
 	} else if (size <= SMALL_FILE_SIZE) {
 		char *buf = xmalloc(size);
 		if (size == read_in_full(fd, buf, size))
-			ret = index_mem(sha1, buf, size, type, path, flags);
+			ret = index_mem(oid, buf, size, type, path, flags);
 		else
 			ret = error_errno("short read");
 		free(buf);
 	} else {
 		void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
-		ret = index_mem(sha1, buf, size, type, path, flags);
+		ret = index_mem(oid, buf, size, type, path, flags);
 		munmap(buf, size);
 	}
 	return ret;
@@ -1793,12 +1793,12 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
 	 * die() for large files.
 	 */
 	if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
-		ret = index_stream_convert_blob(oid->hash, fd, path, flags);
+		ret = index_stream_convert_blob(oid, fd, path, flags);
 	else if (!S_ISREG(st->st_mode))
-		ret = index_pipe(oid->hash, fd, type, path, flags);
+		ret = index_pipe(oid, fd, type, path, flags);
 	else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
 		 (path && would_convert_to_git(&the_index, path)))
-		ret = index_core(oid->hash, fd, xsize_t(st->st_size), type, path,
+		ret = index_core(oid, fd, xsize_t(st->st_size), type, path,
 				 flags);
 	else
 		ret = index_stream(oid, fd, xsize_t(st->st_size), type, path,
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 18/24] Convert remaining callers of resolve_gitlink_ref to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (16 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 17/24] sha1_file: convert index_path and index_fd " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 19/24] refs: convert resolve_gitlink_ref to struct " brian m. carlson
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 diff-lib.c     | 4 ++--
 dir.c          | 8 ++++----
 read-cache.c   | 6 +++---
 unpack-trees.c | 8 ++++----
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index 4e0980caa8..af4f1b7865 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -36,7 +36,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
 	if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
 		return 1;
 	if (S_ISDIR(st->st_mode)) {
-		unsigned char sub[20];
+		struct object_id sub;
 
 		/*
 		 * If ce is already a gitlink, we can have a plain
@@ -50,7 +50,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
 		 * a directory --- the blob was removed!
 		 */
 		if (!S_ISGITLINK(ce->ce_mode) &&
-		    resolve_gitlink_ref(ce->name, "HEAD", sub))
+		    resolve_gitlink_ref(ce->name, "HEAD", sub.hash))
 			return 1;
 	}
 	return 0;
diff --git a/dir.c b/dir.c
index 1d17b800cf..a4198ba7fd 100644
--- a/dir.c
+++ b/dir.c
@@ -1390,8 +1390,8 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
 		if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
 			break;
 		if (!(dir->flags & DIR_NO_GITLINKS)) {
-			unsigned char sha1[20];
-			if (resolve_gitlink_ref(dirname, "HEAD", sha1) == 0)
+			struct object_id oid;
+			if (resolve_gitlink_ref(dirname, "HEAD", oid.hash) == 0)
 				return path_untracked;
 		}
 		return path_recurse;
@@ -2279,10 +2279,10 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
 	int ret = 0, original_len = path->len, len, kept_down = 0;
 	int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY);
 	int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL);
-	unsigned char submodule_head[20];
+	struct object_id submodule_head;
 
 	if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
-	    !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) {
+	    !resolve_gitlink_ref(path->buf, "HEAD", submodule_head.hash)) {
 		/* Do not descend and nuke a nested git work tree. */
 		if (kept_up)
 			*kept_up = 1;
diff --git a/read-cache.c b/read-cache.c
index 65f4fe8375..131485b3a6 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -191,7 +191,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
 
 static int ce_compare_gitlink(const struct cache_entry *ce)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 
 	/*
 	 * We don't actually require that the .git directory
@@ -201,9 +201,9 @@ static int ce_compare_gitlink(const struct cache_entry *ce)
 	 *
 	 * If so, we consider it always to match.
 	 */
-	if (resolve_gitlink_ref(ce->name, "HEAD", sha1) < 0)
+	if (resolve_gitlink_ref(ce->name, "HEAD", oid.hash) < 0)
 		return 0;
-	return hashcmp(sha1, ce->oid.hash);
+	return oidcmp(&oid, &ce->oid);
 }
 
 static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
diff --git a/unpack-trees.c b/unpack-trees.c
index 71b70ccb12..0dc76eddfe 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1541,15 +1541,15 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
 	int cnt = 0;
 
 	if (S_ISGITLINK(ce->ce_mode)) {
-		unsigned char sha1[20];
-		int sub_head = resolve_gitlink_ref(ce->name, "HEAD", sha1);
+		struct object_id oid;
+		int sub_head = resolve_gitlink_ref(ce->name, "HEAD", oid.hash);
 		/*
 		 * If we are not going to update the submodule, then
 		 * we don't care.
 		 */
-		if (!sub_head && !hashcmp(sha1, ce->oid.hash))
+		if (!sub_head && !oidcmp(&oid, &ce->oid))
 			return 0;
-		return verify_clean_submodule(sub_head ? NULL : sha1_to_hex(sha1),
+		return verify_clean_submodule(sub_head ? NULL : oid_to_hex(&oid),
 					      ce, error_type, o);
 	}
 
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 19/24] refs: convert resolve_gitlink_ref to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (17 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 18/24] Convert remaining callers of resolve_gitlink_ref to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 20/24] worktree: convert struct worktree to " brian m. carlson
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert the declaration and definition of resolve_gitlink_ref to use
struct object_id and apply the following semantic patch:

@@
expression E1, E2, E3;
@@
- resolve_gitlink_ref(E1, E2, E3.hash)
+ resolve_gitlink_ref(E1, E2, &E3)

@@
expression E1, E2, E3;
@@
- resolve_gitlink_ref(E1, E2, E3->hash)
+ resolve_gitlink_ref(E1, E2, E3)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/update-index.c | 4 ++--
 combine-diff.c         | 2 +-
 diff-lib.c             | 2 +-
 dir.c                  | 4 ++--
 read-cache.c           | 2 +-
 refs.c                 | 6 +++---
 refs.h                 | 2 +-
 sha1_file.c            | 2 +-
 unpack-trees.c         | 2 +-
 9 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 24f4b28951..fefbe60167 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -328,7 +328,7 @@ static int process_directory(const char *path, int len, struct stat *st)
 		if (S_ISGITLINK(ce->ce_mode)) {
 
 			/* Do nothing to the index if there is no HEAD! */
-			if (resolve_gitlink_ref(path, "HEAD", oid.hash) < 0)
+			if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
 				return 0;
 
 			return add_one_path(ce, path, len, st);
@@ -354,7 +354,7 @@ static int process_directory(const char *path, int len, struct stat *st)
 	}
 
 	/* No match - should we add it as a gitlink? */
-	if (!resolve_gitlink_ref(path, "HEAD", oid.hash))
+	if (!resolve_gitlink_ref(path, "HEAD", &oid))
 		return add_one_path(NULL, path, len, st);
 
 	/* Error out. */
diff --git a/combine-diff.c b/combine-diff.c
index 9e163d5ada..82f6070977 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1014,7 +1014,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 			elem->mode = canon_mode(st.st_mode);
 		} else if (S_ISDIR(st.st_mode)) {
 			struct object_id oid;
-			if (resolve_gitlink_ref(elem->path, "HEAD", oid.hash) < 0)
+			if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
 				result = grab_blob(&elem->oid, elem->mode,
 						   &result_size, NULL, NULL);
 			else
diff --git a/diff-lib.c b/diff-lib.c
index af4f1b7865..d2ea02f4d7 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -50,7 +50,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
 		 * a directory --- the blob was removed!
 		 */
 		if (!S_ISGITLINK(ce->ce_mode) &&
-		    resolve_gitlink_ref(ce->name, "HEAD", sub.hash))
+		    resolve_gitlink_ref(ce->name, "HEAD", &sub))
 			return 1;
 	}
 	return 0;
diff --git a/dir.c b/dir.c
index a4198ba7fd..f09a31e102 100644
--- a/dir.c
+++ b/dir.c
@@ -1391,7 +1391,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
 			break;
 		if (!(dir->flags & DIR_NO_GITLINKS)) {
 			struct object_id oid;
-			if (resolve_gitlink_ref(dirname, "HEAD", oid.hash) == 0)
+			if (resolve_gitlink_ref(dirname, "HEAD", &oid) == 0)
 				return path_untracked;
 		}
 		return path_recurse;
@@ -2282,7 +2282,7 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
 	struct object_id submodule_head;
 
 	if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
-	    !resolve_gitlink_ref(path->buf, "HEAD", submodule_head.hash)) {
+	    !resolve_gitlink_ref(path->buf, "HEAD", &submodule_head)) {
 		/* Do not descend and nuke a nested git work tree. */
 		if (kept_up)
 			*kept_up = 1;
diff --git a/read-cache.c b/read-cache.c
index 131485b3a6..7766196aff 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -201,7 +201,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce)
 	 *
 	 * If so, we consider it always to match.
 	 */
-	if (resolve_gitlink_ref(ce->name, "HEAD", oid.hash) < 0)
+	if (resolve_gitlink_ref(ce->name, "HEAD", &oid) < 0)
 		return 0;
 	return oidcmp(&oid, &ce->oid);
 }
diff --git a/refs.c b/refs.c
index 9ddf7fcf7d..2fbe9942e2 100644
--- a/refs.c
+++ b/refs.c
@@ -1476,7 +1476,7 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
 }
 
 int resolve_gitlink_ref(const char *submodule, const char *refname,
-			unsigned char *sha1)
+			struct object_id *oid)
 {
 	struct ref_store *refs;
 	int flags;
@@ -1486,8 +1486,8 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
 	if (!refs)
 		return -1;
 
-	if (!refs_resolve_ref_unsafe(refs, refname, 0, sha1, &flags) ||
-	    is_null_sha1(sha1))
+	if (!refs_resolve_ref_unsafe(refs, refname, 0, oid->hash, &flags) ||
+	    is_null_oid(oid))
 		return -1;
 	return 0;
 }
diff --git a/refs.h b/refs.h
index 1bc241424d..bb0dcd97af 100644
--- a/refs.h
+++ b/refs.h
@@ -130,7 +130,7 @@ int peel_ref(const char *refname, struct object_id *oid);
  * otherwise, return a non-zero value.
  */
 int resolve_gitlink_ref(const char *submodule, const char *refname,
-			unsigned char *sha1);
+			struct object_id *oid);
 
 /*
  * Return true iff abbrev_name is a possible abbreviation for
diff --git a/sha1_file.c b/sha1_file.c
index 793fd2d194..f8c82ce2a2 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1832,7 +1832,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
 		strbuf_release(&sb);
 		break;
 	case S_IFDIR:
-		return resolve_gitlink_ref(path, "HEAD", oid->hash);
+		return resolve_gitlink_ref(path, "HEAD", oid);
 	default:
 		return error("%s: unsupported file type", path);
 	}
diff --git a/unpack-trees.c b/unpack-trees.c
index 0dc76eddfe..25740cb593 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1542,7 +1542,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
 
 	if (S_ISGITLINK(ce->ce_mode)) {
 		struct object_id oid;
-		int sub_head = resolve_gitlink_ref(ce->name, "HEAD", oid.hash);
+		int sub_head = resolve_gitlink_ref(ce->name, "HEAD", &oid);
 		/*
 		 * If we are not going to update the submodule, then
 		 * we don't care.
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 20/24] worktree: convert struct worktree to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (18 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 19/24] refs: convert resolve_gitlink_ref to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct " brian m. carlson
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert the head_sha1 member to be head_oid instead.  This is required
to convert resolve_ref_unsafe.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/worktree.c | 6 +++---
 worktree.c         | 2 +-
 worktree.h         | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index de26849f55..d9fe6f694e 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -392,7 +392,7 @@ static void show_worktree_porcelain(struct worktree *wt)
 	if (wt->is_bare)
 		printf("bare\n");
 	else {
-		printf("HEAD %s\n", sha1_to_hex(wt->head_sha1));
+		printf("HEAD %s\n", oid_to_hex(&wt->head_oid));
 		if (wt->is_detached)
 			printf("detached\n");
 		else if (wt->head_ref)
@@ -412,7 +412,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
 		strbuf_addstr(&sb, "(bare)");
 	else {
 		strbuf_addf(&sb, "%-*s ", abbrev_len,
-				find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
+				find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV));
 		if (wt->is_detached)
 			strbuf_addstr(&sb, "(detached HEAD)");
 		else if (wt->head_ref) {
@@ -437,7 +437,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
 
 		if (path_len > *maxlen)
 			*maxlen = path_len;
-		sha1_len = strlen(find_unique_abbrev(wt[i]->head_sha1, *abbrev));
+		sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev));
 		if (sha1_len > *abbrev)
 			*abbrev = sha1_len;
 	}
diff --git a/worktree.c b/worktree.c
index 70015629dc..cb35db03fa 100644
--- a/worktree.c
+++ b/worktree.c
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
 	target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
 					 "HEAD",
 					 0,
-					 wt->head_sha1, &flags);
+					 wt->head_oid.hash, &flags);
 	if (!target)
 		return;
 
diff --git a/worktree.h b/worktree.h
index 9276c81ae7..c28a880e18 100644
--- a/worktree.h
+++ b/worktree.h
@@ -8,7 +8,7 @@ struct worktree {
 	char *id;
 	char *head_ref;		/* NULL if HEAD is broken or detached */
 	char *lock_reason;	/* internal use */
-	unsigned char head_sha1[20];
+	struct object_id head_oid;
 	int is_detached;
 	int is_bare;
 	int is_current;
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (19 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 20/24] worktree: convert struct worktree to " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-11  8:23   ` Michael Haggerty
  2017-10-09  1:11 ` [PATCH v2 22/24] refs: convert peel_object " brian m. carlson
                   ` (5 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert resolve_ref_unsafe to take a pointer to struct object_id by
converting one remaining caller to use struct object_id, converting the
declaration and definition, and applying the following semantic patch:

@@
expression E1, E2, E3, E4;
@@
- resolve_ref_unsafe(E1, E2, E3.hash, E4)
+ resolve_ref_unsafe(E1, E2, &E3, E4)

@@
expression E1, E2, E3, E4;
@@
- resolve_ref_unsafe(E1, E2, E3->hash, E4)
+ resolve_ref_unsafe(E1, E2, E3, E4)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 blame.c                   |  4 ++--
 builtin/fsck.c            |  2 +-
 refs.c                    | 28 ++++++++++++++--------------
 refs.h                    |  4 ++--
 refs/files-backend.c      |  8 ++++----
 sequencer.c               |  2 +-
 t/helper/test-ref-store.c |  6 +++---
 transport-helper.c        |  7 +++----
 worktree.c                |  2 +-
 9 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/blame.c b/blame.c
index f575e9cbf4..c3060de2f8 100644
--- a/blame.c
+++ b/blame.c
@@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	commit->date = now;
 	parent_tail = &commit->parents;
 
-	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
+	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
 		die("no such ref: HEAD");
 
 	parent_tail = append_parent(parent_tail, &head_oid);
@@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
 		return NULL;
 
 	/* Do we have HEAD? */
-	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
+	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
 		return NULL;
 	head_commit = lookup_commit_reference_gently(&head_oid, 1);
 	if (!head_commit)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 56afe405b8..5f91116d73 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -555,7 +555,7 @@ static int fsck_head_link(void)
 	if (verbose)
 		fprintf(stderr, "Checking HEAD link\n");
 
-	head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, NULL);
+	head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
 	if (!head_points_at) {
 		errors_found |= ERROR_REFS;
 		return error("Invalid HEAD");
diff --git a/refs.c b/refs.c
index 2fbe9942e2..a030937f77 100644
--- a/refs.c
+++ b/refs.c
@@ -199,7 +199,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
 	const char *result;
 
 	result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
-					 oid->hash, flags);
+					 oid, flags);
 	return xstrdup_or_null(result);
 }
 
@@ -221,7 +221,7 @@ struct ref_filter {
 int refs_read_ref_full(struct ref_store *refs, const char *refname,
 		       int resolve_flags, struct object_id *oid, int *flags)
 {
-	if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
+	if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
 		return 0;
 	return -1;
 }
@@ -480,7 +480,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
 		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result->hash, &flag);
+				       this_result, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
@@ -511,7 +511,7 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
 		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 hash.hash, NULL);
+					 &hash, NULL);
 		if (!ref)
 			continue;
 		if (reflog_exists(path.buf))
@@ -1384,15 +1384,15 @@ int refs_read_raw_ref(struct ref_store *ref_store,
 const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 				    const char *refname,
 				    int resolve_flags,
-				    unsigned char *sha1, int *flags)
+				    struct object_id *oid, int *flags)
 {
 	static struct strbuf sb_refname = STRBUF_INIT;
 	struct object_id unused_oid;
 	int unused_flags;
 	int symref_count;
 
-	if (!sha1)
-		sha1 = unused_oid.hash;
+	if (!oid)
+		oid = &unused_oid;
 	if (!flags)
 		flags = &unused_flags;
 
@@ -1420,11 +1420,11 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 		unsigned int read_flags = 0;
 
 		if (refs_read_raw_ref(refs, refname,
-				      sha1, &sb_refname, &read_flags)) {
+				      oid->hash, &sb_refname, &read_flags)) {
 			*flags |= read_flags;
 			if (errno != ENOENT || (resolve_flags & RESOLVE_REF_READING))
 				return NULL;
-			hashclr(sha1);
+			oidclr(oid);
 			if (*flags & REF_BAD_NAME)
 				*flags |= REF_ISBROKEN;
 			return refname;
@@ -1434,7 +1434,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
 		if (!(read_flags & REF_ISSYMREF)) {
 			if (*flags & REF_BAD_NAME) {
-				hashclr(sha1);
+				oidclr(oid);
 				*flags |= REF_ISBROKEN;
 			}
 			return refname;
@@ -1442,7 +1442,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
 		refname = sb_refname.buf;
 		if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
-			hashclr(sha1);
+			oidclr(oid);
 			return refname;
 		}
 		if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
@@ -1469,10 +1469,10 @@ int refs_init_db(struct strbuf *err)
 }
 
 const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
-			       unsigned char *sha1, int *flags)
+			       struct object_id *oid, int *flags)
 {
 	return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
-				       resolve_flags, sha1, flags);
+				       resolve_flags, oid, flags);
 }
 
 int resolve_gitlink_ref(const char *submodule, const char *refname,
@@ -1486,7 +1486,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
 	if (!refs)
 		return -1;
 
-	if (!refs_resolve_ref_unsafe(refs, refname, 0, oid->hash, &flags) ||
+	if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
 	    is_null_oid(oid))
 		return -1;
 	return 0;
diff --git a/refs.h b/refs.h
index bb0dcd97af..4eedc880c6 100644
--- a/refs.h
+++ b/refs.h
@@ -62,10 +62,10 @@ struct worktree;
 const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 				    const char *refname,
 				    int resolve_flags,
-				    unsigned char *sha1,
+				    struct object_id *oid,
 				    int *flags);
 const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
-			       unsigned char *sha1, int *flags);
+			       struct object_id *oid, int *flags);
 
 char *refs_resolve_refdup(struct ref_store *refs,
 			  const char *refname, int resolve_flags,
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4400e18eee..61f3690299 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -189,7 +189,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
 			if (!refs_resolve_ref_unsafe(&refs->base,
 						     refname.buf,
 						     RESOLVE_REF_READING,
-						     oid.hash, &flag)) {
+						     &oid, &flag)) {
 				oidclr(&oid);
 				flag |= REF_ISBROKEN;
 			} else if (is_null_oid(&oid)) {
@@ -890,7 +890,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 	files_ref_path(refs, &ref_file, refname);
 	resolved = !!refs_resolve_ref_unsafe(&refs->base,
 					     refname, resolve_flags,
-					     lock->old_oid.hash, type);
+					     &lock->old_oid, type);
 	if (!resolved && errno == EISDIR) {
 		/*
 		 * we are trying to lock foo but we used to
@@ -909,7 +909,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 		}
 		resolved = !!refs_resolve_ref_unsafe(&refs->base,
 						     refname, resolve_flags,
-						     lock->old_oid.hash, type);
+						     &lock->old_oid, type);
 	}
 	if (!resolved) {
 		last_errno = errno;
@@ -1286,7 +1286,7 @@ static int files_rename_ref(struct ref_store *ref_store,
 
 	if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
 				     RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
-				orig_oid.hash, &flag)) {
+				&orig_oid, &flag)) {
 		ret = error("refname %s not found", oldrefname);
 		goto out;
 	}
diff --git a/sequencer.c b/sequencer.c
index f1f895774a..982fc35caf 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -488,7 +488,7 @@ static int is_index_unchanged(void)
 	struct object_id head_oid;
 	struct commit *head_commit;
 
-	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
+	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
 		return error(_("could not resolve HEAD commit\n"));
 
 	head_commit = lookup_commit(&head_oid);
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index cea3285ada..d846c88ed2 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -127,15 +127,15 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
 
 static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	const char *refname = notnull(*argv++, "refname");
 	int resolve_flags = arg_flags(*argv++, "resolve-flags");
 	int flags;
 	const char *ref;
 
 	ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
-				      sha1, &flags);
-	printf("%s %s 0x%x\n", sha1_to_hex(sha1), ref, flags);
+				      &oid, &flags);
+	printf("%s %s 0x%x\n", oid_to_hex(&oid), ref, flags);
 	return ref ? 0 : 1;
 }
 
diff --git a/transport-helper.c b/transport-helper.c
index 640ce5a492..bf05a2dcf1 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -942,10 +942,9 @@ static int push_refs_with_export(struct transport *transport,
 					int flag;
 
 					/* Follow symbolic refs (mainly for HEAD). */
-					name = resolve_ref_unsafe(
-						 ref->peer_ref->name,
-						 RESOLVE_REF_READING,
-						 oid.hash, &flag);
+					name = resolve_ref_unsafe(ref->peer_ref->name,
+								  RESOLVE_REF_READING,
+								  &oid, &flag);
 					if (!name || !(flag & REF_ISSYMREF))
 						name = ref->peer_ref->name;
 
diff --git a/worktree.c b/worktree.c
index cb35db03fa..2799abd555 100644
--- a/worktree.c
+++ b/worktree.c
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
 	target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
 					 "HEAD",
 					 0,
-					 wt->head_oid.hash, &flags);
+					 &wt->head_oid, &flags);
 	if (!target)
 		return;
 
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 22/24] refs: convert peel_object to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (20 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-09  1:11 ` [PATCH v2 23/24] refs: convert read_raw_ref backends " brian m. carlson
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs.c                | 8 ++++----
 refs/files-backend.c  | 2 +-
 refs/packed-backend.c | 4 ++--
 refs/ref-cache.c      | 2 +-
 refs/refs-internal.h  | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/refs.c b/refs.c
index a030937f77..958234e7d6 100644
--- a/refs.c
+++ b/refs.c
@@ -252,12 +252,12 @@ static int filter_refs(const char *refname, const struct object_id *oid,
 	return filter->fn(refname, oid, flags, filter->cb_data);
 }
 
-enum peel_status peel_object(const unsigned char *name, unsigned char *sha1)
+enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
 {
-	struct object *o = lookup_unknown_object(name);
+	struct object *o = lookup_unknown_object(name->hash);
 
 	if (o->type == OBJ_NONE) {
-		int type = sha1_object_info(name, NULL);
+		int type = sha1_object_info(name->hash, NULL);
 		if (type < 0 || !object_as_type(o, type, 0))
 			return PEEL_INVALID;
 	}
@@ -269,7 +269,7 @@ enum peel_status peel_object(const unsigned char *name, unsigned char *sha1)
 	if (!o)
 		return PEEL_INVALID;
 
-	hashcpy(sha1, o->oid.hash);
+	oidcpy(oid, &o->oid);
 	return PEEL_PEELED;
 }
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 61f3690299..417c662d5d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -675,7 +675,7 @@ static int files_peel_ref(struct ref_store *ref_store,
 	    !refs_peel_ref(refs->packed_ref_store, refname, oid))
 		return 0;
 
-	return peel_object(base.hash, oid->hash);
+	return peel_object(&base, oid);
 }
 
 struct files_ref_iterator {
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index a450efd21e..25e6fc4ffe 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -716,8 +716,8 @@ static int write_with_updates(struct packed_ref_store *refs,
 			i++;
 		} else {
 			struct object_id peeled;
-			int peel_error = peel_object(update->new_oid.hash,
-						     peeled.hash);
+			int peel_error = peel_object(&update->new_oid,
+						     &peeled);
 
 			if (write_packed_entry(out, update->refname,
 					       update->new_oid.hash,
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index 76bb723c86..e36702ed06 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -509,7 +509,7 @@ enum peel_status peel_entry(struct ref_entry *entry, int repeel)
 	if (entry->flag & REF_ISSYMREF)
 		return PEEL_IS_SYMREF;
 
-	status = peel_object(entry->u.value.oid.hash, entry->u.value.peeled.hash);
+	status = peel_object(&entry->u.value.oid, &entry->u.value.peeled);
 	if (status == PEEL_PEELED || status == PEEL_NON_TAG)
 		entry->flag |= REF_KNOWS_PEELED;
 	return status;
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 0cbce76f21..cf84da33d5 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -120,11 +120,11 @@ enum peel_status {
 /*
  * Peel the named object; i.e., if the object is a tag, resolve the
  * tag recursively until a non-tag is found.  If successful, store the
- * result to sha1 and return PEEL_PEELED.  If the object is not a tag
+ * result to oid and return PEEL_PEELED.  If the object is not a tag
  * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
  * and leave sha1 unchanged.
  */
-enum peel_status peel_object(const unsigned char *name, unsigned char *sha1);
+enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
 
 /*
  * Copy the reflog message msg to buf, which has been allocated sufficiently
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 23/24] refs: convert read_raw_ref backends to struct object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (21 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 22/24] refs: convert peel_object " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-11  8:30   ` Michael Haggerty
  2017-10-09  1:11 ` [PATCH v2 24/24] refs/files-backend: convert static functions to " brian m. carlson
                   ` (3 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert the unsigned char * parameter to struct object_id * for
files_read_raw_ref and packed_read_raw-ref.  Update the documentation.
Switch from using get_sha1_hex and a hard-coded 40 to using
parse_oid_hex.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs.c                |  8 ++++----
 refs/files-backend.c  | 13 +++++++------
 refs/packed-backend.c |  4 ++--
 refs/refs-internal.h  | 10 +++++-----
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/refs.c b/refs.c
index 958234e7d6..d8d4e06438 100644
--- a/refs.c
+++ b/refs.c
@@ -1374,10 +1374,10 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
 }
 
 int refs_read_raw_ref(struct ref_store *ref_store,
-		      const char *refname, unsigned char *sha1,
+		      const char *refname, struct object_id *oid,
 		      struct strbuf *referent, unsigned int *type)
 {
-	return ref_store->be->read_raw_ref(ref_store, refname, sha1, referent, type);
+	return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type);
 }
 
 /* This function needs to return a meaningful errno on failure */
@@ -1420,7 +1420,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 		unsigned int read_flags = 0;
 
 		if (refs_read_raw_ref(refs, refname,
-				      oid->hash, &sb_refname, &read_flags)) {
+				      oid, &sb_refname, &read_flags)) {
 			*flags |= read_flags;
 			if (errno != ENOENT || (resolve_flags & RESOLVE_REF_READING))
 				return NULL;
@@ -1842,7 +1842,7 @@ int refs_verify_refname_available(struct ref_store *refs,
 		if (skip && string_list_has_string(skip, dirname.buf))
 			continue;
 
-		if (!refs_read_raw_ref(refs, dirname.buf, oid.hash, &referent, &type)) {
+		if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
 			strbuf_addf(err, "'%s' exists; cannot create '%s'",
 				    dirname.buf, refname);
 			goto cleanup;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 417c662d5d..7281f27f62 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -261,7 +261,7 @@ static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
 }
 
 static int files_read_raw_ref(struct ref_store *ref_store,
-			      const char *refname, unsigned char *sha1,
+			      const char *refname, struct object_id *oid,
 			      struct strbuf *referent, unsigned int *type)
 {
 	struct files_ref_store *refs =
@@ -270,6 +270,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
 	struct strbuf sb_path = STRBUF_INIT;
 	const char *path;
 	const char *buf;
+	const char *p;
 	struct stat st;
 	int fd;
 	int ret = -1;
@@ -304,7 +305,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
 		if (errno != ENOENT)
 			goto out;
 		if (refs_read_raw_ref(refs->packed_ref_store, refname,
-				      sha1, referent, type)) {
+				      oid, referent, type)) {
 			errno = ENOENT;
 			goto out;
 		}
@@ -344,7 +345,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
 		 * packed ref:
 		 */
 		if (refs_read_raw_ref(refs->packed_ref_store, refname,
-				      sha1, referent, type)) {
+				      oid, referent, type)) {
 			errno = EISDIR;
 			goto out;
 		}
@@ -390,8 +391,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
 	 * Please note that FETCH_HEAD has additional
 	 * data after the sha.
 	 */
-	if (get_sha1_hex(buf, sha1) ||
-	    (buf[40] != '\0' && !isspace(buf[40]))) {
+	if (parse_oid_hex(buf, oid, &p) ||
+	    (*p != '\0' && !isspace(*p))) {
 		*type |= REF_ISBROKEN;
 		errno = EINVAL;
 		goto out;
@@ -545,7 +546,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
 	 */
 
 	if (files_read_raw_ref(&refs->base, refname,
-			       lock->old_oid.hash, referent, type)) {
+			       &lock->old_oid, referent, type)) {
 		if (errno == ENOENT) {
 			if (mustexist) {
 				/* Garden variety missing reference. */
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 25e6fc4ffe..c1960c4cfa 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -319,7 +319,7 @@ static struct ref_entry *get_packed_ref(struct packed_ref_store *refs,
 }
 
 static int packed_read_raw_ref(struct ref_store *ref_store,
-			       const char *refname, unsigned char *sha1,
+			       const char *refname, struct object_id *oid,
 			       struct strbuf *referent, unsigned int *type)
 {
 	struct packed_ref_store *refs =
@@ -335,7 +335,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store,
 		return -1;
 	}
 
-	hashcpy(sha1, entry->u.value.oid.hash);
+	oidcpy(oid, &entry->u.value.oid);
 	*type = REF_ISPACKED;
 	return 0;
 }
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index cf84da33d5..d2bcaef321 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -181,7 +181,7 @@ struct ref_update {
 };
 
 int refs_read_raw_ref(struct ref_store *ref_store,
-		      const char *refname, unsigned char *sha1,
+		      const char *refname, struct object_id *oid,
 		      struct strbuf *referent, unsigned int *type);
 
 /*
@@ -603,13 +603,13 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
  * Read a reference from the specified reference store, non-recursively.
  * Set type to describe the reference, and:
  *
- * - If refname is the name of a normal reference, fill in sha1
+ * - If refname is the name of a normal reference, fill in oid
  *   (leaving referent unchanged).
  *
  * - If refname is the name of a symbolic reference, write the full
  *   name of the reference to which it refers (e.g.
  *   "refs/heads/master") to referent and set the REF_ISSYMREF bit in
- *   type (leaving sha1 unchanged). The caller is responsible for
+ *   type (leaving oid unchanged). The caller is responsible for
  *   validating that referent is a valid reference name.
  *
  * WARNING: refname might be used as part of a filename, so it is
@@ -621,7 +621,7 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
  *
  * Return 0 on success. If the ref doesn't exist, set errno to ENOENT
  * and return -1. If the ref exists but is neither a symbolic ref nor
- * a sha1, it is broken; set REF_ISBROKEN in type, set errno to
+ * an object ID, it is broken; set REF_ISBROKEN in type, set errno to
  * EINVAL, and return -1. If there is another error reading the ref,
  * set errno appropriately and return -1.
  *
@@ -638,7 +638,7 @@ typedef int reflog_expire_fn(struct ref_store *ref_store,
  *   refname will still be valid and unchanged.
  */
 typedef int read_raw_ref_fn(struct ref_store *ref_store,
-			    const char *refname, unsigned char *sha1,
+			    const char *refname, struct object_id *oid,
 			    struct strbuf *referent, unsigned int *type);
 
 struct ref_storage_be {
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* [PATCH v2 24/24] refs/files-backend: convert static functions to object_id
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (22 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 23/24] refs: convert read_raw_ref backends " brian m. carlson
@ 2017-10-09  1:11 ` " brian m. carlson
  2017-10-11  8:36   ` Michael Haggerty
  2017-10-09 18:00 ` [PATCH v2 00/24] object_id part 10 Stefan Beller
                   ` (2 subsequent siblings)
  26 siblings, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-09  1:11 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Convert several static functions to take pointers to struct object_id.
Change the relevant parameters to write_packed_entry to be const, as we
don't modify them.  Rename lock_ref_sha1_basic to lock_ref_oid_basic to
reflect its new argument.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs/files-backend.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7281f27f62..84d8e3da99 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -811,7 +811,7 @@ static struct ref_iterator *files_ref_iterator_begin(
  * return a negative value.
  */
 static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
-		       const unsigned char *old_sha1, int mustexist,
+		       const struct object_id *old_oid, int mustexist,
 		       struct strbuf *err)
 {
 	assert(err);
@@ -819,7 +819,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 	if (refs_read_ref_full(ref_store, lock->ref_name,
 			       mustexist ? RESOLVE_REF_READING : 0,
 			       &lock->old_oid, NULL)) {
-		if (old_sha1) {
+		if (old_oid) {
 			int save_errno = errno;
 			strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
 			errno = save_errno;
@@ -829,11 +829,11 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 			return 0;
 		}
 	}
-	if (old_sha1 && hashcmp(lock->old_oid.hash, old_sha1)) {
+	if (old_oid && oidcmp(&lock->old_oid, old_oid)) {
 		strbuf_addf(err, "ref '%s' is at %s but expected %s",
 			    lock->ref_name,
 			    oid_to_hex(&lock->old_oid),
-			    sha1_to_hex(old_sha1));
+			    oid_to_hex(old_oid));
 		errno = EBUSY;
 		return -1;
 	}
@@ -863,22 +863,22 @@ static int create_reflock(const char *path, void *cb)
  * Locks a ref returning the lock on success and NULL on failure.
  * On failure errno is set to something meaningful.
  */
-static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
-					    const char *refname,
-					    const unsigned char *old_sha1,
-					    const struct string_list *extras,
-					    const struct string_list *skip,
-					    unsigned int flags, int *type,
-					    struct strbuf *err)
+static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
+					   const char *refname,
+					   const struct object_id *old_oid,
+					   const struct string_list *extras,
+					   const struct string_list *skip,
+					   unsigned int flags, int *type,
+					   struct strbuf *err)
 {
 	struct strbuf ref_file = STRBUF_INIT;
 	struct ref_lock *lock;
 	int last_errno = 0;
-	int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
+	int mustexist = (old_oid && !is_null_oid(old_oid));
 	int resolve_flags = RESOLVE_REF_NO_RECURSE;
 	int resolved;
 
-	files_assert_main_repository(refs, "lock_ref_sha1_basic");
+	files_assert_main_repository(refs, "lock_ref_oid_basic");
 	assert(err);
 
 	lock = xcalloc(1, sizeof(struct ref_lock));
@@ -944,7 +944,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 		goto error_return;
 	}
 
-	if (verify_lock(&refs->base, lock, old_sha1, mustexist, err)) {
+	if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) {
 		last_errno = errno;
 		goto error_return;
 	}
@@ -1349,8 +1349,8 @@ static int files_rename_ref(struct ref_store *ref_store,
 
 	logmoved = log;
 
-	lock = lock_ref_sha1_basic(refs, newrefname, NULL, NULL, NULL,
-				   REF_NODEREF, NULL, &err);
+	lock = lock_ref_oid_basic(refs, newrefname, NULL, NULL, NULL,
+				  REF_NODEREF, NULL, &err);
 	if (!lock) {
 		error("unable to rename '%s' to '%s': %s", oldrefname, newrefname, err.buf);
 		strbuf_release(&err);
@@ -1369,8 +1369,8 @@ static int files_rename_ref(struct ref_store *ref_store,
 	goto out;
 
  rollback:
-	lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
-				   REF_NODEREF, NULL, &err);
+	lock = lock_ref_oid_basic(refs, oldrefname, NULL, NULL, NULL,
+				  REF_NODEREF, NULL, &err);
 	if (!lock) {
 		error("unable to lock %s for rollback: %s", oldrefname, err.buf);
 		strbuf_release(&err);
@@ -1769,9 +1769,9 @@ static int files_create_symref(struct ref_store *ref_store,
 	struct ref_lock *lock;
 	int ret;
 
-	lock = lock_ref_sha1_basic(refs, refname, NULL,
-				   NULL, NULL, REF_NODEREF, NULL,
-				   &err);
+	lock = lock_ref_oid_basic(refs, refname, NULL,
+				  NULL, NULL, REF_NODEREF, NULL,
+				  &err);
 	if (!lock) {
 		error("%s", err.buf);
 		strbuf_release(&err);
@@ -2943,9 +2943,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
 	 * reference itself, plus we might need to update the
 	 * reference if --updateref was specified:
 	 */
-	lock = lock_ref_sha1_basic(refs, refname, oid->hash,
-				   NULL, NULL, REF_NODEREF,
-				   &type, &err);
+	lock = lock_ref_oid_basic(refs, refname, oid,
+				  NULL, NULL, REF_NODEREF,
+				  &type, &err);
 	if (!lock) {
 		error("cannot lock ref '%s': %s", refname, err.buf);
 		strbuf_release(&err);
-- 
2.14.2.920.gcf0c67979c


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (23 preceding siblings ...)
  2017-10-09  1:11 ` [PATCH v2 24/24] refs/files-backend: convert static functions to " brian m. carlson
@ 2017-10-09 18:00 ` Stefan Beller
  2017-10-09 22:44 ` Junio C Hamano
  2017-10-11 10:05 ` Michael Haggerty
  26 siblings, 0 replies; 53+ messages in thread
From: Stefan Beller @ 2017-10-09 18:00 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams

On Sun, Oct 8, 2017 at 6:11 PM, brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> This is the tenth in a series of patches to convert from unsigned char
> [20] to struct object_id.  This series mostly involves changes to the
> refs code.  After these changes, there are almost no references to
> unsigned char in the main refs code.
>
> The series has not been rebased on master since the last submission, but
> I can do so if that's more convenient.
>
> This series is available from the following URL:
> https://github.com/bk2204/git.git object-id-part10

Skimmed-over-and-found-no-issues-by: Stefan Beller <sbeller@google.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 01/24] walker: convert to struct object_id
  2017-10-09  1:11 ` [PATCH v2 01/24] walker: convert to struct object_id brian m. carlson
@ 2017-10-09 22:37   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 22:37 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

Hi,

brian m. carlson wrote:

> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  walker.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)

An egrep for 'sha1|unsigned char' finds nothing left in the file after
this change.

[...]
> --- a/walker.c
> +++ b/walker.c
> @@ -7,7 +7,7 @@
>  #include "blob.h"
>  #include "refs.h"
>  
> -static unsigned char current_commit_sha1[20];
> +static struct object_id current_commit_oid;

Yay!

nit, not suggesting changing anything: I would have been tempted to
call this current_commit_id, or even just current_commmit.

[...]
> @@ -259,7 +259,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
>  	struct strbuf refname = STRBUF_INIT;
>  	struct strbuf err = STRBUF_INIT;
>  	struct ref_transaction *transaction = NULL;
> -	unsigned char *sha1 = xmalloc(targets * 20);
> +	struct object_id *oids = xmalloc(targets * sizeof(struct object_id));

Not new in this patch, just noticing while we're here: can this
multiplication overflow?

E.g. in remote-curl, it looks like nr_heads gets incremented once per
"fetch" line passed to the remote helper, making it unbounded.

This could use st_mult or ALLOC_ARRAY to protect against that.  The
caller remote-curl.c::parse_fetch also needs an overflow check to
avoid overflowing its "int".  Likewise, walker_targets_stdin needs an
overflow check to avoid overflowing its "int".

[...]
> @@ -321,7 +321,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
>  done:
>  	ref_transaction_free(transaction);
>  	free(msg);
> -	free(sha1);
> +	free(oids);

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to object_id
  2017-10-09  1:11 ` [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to " brian m. carlson
@ 2017-10-09 22:38   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 22:38 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Change the member of this struct to be a struct object_id.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  refs/files-backend.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Yes, this is an obvious improvement to the clarity of the code.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct object_id
  2017-10-09  1:11 ` [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct " brian m. carlson
@ 2017-10-09 22:43   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 22:43 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Convert delete_ref and refs_delete_ref to take a pointer to struct
> object_id.  Update the documentation accordingly, including referring to
> null_oid in lowercase, as it is not a #define constant.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/branch.c          |  2 +-
>  builtin/replace.c         |  2 +-
>  builtin/reset.c           |  2 +-
>  builtin/tag.c             |  2 +-
>  builtin/update-ref.c      |  2 +-
>  refs.c                    | 21 +++++++++++----------
>  refs.h                    | 12 ++++++------
>  refs/files-backend.c      |  2 +-
>  t/helper/test-ref-store.c |  6 +++---
>  9 files changed, 26 insertions(+), 25 deletions(-)

Was this prepared using coccinelle?  (Just curious.)

[...]
> @@ -663,12 +663,13 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
>  
>  	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
>  		assert(refs == get_main_ref_store());
> -		return delete_pseudoref(refname, old_sha1);
> +		return delete_pseudoref(refname, old_oid);
>  	}
>  
>  	transaction = ref_store_transaction_begin(refs, &err);
>  	if (!transaction ||
> -	    ref_transaction_delete(transaction, refname, old_sha1,
> +	    ref_transaction_delete(transaction, refname,
> +				   old_oid ? old_oid->hash : NULL,
>  				   flags, msg, &err) ||

musing out loud: Distinguishing contexts where we need this kind of
change and contexts where we can use old_oid->hash directly can be
subtle.  Do we need some kind of annotation to mark which parameters
are nullable and which aren't?

[...]
> --- a/refs.h
> +++ b/refs.h
> @@ -371,19 +371,19 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname);
>  int reflog_exists(const char *refname);
>  
>  /*
> - * Delete the specified reference. If old_sha1 is non-NULL, then
> + * Delete the specified reference. If old_oid is non-NULL, then
>   * verify that the current value of the reference is old_sha1 before
> - * deleting it. If old_sha1 is NULL, delete the reference if it
> - * exists, regardless of its old value. It is an error for old_sha1 to
> - * be NULL_SHA1. msg and flags are passed through to
> + * deleting it. If old_oid is NULL, delete the reference if it
> + * exists, regardless of its old value. It is an error for old_oid to
> + * be null_oid. msg and flags are passed through to
>   * ref_transaction_delete().
>   */
>  int refs_delete_ref(struct ref_store *refs, const char *msg,

Thanks for updating the comment.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (24 preceding siblings ...)
  2017-10-09 18:00 ` [PATCH v2 00/24] object_id part 10 Stefan Beller
@ 2017-10-09 22:44 ` Junio C Hamano
  2017-10-11 10:05 ` Michael Haggerty
  26 siblings, 0 replies; 53+ messages in thread
From: Junio C Hamano @ 2017-10-09 22:44 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

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

> This is the tenth in a series of patches to convert from unsigned char
> [20] to struct object_id.  This series mostly involves changes to the
> refs code.  After these changes, there are almost no references to
> unsigned char in the main refs code.
>
> The series has not been rebased on master since the last submission, but
> I can do so if that's more convenient.

Thanks for working on this.

I took a look at the conflicting parts between what happened on
'master' since than and this series.  Two things stood out:

 - many calls to resolve_refdup() started passing NULL when the
   caller does not care the object name (they just want to know what
   ref the symref points at, if any).

 - the implementation of ref peeling has been updated quite a bit.

In addition, builtin/pack-objects.c will lose want_object_in_pack()
and a new function ignore_object() will be introduced to replace its
role in a topic in flight.

Having said all that, I think I managed to come up with a clean
conflict resolutions to all integration branches 'master', 'next',
'jch' and 'pu' (that is, I pretend that the topic is mergeable to
these branches immediately, make a trial merge and test the result
before teaching the resolution to my rerere database, even though
the trial merges to more stable branches than the branch the topic
will start cooking in would be immediately discarded); at least the
results of these all passed the tests, so this round that is based
on a tad older version of 'master' looks alright.


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use struct object_id
  2017-10-09  1:11 ` [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use " brian m. carlson
@ 2017-10-09 22:57   ` Jonathan Nieder
  2017-10-11  6:33   ` Michael Haggerty
  1 sibling, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 22:57 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Convert update_ref, refs_update_ref, and write_pseudoref to use struct
> object_id.  Update the existing callers as well.  Remove update_ref_oid,
> as it is no longer needed.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---

I'm very happy to see this kind of cleanup (removal of update_ref_oid).

>  bisect.c                  |  5 +++--
>  builtin/am.c              | 14 +++++++-------
>  builtin/checkout.c        |  3 +--
>  builtin/clone.c           | 14 +++++++-------
>  builtin/merge.c           | 13 ++++++-------
>  builtin/notes.c           | 10 +++++-----
>  builtin/pull.c            |  2 +-
>  builtin/reset.c           |  4 ++--
>  builtin/update-ref.c      |  2 +-
>  notes-cache.c             |  2 +-
>  notes-utils.c             |  2 +-
>  refs.c                    | 40 ++++++++++++++++------------------------
>  refs.h                    |  5 +----
>  sequencer.c               |  9 +++------
>  t/helper/test-ref-store.c | 10 +++++-----
>  transport-helper.c        |  3 ++-
>  transport.c               |  4 ++--
>  17 files changed, 64 insertions(+), 78 deletions(-)
[...]
> +++ b/builtin/checkout.c
> @@ -664,8 +664,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
>  	if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
>  		/* Nothing to do. */
>  	} else if (opts->force_detach || !new->path) {	/* No longer on any branch. */
> -		update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
> -			   REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
> +		update_ref(msg.buf, "HEAD", &new->commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);

Long line.

[...]
> --- a/builtin/pull.c
> +++ b/builtin/pull.c
> @@ -544,7 +544,7 @@ static int pull_into_void(const struct object_id *merge_head,
>  	if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
>  		return 1;
>  
> -	if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
> +	if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
>  		return 1;

nit, not needing a change: Preexisting long line.

I wonder if we can teach "make style" to perform line wrapping
correctly and fix those all at once e.g. in builtin/ at some point.
When reading, a consistent line length is helpful, but reviewing each
patch for it feels like wasted time.

[...]
> --- a/refs.c
> +++ b/refs.c
> @@ -985,17 +985,9 @@ int ref_transaction_verify(struct ref_transaction *transaction,
>  				      flags, NULL, err);
>  }
>  
> -int update_ref_oid(const char *msg, const char *refname,
> -	       const struct object_id *new_oid, const struct object_id *old_oid,
> -	       unsigned int flags, enum action_on_err onerr)
> -{
> -	return update_ref(msg, refname, new_oid ? new_oid->hash : NULL,
> -		old_oid ? old_oid->hash : NULL, flags, onerr);
> -}
> -

Yay!

[...]
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -1114,12 +1114,10 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
>  	 * write it at all.
>  	 */
>  	if (command == TODO_PICK && !opts->no_commit && (res == 0 || res == 1) &&
> -	    update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.oid.hash, NULL,
> -		       REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
> +	    update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
>  		res = -1;
>  	if (command == TODO_REVERT && ((opts->no_commit && res == 0) || res == 1) &&
> -	    update_ref(NULL, "REVERT_HEAD", commit->object.oid.hash, NULL,
> -		       REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))
> +	    update_ref(NULL, "REVERT_HEAD", &commit->object.oid, NULL, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR))

Long lines.

[...]
> @@ -2123,8 +2121,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
>  			}
>  			msg = reflog_message(opts, "finish", "%s onto %s",
>  				head_ref.buf, buf.buf);
> -			if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
> -					REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
> +			if (update_ref(msg, head_ref.buf, &head, &orig, REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
>  				res = error(_("could not update %s"),
>  					head_ref.buf);

Likewise.

As mentioned above, I am not too worried about the line length issues
(none of these is particularly jarring).  For what it's worth,

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 05/24] refs: update ref transactions to use struct object_id
  2017-10-09  1:11 ` [PATCH v2 05/24] refs: update ref transactions " brian m. carlson
@ 2017-10-09 23:13   ` Jonathan Nieder
  2017-10-11  6:58   ` Michael Haggerty
  1 sibling, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 23:13 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Update the ref transaction code to use struct object_id.  Remove one
> NULL pointer check which was previously inserted around a dereference;
> since we now pass a pointer to struct object_id directly through, the
> code we're calling handles this for us.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  branch.c               |  2 +-
>  builtin/clone.c        |  2 +-
>  builtin/commit.c       |  4 ++--
>  builtin/fetch.c        |  4 ++--
>  builtin/receive-pack.c |  4 ++--
>  builtin/replace.c      |  2 +-
>  builtin/tag.c          |  2 +-
>  builtin/update-ref.c   |  8 ++++----
>  fast-import.c          |  4 ++--
>  refs.c                 | 44 +++++++++++++++++++++-----------------------
>  refs.h                 | 24 ++++++++++++------------
>  refs/files-backend.c   | 12 ++++++------
>  refs/refs-internal.h   |  4 ++--
>  sequencer.c            |  2 +-
>  walker.c               |  2 +-
>  15 files changed, 59 insertions(+), 61 deletions(-)

Makes sense.

[...]
> +++ b/refs.c
[...]
>  int ref_transaction_create(struct ref_transaction *transaction,
>  			   const char *refname,
> -			   const unsigned char *new_sha1,
> +			   const struct object_id *new_oid,
>  			   unsigned int flags, const char *msg,
>  			   struct strbuf *err)
>  {
> -	if (!new_sha1 || is_null_sha1(new_sha1))
> +	if (!new_oid || is_null_oid(new_oid))
>  		die("BUG: create called without valid new_sha1");

The error message still refers to new_sha1.

[...]
>  int ref_transaction_delete(struct ref_transaction *transaction,
>  			   const char *refname,
> -			   const unsigned char *old_sha1,
> +			   const struct object_id *old_oid,
>  			   unsigned int flags, const char *msg,
>  			   struct strbuf *err)
>  {
> -	if (old_sha1 && is_null_sha1(old_sha1))
> +	if (old_oid && is_null_oid(old_oid))
>  		die("BUG: delete called with old_sha1 set to zeros");

Likewise.

[...]
>  int ref_transaction_verify(struct ref_transaction *transaction,
>  			   const char *refname,
> -			   const unsigned char *old_sha1,
> +			   const struct object_id *old_oid,
>  			   unsigned int flags,
>  			   struct strbuf *err)
>  {
> -	if (!old_sha1)
> +	if (!old_oid)
>  		die("BUG: verify called with old_sha1 set to NULL");

Likewise.

[...]
> +++ b/refs.h
> @@ -519,15 +519,15 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
[...]
>  /*
> - * Add a reference creation to transaction. new_sha1 is the value that
> + * Add a reference creation to transaction. new_oid is the value that
>   * the reference should have after the update; it must not be
> - * null_sha1. It is verified that the reference does not exist
> + * null_oid. It is verified that the reference does not exist
>   * already.
>   *
>   * See the above comment "Reference transaction updates" for more
> @@ -535,35 +535,35 @@ int ref_transaction_update(struct ref_transaction *transaction,
>   */

(Possible diff generation bug: there's exactly one line represented in
that @@ field.  I would have expected the diff generator to combine
the hunks.)

I think this is fine to go in without the error messages being fixed.
A grep for 'sha1' will find them later so that they can be addressed
in a separate patch.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 06/24] Convert check_connected to use struct object_id
  2017-10-09  1:11 ` [PATCH v2 06/24] Convert check_connected " brian m. carlson
@ 2017-10-09 23:20   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 23:20 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Convert check_connected and the callbacks it takes to use struct
> object_id.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/clone.c        |  4 ++--
>  builtin/fetch.c        |  4 ++--
>  builtin/receive-pack.c | 10 +++++-----
>  connected.c            | 18 +++++++++---------
>  connected.h            |  4 ++--
>  5 files changed, 20 insertions(+), 20 deletions(-)

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
  2017-10-09  1:11 ` [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to " brian m. carlson
@ 2017-10-09 23:36   ` Jonathan Nieder
  2017-10-10  1:16   ` Junio C Hamano
  1 sibling, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-09 23:36 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> All of the callers already pass the hash member of struct object_id, so
> update them to pass a pointer to the struct directly,
>
> This transformation was done with an update to declaration and
> definition and the following semantic patch:
>
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_refdup(E1, E2, E3.hash, E4)
> + resolve_refdup(E1, E2, &E3, E4)
>
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_refdup(E1, E2, E3->hash, E4)
> + resolve_refdup(E1, E2, E3, E4)
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>

Lovely.  I tried putting that in contrib/coccinelle/resolve_refdup.cocci,
running

  git grep -l -e resolve_refdup -- '*.c' '*.h' |
  xargs spatch --in-place --sp-file contrib/coccinelle/resolve_refdup.cocci

and diffing the result against this commit.  With --word-diff, there
are a small number of changes:

- the above semantic patch handles resolve_refdup but not
  refs_resolve_refdup.  This commit does both.

- as mentioned in the commit message, the above semantic patch only
  updates callers.  This commit updates the implementations to match.

Without --word-diff, I also see some line-wrapping changes, which all
seem reasonable.  (Coccinelle's line-wrapping heuristics seem to be
pretty specific to Linux kernel style.)

In other words, this does what it says on the cover in a
straightforward and reviewable way.  Thanks for that.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
  2017-10-09  1:11 ` [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to " brian m. carlson
  2017-10-09 23:36   ` Jonathan Nieder
@ 2017-10-10  1:16   ` Junio C Hamano
  1 sibling, 0 replies; 53+ messages in thread
From: Junio C Hamano @ 2017-10-10  1:16 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

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

> All of the callers already pass the hash member of struct object_id, so
> update them to pass a pointer to the struct directly,
>
> This transformation was done with an update to declaration and
> definition and the following semantic patch:
>
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_refdup(E1, E2, E3.hash, E4)
> + resolve_refdup(E1, E2, &E3, E4)
>
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_refdup(E1, E2, E3->hash, E4)
> + resolve_refdup(E1, E2, E3, E4)
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---

As I mentioned in my response to the cover letter, quite a many of
these now pass NULL (i.e. "I do not care what commit the HEAD is at;
I only am interested in which branch I am on"), making major part of
this patch irrelevant.  The conflict resolution is trivial, and I do
not think rebasing is worth it, though.


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 08/24] refs: convert read_ref and read_ref_full to object_id
  2017-10-09  1:11 ` [PATCH v2 08/24] refs: convert read_ref and read_ref_full to " brian m. carlson
@ 2017-10-10  1:35   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  1:35 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> All but two of the call sites already had parameters using the hash

nit: "already have", since commit messages use the present for the
state of the codebase without the patch applied.

> parameter of struct object_id, so convert them to take a pointer to the
> struct directly.  Also convert refs_read_refs_full, the underlying
> implementation.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/checkout.c     |  6 +++---
>  builtin/remote.c       |  2 +-
>  builtin/replace.c      |  4 ++--
>  builtin/show-ref.c     |  2 +-
>  builtin/tag.c          |  4 ++--
>  builtin/update-index.c |  6 +++---
>  bundle.c               |  2 +-
>  fast-import.c          |  2 +-
>  notes-cache.c          |  2 +-
>  notes-merge.c          |  2 +-
>  notes-utils.c          |  2 +-
>  notes.c                |  2 +-
>  refs.c                 | 20 ++++++++++----------
>  refs.h                 |  6 +++---
>  refs/files-backend.c   | 16 ++++++++--------
>  remote-testsvn.c       |  2 +-
>  remote.c               |  6 +++---
>  sequencer.c            |  2 +-
>  transport-helper.c     |  5 ++---
>  19 files changed, 46 insertions(+), 47 deletions(-)
[...]
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -379,7 +379,7 @@ static int checkout_paths(const struct checkout_opts *opts,
>  	if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
>  		die(_("unable to write new index file"));
>  
> -	read_ref_full("HEAD", 0, rev.hash, NULL);
> +	read_ref_full("HEAD", 0, &rev, NULL);

Yep, this is nicer (and likewise for the rest of them).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct object_id
  2017-10-09  1:11 ` [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct " brian m. carlson
@ 2017-10-10  2:03   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  2:03 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> All of the callers of these functions just pass the hash member of a
> struct object_id, so convert them to use a pointer to struct object_id
> directly.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  archive.c             |  2 +-
>  branch.c              |  2 +-
>  builtin/fast-export.c |  2 +-
>  builtin/log.c         |  2 +-
>  builtin/merge-base.c  |  2 +-
>  builtin/merge.c       |  2 +-
>  builtin/rev-parse.c   |  2 +-
>  builtin/show-branch.c |  2 +-
>  bundle.c              |  2 +-
>  refs.c                | 14 +++++++-------
>  refs.h                |  4 ++--
>  remote.c              |  3 +--
>  sha1_name.c           |  6 +++---
>  upload-pack.c         |  2 +-
>  wt-status.c           |  2 +-
>  15 files changed, 24 insertions(+), 25 deletions(-)

One worry below.  I might be worrying in vain but thought I might as
well ask.

> --- a/refs.c
> +++ b/refs.c
[...]
> -int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
> +int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
>  {
>  	const char **p, *r;
>  	int refs_found = 0;
> @@ -472,15 +472,15 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
>  
>  	*ref = NULL;
>  	for (p = ref_rev_parse_rules; *p; p++) {
> -		unsigned char sha1_from_ref[20];
> -		unsigned char *this_result;
> +		struct object_id oid_from_ref;
> +		struct object_id *this_result;
>  		int flag;
>  
> -		this_result = refs_found ? sha1_from_ref : sha1;
> +		this_result = refs_found ? &oid_from_ref : oid;
>  		strbuf_reset(&fullref);
>  		strbuf_addf(&fullref, *p, len, str);
>  		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
> -				       this_result, &flag);
> +				       this_result->hash, &flag);

Can this_result be NULL?  Can the oid param be NULL?

Since both this and dwim_ref are non-static functions, I'd be comforted by an

	if (!oid)
		BUG("expand_ref: oid must be non-NULL");

at the top so that mistakes in callers are caught quickly.

[...]
> --- a/remote.c
> +++ b/remote.c
> @@ -1628,8 +1628,7 @@ static void set_merge(struct branch *ret)
>  		if (!remote_find_tracking(remote, ret->merge[i]) ||
>  		    strcmp(ret->remote_name, "."))
>  			continue;
> -		if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
> -			     oid.hash, &ref) == 1)
> +		if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]), &oid, &ref) == 1)
>  			ret->merge[i]->dst = ref;

Long line (but as discussed earlier in this series, I don't mind).

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to object_id
  2017-10-09  1:11 ` [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to " brian m. carlson
@ 2017-10-10  2:15   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  2:15 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Convert the remaining uses of unsigned char [20] to struct object_id.
> This conversion is needed for dwim_log.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/reflog.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)

Thanks.  Looks good.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 11/24] refs: convert dwim_log to struct object_id
  2017-10-09  1:11 ` [PATCH v2 11/24] refs: convert dwim_log to struct " brian m. carlson
@ 2017-10-10  2:18   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  2:18 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/reflog.c | 4 ++--
>  reflog-walk.c    | 2 +-
>  refs.c           | 8 ++++----
>  refs.h           | 2 +-
>  sha1_name.c      | 2 +-
>  5 files changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Jonathan Nieer <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to object_id
  2017-10-09  1:11 ` [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to " brian m. carlson
@ 2017-10-10  2:19   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  2:19 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> Convert traverse_bitmap_commit_list and the callbacks it takes to use a
> pointer to struct object_id.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/pack-objects.c | 8 ++++----
>  builtin/rev-list.c     | 4 ++--
>  pack-bitmap.c          | 8 ++++----
>  pack-bitmap.h          | 2 +-
>  4 files changed, 11 insertions(+), 11 deletions(-)

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 13/24] builtin/pack-objects: convert to struct object_id
  2017-10-09  1:11 ` [PATCH v2 13/24] builtin/pack-objects: convert to struct " brian m. carlson
@ 2017-10-10  2:24   ` Jonathan Nieder
  0 siblings, 0 replies; 53+ messages in thread
From: Jonathan Nieder @ 2017-10-10  2:24 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Jeff King, Michael Haggerty, Brandon Williams, Stefan Beller

brian m. carlson wrote:

> This is one of the last unconverted callers to peel_ref.  While we're
> fixing that, convert the rest of the file, since it will need to be
> converted at some point anyway.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/pack-objects.c | 135 +++++++++++++++++++++++++------------------------
>  1 file changed, 68 insertions(+), 67 deletions(-)

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use struct object_id
  2017-10-09  1:11 ` [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use " brian m. carlson
  2017-10-09 22:57   ` Jonathan Nieder
@ 2017-10-11  6:33   ` Michael Haggerty
  2017-10-12  8:42     ` brian m. carlson
  1 sibling, 1 reply; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  6:33 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller, David Turner

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Convert update_ref, refs_update_ref, and write_pseudoref to use struct
> object_id.  Update the existing callers as well.  Remove update_ref_oid,
> as it is no longer needed.
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  bisect.c                  |  5 +++--
>  builtin/am.c              | 14 +++++++-------
>  builtin/checkout.c        |  3 +--
>  builtin/clone.c           | 14 +++++++-------
>  builtin/merge.c           | 13 ++++++-------
>  builtin/notes.c           | 10 +++++-----
>  builtin/pull.c            |  2 +-
>  builtin/reset.c           |  4 ++--
>  builtin/update-ref.c      |  2 +-
>  notes-cache.c             |  2 +-
>  notes-utils.c             |  2 +-
>  refs.c                    | 40 ++++++++++++++++------------------------
>  refs.h                    |  5 +----
>  sequencer.c               |  9 +++------
>  t/helper/test-ref-store.c | 10 +++++-----
>  transport-helper.c        |  3 ++-
>  transport.c               |  4 ++--
>  17 files changed, 64 insertions(+), 78 deletions(-)
> 
> [...]
> diff --git a/refs.c b/refs.c
> index 0a5b68d6fb..51942df7b3 100644
> --- a/refs.c
> +++ b/refs.c
> [...]
> @@ -1003,12 +995,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
>  	int ret = 0;
>  
>  	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
> -		assert(refs == get_main_ref_store());

Was the deletion of the line above intentional?

> -		ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
> +		ret = write_pseudoref(refname, new_oid, old_oid, &err);

This is not new to your code, but I just noticed a problem here.
`refs_update_ref()` is documented, via its reference to
`ref_transaction_update()`, to allow `new_sha1` (i.e., now `new_oid`) to
be NULL. (NULL signifies that the value of the reference shouldn't be
changed.)

But `write_pseudoref()` dereferences its `oid` argument unconditionally,
so this call would fail if `new_oid` is NULL.

This has all been the case since `write_pseudoref()` was introduced in
74ec19d4be (pseudorefs: create and use pseudoref update and delete
functions, 2015-07-31).

In my opinion, `write_pseudoref()` is broken. It should accept NULL as
its `oid` argument.

>  	} else {
>  		t = ref_store_transaction_begin(refs, &err);
>  		if (!t ||
> -		    ref_transaction_update(t, refname, new_sha1, old_sha1,
> +		    ref_transaction_update(t, refname, new_oid ? new_oid->hash : NULL,
> +					   old_oid ? old_oid->hash : NULL,
>  					   flags, msg, &err) ||
>  		    ref_transaction_commit(t, &err)) {
>  			ret = 1;
> [...]

Michael

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 05/24] refs: update ref transactions to use struct object_id
  2017-10-09  1:11 ` [PATCH v2 05/24] refs: update ref transactions " brian m. carlson
  2017-10-09 23:13   ` Jonathan Nieder
@ 2017-10-11  6:58   ` Michael Haggerty
  1 sibling, 0 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  6:58 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Update the ref transaction code to use struct object_id.  Remove one
> NULL pointer check which was previously inserted around a dereference;
> since we now pass a pointer to struct object_id directly through, the
> code we're calling handles this for us.
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  branch.c               |  2 +-
>  builtin/clone.c        |  2 +-
>  builtin/commit.c       |  4 ++--
>  builtin/fetch.c        |  4 ++--
>  builtin/receive-pack.c |  4 ++--
>  builtin/replace.c      |  2 +-
>  builtin/tag.c          |  2 +-
>  builtin/update-ref.c   |  8 ++++----
>  fast-import.c          |  4 ++--
>  refs.c                 | 44 +++++++++++++++++++++-----------------------
>  refs.h                 | 24 ++++++++++++------------
>  refs/files-backend.c   | 12 ++++++------
>  refs/refs-internal.h   |  4 ++--
>  sequencer.c            |  2 +-
>  walker.c               |  2 +-
>  15 files changed, 59 insertions(+), 61 deletions(-)
> 
> [...]
> diff --git a/refs.h b/refs.h
> index 369614d392..543dcc5956 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -519,15 +519,15 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
>   */
>  int ref_transaction_update(struct ref_transaction *transaction,

The docstring for this function needs to be updated.

>  			   const char *refname,
> -			   const unsigned char *new_sha1,
> -			   const unsigned char *old_sha1,
> +			   const struct object_id *new_oid,
> +			   const struct object_id *old_oid,
>  			   unsigned int flags, const char *msg,
>  			   struct strbuf *err);
>  
> [...]

Michael

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 14/24] refs: convert peel_ref to struct object_id
  2017-10-09  1:11 ` [PATCH v2 14/24] refs: convert peel_ref " brian m. carlson
@ 2017-10-11  8:00   ` Michael Haggerty
  0 siblings, 0 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  8:00 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Convert peel_ref (and its corresponding backend) to struct object_id.
> 
> This transformation was done with an update to the declaration,
> definition, and test helper and the following semantic patch:
> 
> @@
> expression E1, E2;
> @@
> - peel_ref(E1, E2.hash)
> + peel_ref(E1, &E2)
> 
> @@
> expression E1, E2;
> @@
> - peel_ref(E1, E2->hash)
> + peel_ref(E1, E2)
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/describe.c        | 2 +-
>  builtin/pack-objects.c    | 4 ++--
>  builtin/show-ref.c        | 2 +-
>  refs.c                    | 8 ++++----
>  refs.h                    | 4 ++--
>  refs/files-backend.c      | 8 ++++----
>  refs/packed-backend.c     | 4 ++--
>  refs/refs-internal.h      | 2 +-
>  t/helper/test-ref-store.c | 6 +++---
>  upload-pack.c             | 2 +-
>  10 files changed, 21 insertions(+), 21 deletions(-)
> 
> [...]
> diff --git a/refs.h b/refs.h
> index 8159b7b067..832ade2b13 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -120,8 +120,8 @@ extern int refs_init_db(struct strbuf *err);
>   * ultimately resolve to a peelable tag.
>   */

The comment just above needs to be adjusted.

>  int refs_peel_ref(struct ref_store *refs, const char *refname,
> -		  unsigned char *sha1);
> -int peel_ref(const char *refname, unsigned char *sha1);
> +		  struct object_id *oid);
> +int peel_ref(const char *refname, struct object_id *oid);
>  
>  /**
>   * Resolve refname in the nested "gitlink" repository in the specified
> [...]

Michael


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct object_id
  2017-10-09  1:11 ` [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct " brian m. carlson
@ 2017-10-11  8:23   ` Michael Haggerty
  0 siblings, 0 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  8:23 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Convert resolve_ref_unsafe to take a pointer to struct object_id by
> converting one remaining caller to use struct object_id, converting the
> declaration and definition, and applying the following semantic patch:
> 
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_ref_unsafe(E1, E2, E3.hash, E4)
> + resolve_ref_unsafe(E1, E2, &E3, E4)
> 
> @@
> expression E1, E2, E3, E4;
> @@
> - resolve_ref_unsafe(E1, E2, E3->hash, E4)
> + resolve_ref_unsafe(E1, E2, E3, E4)
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  blame.c                   |  4 ++--
>  builtin/fsck.c            |  2 +-
>  refs.c                    | 28 ++++++++++++++--------------
>  refs.h                    |  4 ++--
>  refs/files-backend.c      |  8 ++++----
>  sequencer.c               |  2 +-
>  t/helper/test-ref-store.c |  6 +++---
>  transport-helper.c        |  7 +++----
>  worktree.c                |  2 +-
>  9 files changed, 31 insertions(+), 32 deletions(-)
> 
> [...]
> diff --git a/refs.h b/refs.h
> index bb0dcd97af..4eedc880c6 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -62,10 +62,10 @@ struct worktree;

The docstring above this hunk needs to be adjusted.

>  const char *refs_resolve_ref_unsafe(struct ref_store *refs,
>  				    const char *refname,
>  				    int resolve_flags,
> -				    unsigned char *sha1,
> +				    struct object_id *oid,
>  				    int *flags);
>  const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
> -			       unsigned char *sha1, int *flags);
> +			       struct object_id *oid, int *flags);
>  
>  char *refs_resolve_refdup(struct ref_store *refs,
>  			  const char *refname, int resolve_flags,
> [...]
Michael

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 23/24] refs: convert read_raw_ref backends to struct object_id
  2017-10-09  1:11 ` [PATCH v2 23/24] refs: convert read_raw_ref backends " brian m. carlson
@ 2017-10-11  8:30   ` Michael Haggerty
  0 siblings, 0 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  8:30 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Convert the unsigned char * parameter to struct object_id * for
> files_read_raw_ref and packed_read_raw-ref.  Update the documentation.

Nit:

s/packed_read_raw-ref/packed_read_raw_ref/

> Switch from using get_sha1_hex and a hard-coded 40 to using
> parse_oid_hex.
> [...]

Michael

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 24/24] refs/files-backend: convert static functions to object_id
  2017-10-09  1:11 ` [PATCH v2 24/24] refs/files-backend: convert static functions to " brian m. carlson
@ 2017-10-11  8:36   ` Michael Haggerty
  0 siblings, 0 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11  8:36 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> Convert several static functions to take pointers to struct object_id.
> Change the relevant parameters to write_packed_entry to be const, as we
> don't modify them.  Rename lock_ref_sha1_basic to lock_ref_oid_basic to
> reflect its new argument.
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  refs/files-backend.c | 48 ++++++++++++++++++++++++------------------------
>  1 file changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 7281f27f62..84d8e3da99 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -811,7 +811,7 @@ static struct ref_iterator *files_ref_iterator_begin(
>   * return a negative value.
>   */

The docstring for this function needs adjusting. It would also be worth
mentioning that `old_oid` is allowed to be NULL (which was true before
but wasn't mentioned).

> [...]

Michael


^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
                   ` (25 preceding siblings ...)
  2017-10-09 22:44 ` Junio C Hamano
@ 2017-10-11 10:05 ` Michael Haggerty
  2017-10-11 10:42   ` Junio C Hamano
  2017-10-12  8:46   ` brian m. carlson
  26 siblings, 2 replies; 53+ messages in thread
From: Michael Haggerty @ 2017-10-11 10:05 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Brandon Williams, Stefan Beller

On 10/09/2017 03:11 AM, brian m. carlson wrote:
> This is the tenth in a series of patches to convert from unsigned char
> [20] to struct object_id.  This series mostly involves changes to the
> refs code.  After these changes, there are almost no references to
> unsigned char in the main refs code.
> 
> The series has not been rebased on master since the last submission, but
> I can do so if that's more convenient.
> 
> This series is available from the following URL:
> https://github.com/bk2204/git.git object-id-part10

I read through the whole series medium-thoroughly and left a few
comments, but overall it looks very good and clear. Thanks so much for
working on this!

I took a stab at rebasing this patch series on top of current master
using `git-imerge`. I pushed the results to my GitHub fork [1] as branch
`object-id-part-10-rebased`. I didn't check the results very carefully,
nor whether the commit messages need adjusting, but I did verify that
each of the commits passes the test suite. Junio, it might serve as
something to compare against your conflict resolution.

Michael

[1] https://github.com/mhagger/git

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-11 10:05 ` Michael Haggerty
@ 2017-10-11 10:42   ` Junio C Hamano
  2017-10-12  8:46   ` brian m. carlson
  1 sibling, 0 replies; 53+ messages in thread
From: Junio C Hamano @ 2017-10-11 10:42 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: brian m. carlson, git, Jeff King, Brandon Williams, Stefan Beller

Michael Haggerty <mhagger@alum.mit.edu> writes:

> I took a stab at rebasing this patch series on top of current master
> using `git-imerge`. I pushed the results to my GitHub fork [1] as branch
> `object-id-part-10-rebased`. I didn't check the results very carefully,
> nor whether the commit messages need adjusting, but I did verify that
> each of the commits passes the test suite. Junio, it might serve as
> something to compare against your conflict resolution.
>
> Michael
>
> [1] https://github.com/mhagger/git

2f0e14e6 ("Merge branch 'js/rebase-i-final'", 2017-10-09) is where
your -rebased series has forked from the mainline.  I checked that
fork-point out, merged bc/object-id I queued to it, with the help
from rerere I earlier taught.  The resulting tree was identical to
the tip of your rebase.

So hopefully both of us should be good ;-)  I do not know about the
intermediate steps, though.

Thanks.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use struct object_id
  2017-10-11  6:33   ` Michael Haggerty
@ 2017-10-12  8:42     ` brian m. carlson
  0 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-12  8:42 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: git, Jeff King, Brandon Williams, Stefan Beller, David Turner

[-- Attachment #1: Type: text/plain, Size: 1709 bytes --]

On Wed, Oct 11, 2017 at 08:33:46AM +0200, Michael Haggerty wrote:
> On 10/09/2017 03:11 AM, brian m. carlson wrote:
> > diff --git a/refs.c b/refs.c
> > index 0a5b68d6fb..51942df7b3 100644
> > --- a/refs.c
> > +++ b/refs.c
> > [...]
> > @@ -1003,12 +995,12 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
> >  	int ret = 0;
> >  
> >  	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
> > -		assert(refs == get_main_ref_store());
> 
> Was the deletion of the line above intentional?

No, that would not have been intentional.  (I would have mentioned it in
the commit message if it were.)  I probably accidentally deleted a line
in my editor.  Will fix.

> > -		ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
> > +		ret = write_pseudoref(refname, new_oid, old_oid, &err);
> 
> This is not new to your code, but I just noticed a problem here.
> `refs_update_ref()` is documented, via its reference to
> `ref_transaction_update()`, to allow `new_sha1` (i.e., now `new_oid`) to
> be NULL. (NULL signifies that the value of the reference shouldn't be
> changed.)
> 
> But `write_pseudoref()` dereferences its `oid` argument unconditionally,
> so this call would fail if `new_oid` is NULL.
> 
> This has all been the case since `write_pseudoref()` was introduced in
> 74ec19d4be (pseudorefs: create and use pseudoref update and delete
> functions, 2015-07-31).
> 
> In my opinion, `write_pseudoref()` is broken. It should accept NULL as
> its `oid` argument.

I can stuff a patch in for that.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 867 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-11 10:05 ` Michael Haggerty
  2017-10-11 10:42   ` Junio C Hamano
@ 2017-10-12  8:46   ` brian m. carlson
  2017-10-12  9:58     ` Junio C Hamano
  1 sibling, 1 reply; 53+ messages in thread
From: brian m. carlson @ 2017-10-12  8:46 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: git, Jeff King, Brandon Williams, Stefan Beller

[-- Attachment #1: Type: text/plain, Size: 1259 bytes --]

On Wed, Oct 11, 2017 at 12:05:50PM +0200, Michael Haggerty wrote:
> On 10/09/2017 03:11 AM, brian m. carlson wrote:
> > This is the tenth in a series of patches to convert from unsigned char
> > [20] to struct object_id.  This series mostly involves changes to the
> > refs code.  After these changes, there are almost no references to
> > unsigned char in the main refs code.
> > 
> > The series has not been rebased on master since the last submission, but
> > I can do so if that's more convenient.
> > 
> > This series is available from the following URL:
> > https://github.com/bk2204/git.git object-id-part10
> 
> I read through the whole series medium-thoroughly and left a few
> comments, but overall it looks very good and clear. Thanks so much for
> working on this!

Thanks for pointing out the places where I forgot to update the
docstrings.  I'll plan another reroll with those changes and the other
issues mentioned about the accidental deletion.

In the course of that, I'll rebase on top of master so that Junio can
avoid as much conflict resolution as possible.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 867 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-12  8:46   ` brian m. carlson
@ 2017-10-12  9:58     ` Junio C Hamano
  2017-10-12 10:22       ` brian m. carlson
  0 siblings, 1 reply; 53+ messages in thread
From: Junio C Hamano @ 2017-10-12  9:58 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Michael Haggerty, git, Jeff King, Brandon Williams, Stefan Beller

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

> In the course of that, I'll rebase on top of master so that Junio can
> avoid as much conflict resolution as possible.

I actually do not mind either way, but by rebasing on top of a more
recent codebase you can lose a large part of 07/24 IIRC, which would
be a big plus ;-)

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [PATCH v2 00/24] object_id part 10
  2017-10-12  9:58     ` Junio C Hamano
@ 2017-10-12 10:22       ` brian m. carlson
  0 siblings, 0 replies; 53+ messages in thread
From: brian m. carlson @ 2017-10-12 10:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michael Haggerty, git, Jeff King, Brandon Williams, Stefan Beller

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

On Thu, Oct 12, 2017 at 06:58:49PM +0900, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > In the course of that, I'll rebase on top of master so that Junio can
> > avoid as much conflict resolution as possible.
> 
> I actually do not mind either way, but by rebasing on top of a more
> recent codebase you can lose a large part of 07/24 IIRC, which would
> be a big plus ;-)

Yes, I just noticed that.  The patch used to be bigger still, but as I
mentioned in the original cover letter, a lot of it went away due to
previous work in that area.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 867 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, back to index

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-09  1:11 [PATCH v2 00/24] object_id part 10 brian m. carlson
2017-10-09  1:11 ` [PATCH v2 01/24] walker: convert to struct object_id brian m. carlson
2017-10-09 22:37   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 02/24] refs/files-backend: convert struct ref_to_prune to " brian m. carlson
2017-10-09 22:38   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 03/24] refs: convert delete_ref and refs_delete_ref to struct " brian m. carlson
2017-10-09 22:43   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 04/24] refs: convert update_ref and refs_update_ref to use " brian m. carlson
2017-10-09 22:57   ` Jonathan Nieder
2017-10-11  6:33   ` Michael Haggerty
2017-10-12  8:42     ` brian m. carlson
2017-10-09  1:11 ` [PATCH v2 05/24] refs: update ref transactions " brian m. carlson
2017-10-09 23:13   ` Jonathan Nieder
2017-10-11  6:58   ` Michael Haggerty
2017-10-09  1:11 ` [PATCH v2 06/24] Convert check_connected " brian m. carlson
2017-10-09 23:20   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 07/24] refs: convert resolve_refdup and refs_resolve_refdup to " brian m. carlson
2017-10-09 23:36   ` Jonathan Nieder
2017-10-10  1:16   ` Junio C Hamano
2017-10-09  1:11 ` [PATCH v2 08/24] refs: convert read_ref and read_ref_full to " brian m. carlson
2017-10-10  1:35   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 09/24] refs: convert dwim_ref and expand_ref to struct " brian m. carlson
2017-10-10  2:03   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 10/24] builtin/reflog: convert remaining unsigned char uses to " brian m. carlson
2017-10-10  2:15   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 11/24] refs: convert dwim_log to struct " brian m. carlson
2017-10-10  2:18   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 12/24] pack-bitmap: convert traverse_bitmap_commit_list to " brian m. carlson
2017-10-10  2:19   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 13/24] builtin/pack-objects: convert to struct " brian m. carlson
2017-10-10  2:24   ` Jonathan Nieder
2017-10-09  1:11 ` [PATCH v2 14/24] refs: convert peel_ref " brian m. carlson
2017-10-11  8:00   ` Michael Haggerty
2017-10-09  1:11 ` [PATCH v2 15/24] refs: convert read_ref_at " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 16/24] refs: convert reflog_expire parameter " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 17/24] sha1_file: convert index_path and index_fd " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 18/24] Convert remaining callers of resolve_gitlink_ref to " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 19/24] refs: convert resolve_gitlink_ref to struct " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 20/24] worktree: convert struct worktree to " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 21/24] refs: convert resolve_ref_unsafe to struct " brian m. carlson
2017-10-11  8:23   ` Michael Haggerty
2017-10-09  1:11 ` [PATCH v2 22/24] refs: convert peel_object " brian m. carlson
2017-10-09  1:11 ` [PATCH v2 23/24] refs: convert read_raw_ref backends " brian m. carlson
2017-10-11  8:30   ` Michael Haggerty
2017-10-09  1:11 ` [PATCH v2 24/24] refs/files-backend: convert static functions to " brian m. carlson
2017-10-11  8:36   ` Michael Haggerty
2017-10-09 18:00 ` [PATCH v2 00/24] object_id part 10 Stefan Beller
2017-10-09 22:44 ` Junio C Hamano
2017-10-11 10:05 ` Michael Haggerty
2017-10-11 10:42   ` Junio C Hamano
2017-10-12  8:46   ` brian m. carlson
2017-10-12  9:58     ` Junio C Hamano
2017-10-12 10:22       ` brian m. carlson

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox