git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Han Xin" <chiyutianyi@gmail.com>,
	"Jiang Xin" <worldhello.net@gmail.com>,
	"René Scharfe" <l.s.r@web.de>,
	"Derrick Stolee" <stolee@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 06/10] object-file API: replace some use of check_object_signature()
Date: Tue,  1 Feb 2022 15:53:08 +0100	[thread overview]
Message-ID: <patch-06.10-2a065bf23da-20220201T144803Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.10-00000000000-20220201T144803Z-avarab@gmail.com>

Add a "hash_object_file_literally()" function to go with the existing
"hash_object_file()" function. This is currently a wrapper for its
sibling, but this change will allow us to change it to take an "enum
object_type" in a subsequent commit.

The only caller that wanted to pass a custom type to
"check_object_signature()" was the "git fsck" via its
"read_loose_object()", which is being changed here.

There was an existing hash_object_file_literally() which I'm renaming
to "hash_write_object_file_literally()", that function is only used
for "hash-object --literally". That renaming is being done because it
would be confusing to have a "hash_object_file_literally()" and a
"hash_object_file()" that do very different things.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/hash-object.c |  4 ++--
 object-file.c         | 18 +++++++++++++-----
 object-store.h        |  6 +++---
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index c7b3ad74c60..624e9e677fb 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -25,8 +25,8 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig
 	if (strbuf_read(&buf, fd, 4096) < 0)
 		ret = -1;
 	else
-		ret = hash_object_file_literally(buf.buf, buf.len, type, oid,
-						 flags);
+		ret = hash_write_object_file_literally(buf.buf, buf.len, type, oid,
+						       flags);
 	strbuf_release(&buf);
 	return ret;
 }
diff --git a/object-file.c b/object-file.c
index 27d10112960..9fc959fa05d 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1862,6 +1862,13 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
 	write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
 }
 
+static void hash_object_file_literally(const struct git_hash_algo *algo, const void *buf,
+				       unsigned long len, const char *type,
+				       struct object_id *oid)
+{
+	hash_object_file(algo, buf, len, type, oid);
+}
+
 int hash_object_file_oideq(const struct git_hash_algo *algo, const void *buf,
 			   unsigned long len, enum object_type type,
 			   const struct object_id *oid,
@@ -2043,9 +2050,9 @@ int write_object_file_flags(const void *buf, unsigned long len,
 	return write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags);
 }
 
-int hash_object_file_literally(const void *buf, unsigned long len,
-			       const char *type, struct object_id *oid,
-			       unsigned flags)
+int hash_write_object_file_literally(const void *buf, unsigned long len,
+				     const char *type, struct object_id *oid,
+				     unsigned flags)
 {
 	char *header;
 	int hdrlen, status = 0;
@@ -2630,9 +2637,10 @@ int read_loose_object(const char *path,
 			git_inflate_end(&stream);
 			goto out;
 		}
-		if (check_object_signature(the_repository, expected_oid,
+		hash_object_file_literally(the_repository->hash_algo,
 					   *contents, *size,
-					   oi->type_name->buf, real_oid))
+					   oi->type_name->buf, real_oid);
+		if (!oideq(expected_oid, real_oid))
 			goto out;
 	}
 
diff --git a/object-store.h b/object-store.h
index 95907062682..2ddc20b3304 100644
--- a/object-store.h
+++ b/object-store.h
@@ -272,9 +272,9 @@ static inline int write_object_file(const void *buf, unsigned long len,
 	return write_object_file_flags(buf, len, type, oid, 0);
 }
 
-int hash_object_file_literally(const void *buf, unsigned long len,
-			       const char *type, struct object_id *oid,
-			       unsigned flags);
+int hash_write_object_file_literally(const void *buf, unsigned long len,
+				     const char *type, struct object_id *oid,
+				     unsigned flags);
 
 /*
  * Add an object file to the in-memory object store, without writing it
-- 
2.35.0.913.g12b4baa2536


  parent reply	other threads:[~2022-02-01 14:53 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 14:53 [PATCH 00/10] object-file API: pass object enums, tidy up streaming interface Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 01/10] object-file.c: split up declaration of unrelated variables Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 02/10] object-file API: return "void", not "int" from hash_object_file() Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 03/10] object-file API: add a format_object_header() function Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 04/10] object-file API: have write_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-01 18:58   ` Junio C Hamano
2022-02-01 14:53 ` [PATCH 05/10] object-file API: provide a hash_object_file_oideq() Ævar Arnfjörð Bjarmason
2022-02-01 19:08   ` Junio C Hamano
2022-02-01 20:56     ` Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` Ævar Arnfjörð Bjarmason [this message]
2022-02-01 19:16   ` [PATCH 06/10] object-file API: replace some use of check_object_signature() Junio C Hamano
2022-02-01 14:53 ` [PATCH 07/10] object-file API: have hash_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 08/10] object-file API: replace check_object_signature() with stream_* Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 09/10] object-file.c: add a literal version of write_object_file_prepare() Ævar Arnfjörð Bjarmason
2022-02-01 14:53 ` [PATCH 10/10] object-file API: pass an enum to read_object_with_reference() Ævar Arnfjörð Bjarmason
2022-02-04 13:51 ` [PATCH v2 00/11] object-file API: pass object enums, tidy up streaming interface Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 01/11] object-file.c: split up declaration of unrelated variables Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 02/11] object-file API: return "void", not "int" from hash_object_file() Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 03/11] object-file API: add a format_object_header() function Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 04/11] object-file API: have write_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-04 20:52     ` Junio C Hamano
2022-02-04 13:51   ` [PATCH v2 05/11] object API: correct "buf" v.s. "map" mismatch in *.c and *.h Ævar Arnfjörð Bjarmason
2022-02-04 20:54     ` Junio C Hamano
2022-02-04 13:51   ` [PATCH v2 06/11] object API: make check_object_signature() oideq()-like, move docs Ævar Arnfjörð Bjarmason
2022-02-04 21:15     ` Junio C Hamano
2022-02-04 13:51   ` [PATCH v2 07/11] object-file API: split up and simplify check_object_signature() Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 08/11] object API: rename hash_object_file_literally() to write_*() Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 09/11] object-file API: have hash_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 10/11] object-file.c: add a literal version of write_object_file_prepare() Ævar Arnfjörð Bjarmason
2022-02-04 13:51   ` [PATCH v2 11/11] object-file API: pass an enum to read_object_with_reference() Ævar Arnfjörð Bjarmason
2022-02-04 23:48   ` [PATCH v3 00/12] object-file API: pass object enums, tidy up streaming interface Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 01/12] object-file.c: split up declaration of unrelated variables Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 02/12] object-file API: return "void", not "int" from hash_object_file() Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 03/12] object-file API: add a format_object_header() function Ævar Arnfjörð Bjarmason
2022-02-17  4:59       ` Jiang Xin
2022-02-17  9:21         ` Ævar Arnfjörð Bjarmason
2022-03-01  3:09           ` Jiang Xin
2022-02-04 23:48     ` [PATCH v3 04/12] object-file API: have write_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 05/12] object API: correct "buf" v.s. "map" mismatch in *.c and *.h Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 06/12] object API docs: move check_object_signature() docs to cache.h Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 07/12] object API users + docs: check <0, not !0 with check_object_signature() Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 08/12] object-file API: split up and simplify check_object_signature() Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 09/12] object API: rename hash_object_file_literally() to write_*() Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 10/12] object-file API: have hash_object_file() take "enum object_type" Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 11/12] object-file.c: add a literal version of write_object_file_prepare() Ævar Arnfjörð Bjarmason
2022-02-04 23:48     ` [PATCH v3 12/12] object-file API: pass an enum to read_object_with_reference() Ævar Arnfjörð Bjarmason

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=patch-06.10-2a065bf23da-20220201T144803Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=chiyutianyi@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=stolee@gmail.com \
    --cc=worldhello.net@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).