From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>
Subject: [PATCH 10/10] packfile: drop nth_packed_object_sha1()
Date: Sun, 23 Feb 2020 23:37:54 -0500 [thread overview]
Message-ID: <20200224043754.GJ1018190@coredump.intra.peff.net> (raw)
In-Reply-To: <20200224042625.GA1015553@coredump.intra.peff.net>
Once upon a time, nth_packed_object_sha1() was the primary way to get
the oid of a packfile's index position. But these days we have the more
type-safe nth_packed_object_id() wrapper, and all callers have been
converted.
Let's drop the "sha1" version (turning the safer wrapper into a single
function) so that nobody is tempted to introduce new callers.
Signed-off-by: Jeff King <peff@peff.net>
---
packfile.c | 23 +++++++----------------
packfile.h | 12 +++---------
2 files changed, 10 insertions(+), 25 deletions(-)
diff --git a/packfile.c b/packfile.c
index 90cb5a05ac..f4e752996d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1867,35 +1867,26 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32
index_lookup, index_lookup_width, result);
}
-const unsigned char *nth_packed_object_sha1(struct packed_git *p,
- uint32_t n)
+int nth_packed_object_id(struct object_id *oid,
+ struct packed_git *p,
+ uint32_t n)
{
const unsigned char *index = p->index_data;
const unsigned int hashsz = the_hash_algo->rawsz;
if (!index) {
if (open_pack_index(p))
- return NULL;
+ return -1;
index = p->index_data;
}
if (n >= p->num_objects)
- return NULL;
+ return -1;
index += 4 * 256;
if (p->index_version == 1) {
- return index + (hashsz + 4) * n + 4;
+ oidread(oid, index + (hashsz + 4) * n + 4);
} else {
index += 8;
- return index + hashsz * n;
+ oidread(oid, index + hashsz * n);
}
-}
-
-int nth_packed_object_id(struct object_id *oid,
- struct packed_git *p,
- uint32_t n)
-{
- const unsigned char *hash = nth_packed_object_sha1(p, n);
- if (!hash)
- return -1;
- hashcpy(oid->hash, hash);
return 0;
}
diff --git a/packfile.h b/packfile.h
index 95b83ba25b..240aa73b95 100644
--- a/packfile.h
+++ b/packfile.h
@@ -121,15 +121,9 @@ void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result);
/*
- * Return the SHA-1 of the nth object within the specified packfile.
- * Open the index if it is not already open. The return value points
- * at the SHA-1 within the mmapped index. Return NULL if there is an
- * error.
- */
-const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
-/*
- * Like nth_packed_object_sha1, but write the data into the object specified by
- * the the first argument. Returns 0 on success, negative otherwise.
+ * Write the oid of the nth object within the specified packfile into the first
+ * parameter. Open the index if it is not already open. Returns 0 on success,
+ * negative otherwise.
*/
int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n);
--
2.25.1.823.g95c5488cf7
next prev parent reply other threads:[~2020-02-24 4:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 4:26 [PATCH 0/10] removing nth_packed_object_sha1() Jeff King
2020-02-24 4:27 ` [PATCH 01/10] nth_packed_object_oid(): use customary integer return Jeff King
2020-02-24 18:23 ` Jeff King
2020-02-24 4:29 ` [PATCH 02/10] pack-objects: read delta base oid into object_id struct Jeff King
2020-02-25 0:19 ` brian m. carlson
2020-02-24 4:30 ` [PATCH 03/10] pack-objects: convert oe_set_delta_ext() to use object_id Jeff King
2020-02-24 4:31 ` [PATCH 04/10] pack-objects: use object_id struct in pack-reuse code Jeff King
2020-02-24 4:32 ` [PATCH 05/10] pack-bitmap: use object_id when loading on-disk bitmaps Jeff King
2020-02-24 4:33 ` [PATCH 06/10] pack-check: convert "internal error" die to a BUG() Jeff King
2020-02-24 4:36 ` [PATCH 07/10] pack-check: push oid lookup into loop Jeff King
2020-02-24 4:36 ` [PATCH 08/10] packed_object_info(): use object_id for returning delta base Jeff King
2020-02-24 4:37 ` [PATCH 09/10] packed_object_info(): use object_id internally for " Jeff King
2020-02-24 4:37 ` Jeff King [this message]
2020-02-25 0:33 ` [PATCH 0/10] removing nth_packed_object_sha1() 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=20200224043754.GJ1018190@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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 NNTP newsgroup(s).