git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
	Stefan Beller <stefanbeller@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH 06/12] builtin/update_ref: convert to struct object_id
Date: Mon,  3 Jul 2017 18:55:27 +0000	[thread overview]
Message-ID: <20170703185533.51530-7-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170703185533.51530-1-sandals@crustytoothpaste.net>

Convert the uses of unsigned char * to struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/update-ref.c | 69 ++++++++++++++++++++++++++--------------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 40ccfc193..6b90c5dea 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -94,10 +94,10 @@ static char *parse_refname(struct strbuf *input, const char **next)
  * provided but cannot be converted to a SHA-1, die.  flags can
  * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
  */
-static int parse_next_sha1(struct strbuf *input, const char **next,
-			   unsigned char *sha1,
-			   const char *command, const char *refname,
-			   int flags)
+static int parse_next_oid(struct strbuf *input, const char **next,
+			  struct object_id *oid,
+			  const char *command, const char *refname,
+			  int flags)
 {
 	struct strbuf arg = STRBUF_INIT;
 	int ret = 0;
@@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
 		(*next)++;
 		*next = parse_arg(*next, &arg);
 		if (arg.len) {
-			if (get_sha1(arg.buf, sha1))
+			if (get_oid(arg.buf, oid))
 				goto invalid;
 		} else {
 			/* Without -z, an empty value means all zeros: */
-			hashclr(sha1);
+			oidclr(oid);
 		}
 	} else {
 		/* With -z, read the next NUL-terminated line */
@@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
 		*next += arg.len;
 
 		if (arg.len) {
-			if (get_sha1(arg.buf, sha1))
+			if (get_oid(arg.buf, oid))
 				goto invalid;
 		} else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
 			/* With -z, treat an empty value as all zeros: */
 			warning("%s %s: missing <newvalue>, treating as zero",
 				command, refname);
-			hashclr(sha1);
+			oidclr(oid);
 		} else {
 			/*
 			 * With -z, an empty non-required value means
@@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char new_sha1[20];
-	unsigned char old_sha1[20];
+	struct object_id new_oid, old_oid;
 	int have_old;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("update: missing <ref>");
 
-	if (parse_next_sha1(input, &next, new_sha1, "update", refname,
-			    PARSE_SHA1_ALLOW_EMPTY))
+	if (parse_next_oid(input, &next, &new_oid, "update", refname,
+			   PARSE_SHA1_ALLOW_EMPTY))
 		die("update %s: missing <newvalue>", refname);
 
-	have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname,
-				    PARSE_SHA1_OLD);
+	have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
+				   PARSE_SHA1_OLD);
 
 	if (*next != line_termination)
 		die("update %s: extra input: %s", refname, next);
 
 	if (ref_transaction_update(transaction, refname,
-				   new_sha1, have_old ? old_sha1 : NULL,
+				   new_oid.hash, have_old ? old_oid.hash : NULL,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char new_sha1[20];
+	struct object_id new_oid;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("create: missing <ref>");
 
-	if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0))
+	if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
 		die("create %s: missing <newvalue>", refname);
 
-	if (is_null_sha1(new_sha1))
+	if (is_null_oid(&new_oid))
 		die("create %s: zero <newvalue>", refname);
 
 	if (*next != line_termination)
 		die("create %s: extra input: %s", refname, next);
 
-	if (ref_transaction_create(transaction, refname, new_sha1,
+	if (ref_transaction_create(transaction, refname, new_oid.hash,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 	int have_old;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("delete: missing <ref>");
 
-	if (parse_next_sha1(input, &next, old_sha1, "delete", refname,
-			    PARSE_SHA1_OLD)) {
+	if (parse_next_oid(input, &next, &old_oid, "delete", refname,
+			   PARSE_SHA1_OLD)) {
 		have_old = 0;
 	} else {
-		if (is_null_sha1(old_sha1))
+		if (is_null_oid(&old_oid))
 			die("delete %s: zero <oldvalue>", refname);
 		have_old = 1;
 	}
@@ -270,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_sha1 : NULL,
+				   have_old ? old_oid.hash : NULL,
 				   update_flags, msg, &err))
 		die("%s", err.buf);
 
@@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("verify: missing <ref>");
 
-	if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
-			    PARSE_SHA1_OLD))
-		hashclr(old_sha1);
+	if (parse_next_oid(input, &next, &old_oid, "verify", refname,
+			   PARSE_SHA1_OLD))
+		oidclr(&old_oid);
 
 	if (*next != line_termination)
 		die("verify %s: extra input: %s", refname, next);
 
-	if (ref_transaction_verify(transaction, refname, old_sha1,
+	if (ref_transaction_verify(transaction, refname, old_oid.hash,
 				   update_flags, &err))
 		die("%s", err.buf);
 
@@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
 int cmd_update_ref(int argc, const char **argv, const char *prefix)
 {
 	const char *refname, *oldval;
-	unsigned char sha1[20], oldsha1[20];
+	struct object_id oid, oldoid;
 	int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
 	unsigned int flags = 0;
 	int create_reflog = 0;
@@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 		refname = argv[0];
 		value = argv[1];
 		oldval = argv[2];
-		if (get_sha1(value, sha1))
+		if (get_oid(value, &oid))
 			die("%s: not a valid SHA1", value);
 	}
 
@@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 			 * The empty string implies that the reference
 			 * must not already exist:
 			 */
-			hashclr(oldsha1);
-		else if (get_sha1(oldval, oldsha1))
+			oidclr(&oldoid);
+		else if (get_oid(oldval, &oldoid))
 			die("%s: not a valid old SHA1", oldval);
 	}
 
@@ -435,10 +434,10 @@ 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_sha1(oldsha1)) ? oldsha1 : NULL,
+				  (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
 				  flags);
 	else
-		return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
+		return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
 				  flags | create_reflog_flag,
 				  UPDATE_REFS_DIE_ON_ERR);
 }

  parent reply	other threads:[~2017-07-03 18:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
2017-07-03 18:55 ` [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 02/12] builtin/merge-tree: " brian m. carlson
2017-07-03 18:55 ` [PATCH 03/12] submodule: convert submodule config lookup to use object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 04/12] remote: convert struct push_cas to struct object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 05/12] sequencer: convert " brian m. carlson
2017-07-03 18:55 ` brian m. carlson [this message]
2017-07-03 20:49   ` [PATCH 06/12] builtin/update_ref: " Ævar Arnfjörð Bjarmason
2017-07-04 14:45     ` brian m. carlson
2017-07-03 18:55 ` [PATCH 07/12] bisect: convert bisect_checkout " brian m. carlson
2017-07-03 18:55 ` [PATCH 08/12] builtin/unpack-file: convert " brian m. carlson
2017-07-03 18:55 ` [PATCH 09/12] builtin/verify-tag: " brian m. carlson
2017-07-03 18:55 ` [PATCH 10/12] Convert remaining callers of get_sha1 to get_oid brian m. carlson
2017-07-03 18:55 ` [PATCH 11/12] sha1_name: convert get_sha1* to get_oid* brian m. carlson
2017-07-05 18:01   ` Stefan Beller
2017-07-05 18:38     ` Junio C Hamano
2017-07-07 21:22       ` brian m. carlson
2017-07-03 18:55 ` [PATCH 12/12] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
2017-07-05  4:10 ` [PATCH 00/12] object_id part 9 Junio C Hamano
2017-07-05 18:02   ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170703185533.51530-7-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=stefanbeller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).