All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Michael Haggerty" <mhagger@alum.mit.edu>,
	"Stefan Beller" <sbeller@google.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 38/53] refs: convert struct ref_update to use struct object_id
Date: Mon,  1 May 2017 02:29:31 +0000	[thread overview]
Message-ID: <20170501022946.258735-39-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170501022946.258735-1-sandals@crustytoothpaste.net>

Convert struct ref_array_item to use struct object_id by changing the
definition and applying the following semantic patch, plus the standard
object_id transforms:

@@
struct ref_update E1;
@@
- E1.new_sha1
+ E1.new_oid.hash

@@
struct ref_update *E1;
@@
- E1->new_sha1
+ E1->new_oid.hash

@@
struct ref_update E1;
@@
- E1.old_sha1
+ E1.old_oid.hash

@@
struct ref_update *E1;
@@
- E1->old_sha1
+ E1->old_oid.hash

This transformation allows us to convert write_ref_to_lockfile, which is
required to convert parse_object.

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

diff --git a/refs.c b/refs.c
index df75f8e0d..c738f5911 100644
--- a/refs.c
+++ b/refs.c
@@ -882,9 +882,9 @@ struct ref_update *ref_transaction_add_update(
 	update->flags = flags;
 
 	if (flags & REF_HAVE_NEW)
-		hashcpy(update->new_sha1, new_sha1);
+		hashcpy(update->new_oid.hash, new_sha1);
 	if (flags & REF_HAVE_OLD)
-		hashcpy(update->old_sha1, old_sha1);
+		hashcpy(update->old_oid.hash, old_sha1);
 	update->msg = xstrdup_or_null(msg);
 	return update;
 }
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 298a838c5..413505ff0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2633,7 +2633,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_sha1, update->old_sha1,
+			update->new_oid.hash, update->old_oid.hash,
 			update->msg);
 
 	item->util = new_update;
@@ -2690,7 +2690,7 @@ static int split_symref_update(struct files_ref_store *refs,
 
 	new_update = ref_transaction_add_update(
 			transaction, referent, new_flags,
-			update->new_sha1, update->old_sha1,
+			update->new_oid.hash, update->old_oid.hash,
 			update->msg);
 
 	new_update->parent_update = update;
@@ -2729,10 +2729,10 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
 			 struct strbuf *err)
 {
 	if (!(update->flags & REF_HAVE_OLD) ||
-		   !hashcmp(oid->hash, update->old_sha1))
+		   !oidcmp(oid, &update->old_oid))
 		return 0;
 
-	if (is_null_sha1(update->old_sha1))
+	if (is_null_oid(&update->old_oid))
 		strbuf_addf(err, "cannot lock ref '%s': "
 			    "reference already exists",
 			    original_update_refname(update));
@@ -2740,13 +2740,13 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
 		strbuf_addf(err, "cannot lock ref '%s': "
 			    "reference is missing but expected %s",
 			    original_update_refname(update),
-			    sha1_to_hex(update->old_sha1));
+			    oid_to_hex(&update->old_oid));
 	else
 		strbuf_addf(err, "cannot lock ref '%s': "
 			    "is at %s but expected %s",
 			    original_update_refname(update),
 			    oid_to_hex(oid),
-			    sha1_to_hex(update->old_sha1));
+			    oid_to_hex(&update->old_oid));
 
 	return -1;
 }
@@ -2773,13 +2773,13 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 {
 	struct strbuf referent = STRBUF_INIT;
 	int mustexist = (update->flags & REF_HAVE_OLD) &&
-		!is_null_sha1(update->old_sha1);
+		!is_null_oid(&update->old_oid);
 	int ret;
 	struct ref_lock *lock;
 
 	files_assert_main_repository(refs, "lock_ref_for_update");
 
-	if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
+	if ((update->flags & REF_HAVE_NEW) && is_null_oid(&update->new_oid))
 		update->flags |= REF_DELETING;
 
 	if (head_ref) {
@@ -2861,12 +2861,12 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 	    !(update->flags & REF_DELETING) &&
 	    !(update->flags & REF_LOG_ONLY)) {
 		if (!(update->type & REF_ISSYMREF) &&
-		    !hashcmp(lock->old_oid.hash, update->new_sha1)) {
+		    !oidcmp(&lock->old_oid, &update->new_oid)) {
 			/*
 			 * The reference already has the desired
 			 * value, so we don't need to write it.
 			 */
-		} else if (write_ref_to_lockfile(lock, update->new_sha1,
+		} else if (write_ref_to_lockfile(lock, update->new_oid.hash,
 						 err)) {
 			char *write_err = strbuf_detach(err, NULL);
 
@@ -3002,7 +3002,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
 			if (files_log_ref_write(refs,
 						lock->ref_name,
 						lock->old_oid.hash,
-						update->new_sha1,
+						update->new_oid.hash,
 						update->msg, update->flags,
 						err)) {
 				char *old_msg = strbuf_detach(err, NULL);
@@ -3151,7 +3151,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
 		struct ref_update *update = transaction->updates[i];
 
 		if ((update->flags & REF_HAVE_OLD) &&
-		    !is_null_sha1(update->old_sha1))
+		    !is_null_oid(&update->old_oid))
 			die("BUG: initial ref transaction with old_sha1 set");
 		if (refs_verify_refname_available(&refs->base, update->refname,
 						  &affected_refnames, NULL,
@@ -3172,8 +3172,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
 		struct ref_update *update = transaction->updates[i];
 
 		if ((update->flags & REF_HAVE_NEW) &&
-		    !is_null_sha1(update->new_sha1))
-			add_packed_ref(refs, update->refname, update->new_sha1);
+		    !is_null_oid(&update->new_oid))
+			add_packed_ref(refs, update->refname,
+				       update->new_oid.hash);
 	}
 
 	if (commit_packed_refs(refs)) {
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 3d46131ef..b267d5ca9 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -130,13 +130,13 @@ struct ref_update {
 	/*
 	 * If (flags & REF_HAVE_NEW), set the reference to this value:
 	 */
-	unsigned char new_sha1[20];
+	struct object_id new_oid;
 
 	/*
 	 * If (flags & REF_HAVE_OLD), check that the reference
 	 * previously had this value:
 	 */
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 
 	/*
 	 * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF,

  parent reply	other threads:[~2017-05-01  2:32 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-01  2:28 [PATCH v2 00/53] object_id part 8 brian m. carlson
2017-05-01  2:28 ` [PATCH v2 01/53] fetch-pack: convert to struct object_id brian m. carlson
2017-05-01  2:28 ` [PATCH v2 02/53] Clean up outstanding object_id transforms brian m. carlson
2017-05-02 18:05   ` Brandon Williams
2017-05-03 23:41     ` brian m. carlson
2017-05-01  2:28 ` [PATCH v2 03/53] Convert struct cache_tree to use struct object_id brian m. carlson
2017-05-02 18:13   ` Brandon Williams
2017-05-03 23:36     ` brian m. carlson
2017-05-01  2:28 ` [PATCH v2 04/53] builtin/name-rev: convert to " brian m. carlson
2017-05-01  2:28 ` [PATCH v2 05/53] builtin/prune: " brian m. carlson
2017-05-01  2:28 ` [PATCH v2 06/53] bundle: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 07/53] branch: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 08/53] builtin/blame: convert static function " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 09/53] builtin/rev-parse: convert " brian m. carlson
2017-05-01 21:54   ` Jonathan Tan
2017-05-01  2:29 ` [PATCH v2 10/53] fast-import: convert internal structs " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 11/53] fast-import: convert " brian m. carlson
2017-05-01 22:07   ` Jonathan Tan
2017-05-01 22:27     ` Jeff King
2017-05-01 22:36       ` Jonathan Tan
2017-05-03 23:34       ` brian m. carlson
2017-05-01  2:29 ` [PATCH v2 12/53] submodule: convert merge_submodule to use " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 13/53] notes-cache: convert to " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 14/53] parse-options-cb: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 15/53] reflog_expire: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 16/53] builtin/verify-commit: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 17/53] tag: convert parse_tag_buffer " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 18/53] http-push: convert some static functions " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 19/53] notes-utils: convert internals " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 20/53] revision: convert prepare_show_merge " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 21/53] shallow: convert shallow registration functions to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 22/53] sequencer: convert some functions to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 23/53] builtin/tag: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 24/53] Convert remaining callers of lookup_commit_reference* to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 25/53] Convert lookup_commit* to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 26/53] pack: convert struct pack_idx_entry " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 27/53] builtin/unpack-objects: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 28/53] Convert remaining callers of lookup_blob to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 29/53] Convert lookup_blob to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 30/53] tree: convert read_tree_1 to use struct object_id internally brian m. carlson
2017-05-01  2:29 ` [PATCH v2 31/53] builtin/reflog: convert tree_is_complete to take struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 32/53] Convert lookup_tree to " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 33/53] log-tree: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 34/53] Convert lookup_tag " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 35/53] Convert the verify_pack callback " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 36/53] Convert struct ref_array_item " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 37/53] ref-filter: convert some static functions " brian m. carlson
2017-05-01  2:29 ` brian m. carlson [this message]
2017-05-01  2:29 ` [PATCH v2 39/53] refs/files-backend: convert many internals " brian m. carlson
2017-05-01 23:24   ` Jonathan Tan
2017-05-03 23:30     ` brian m. carlson
2017-05-01  2:29 ` [PATCH v2 40/53] http-push: convert process_ls_object and descendants to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 41/53] revision: rename add_pending_sha1 to add_pending_oid brian m. carlson
2017-05-01  2:29 ` [PATCH v2 42/53] revision: convert remaining parse_object callers to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 43/53] upload-pack: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 44/53] sha1_name: convert internals of peel_onion " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 45/53] builtin/read-tree: convert to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 46/53] builtin/ls-files: convert overlay_tree_on_cache to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 47/53] sequencer: convert fast_forward_to to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 48/53] merge: convert checkout_fast_forward " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 49/53] builtin/ls-tree: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 50/53] diff-lib: convert do_diff_cache " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 51/53] sequencer: convert do_recursive_merge " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 52/53] tree: convert parse_tree_indirect " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 53/53] object: convert parse_object* to take " brian m. carlson
2017-05-01 23:44   ` Jonathan Tan
2017-05-01 21:10 ` [PATCH v2 00/53] object_id part 8 Stefan Beller
2017-05-02 19:09 ` Brandon Williams
2017-05-04  0:50 ` brian m. carlson

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20170501022946.258735-39-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.