From: "René Scharfe" <l.s.r@web.de>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 1/3] object-store: factor out odb_loose_cache()
Date: Sun, 6 Jan 2019 17:45:30 +0100 [thread overview]
Message-ID: <b87e7e01-baa6-6fb2-7081-0042ecd3b6b7@web.de> (raw)
In-Reply-To: <3512c798-aa42-6fba-ee82-d33a8985be91@web.de>
Add and use a function for loading the entries if a loose object
subdirectory for a given object ID. It frees callers from deriving the
fanout key; they can use the returned oid_array reference for lookups or
forward range scans.
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
object-store.h | 7 +++++++
sha1-file.c | 12 +++++++++---
sha1-name.c | 10 +++++-----
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/object-store.h b/object-store.h
index 60758efad8..7236c571c0 100644
--- a/object-store.h
+++ b/object-store.h
@@ -54,6 +54,13 @@ void add_to_alternates_memory(const char *dir);
*/
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr);
+/*
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
+ */
+struct oid_array *odb_loose_cache(struct object_directory *odb,
+ const struct object_id *oid);
+
struct packed_git {
struct packed_git *next;
struct list_head mru;
diff --git a/sha1-file.c b/sha1-file.c
index 5a272f70de..cb8583b634 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -924,7 +924,6 @@ static int open_sha1_file(struct repository *r,
static int quick_has_loose(struct repository *r,
const unsigned char *sha1)
{
- int subdir_nr = sha1[0];
struct object_id oid;
struct object_directory *odb;
@@ -932,8 +931,7 @@ static int quick_has_loose(struct repository *r,
prepare_alt_odb(r);
for (odb = r->objects->odb; odb; odb = odb->next) {
- odb_load_loose_cache(odb, subdir_nr);
- if (oid_array_lookup(&odb->loose_objects_cache, &oid) >= 0)
+ if (oid_array_lookup(odb_loose_cache(odb, &oid), &oid) >= 0)
return 1;
}
return 0;
@@ -2152,6 +2150,14 @@ static int append_loose_object(const struct object_id *oid, const char *path,
return 0;
}
+struct oid_array *odb_loose_cache(struct object_directory *odb,
+ const struct object_id *oid)
+{
+ int subdir_nr = oid->hash[0];
+ odb_load_loose_cache(odb, subdir_nr);
+ return &odb->loose_objects_cache;
+}
+
void odb_load_loose_cache(struct object_directory *odb, int subdir_nr)
{
struct strbuf buf = STRBUF_INIT;
diff --git a/sha1-name.c b/sha1-name.c
index b24502811b..a656481c6a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -87,21 +87,21 @@ static int match_sha(unsigned, const unsigned char *, const unsigned char *);
static void find_short_object_filename(struct disambiguate_state *ds)
{
- int subdir_nr = ds->bin_pfx.hash[0];
struct object_directory *odb;
for (odb = the_repository->objects->odb;
odb && !ds->ambiguous;
odb = odb->next) {
int pos;
+ struct oid_array *loose_objects;
- odb_load_loose_cache(odb, subdir_nr);
- pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx);
+ loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
+ pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
if (pos < 0)
pos = -1 - pos;
- while (!ds->ambiguous && pos < odb->loose_objects_cache.nr) {
+ while (!ds->ambiguous && pos < loose_objects->nr) {
const struct object_id *oid;
- oid = odb->loose_objects_cache.oid + pos;
+ oid = loose_objects->oid + pos;
if (!match_sha(ds->len, ds->bin_pfx.hash, oid->hash))
break;
update_candidates(ds, oid);
--
2.20.1
next prev parent reply other threads:[~2019-01-06 16:45 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-28 18:04 What's cooking in git.git (Dec 2018, #02; Fri, 28) Junio C Hamano
2018-12-28 18:23 ` Elijah Newren
2019-01-03 13:27 ` Johannes Schindelin
2019-01-07 17:13 ` Elijah Newren
2018-12-28 19:21 ` ag/sequencer-reduce-rewriting-todo, was " Alban Gruin
2018-12-28 20:28 ` Junio C Hamano
2018-12-29 12:08 ` Denton Liu
2019-01-03 13:23 ` ps/stash-in-c, was " Johannes Schindelin
2019-01-06 16:39 ` jk/loose-object-cache René Scharfe
2019-01-06 16:45 ` René Scharfe [this message]
2019-01-07 8:27 ` [PATCH 1/3] object-store: factor out odb_loose_cache() Jeff King
2019-01-07 13:26 ` René Scharfe
2019-01-07 17:29 ` René Scharfe
2019-01-07 11:27 ` Philip Oakley
2019-01-07 12:30 ` Jeff King
2019-01-07 13:11 ` René Scharfe
2019-01-06 16:45 ` [PATCH 2/3] object-store: factor out odb_clear_loose_cache() René Scharfe
2019-01-06 16:45 ` [PATCH 3/3] object-store: use one oid_array per subdirectory for loose cache René Scharfe
2019-01-06 20:38 ` Ævar Arnfjörð Bjarmason
2019-01-06 22:58 ` René Scharfe
2019-01-07 8:31 ` [PATCH 0/11] jk/loose-object-cache sha1/object_id fixups Jeff King
2019-01-07 8:33 ` [PATCH 01/11] sha1-file: fix outdated sha1 comment references Jeff King
2019-01-07 8:34 ` [PATCH 02/11] update comment references to sha1_object_info() Jeff King
2019-01-07 8:34 ` [PATCH 03/11] http: use struct object_id instead of bare sha1 Jeff King
2019-01-07 8:35 ` [PATCH 04/11] sha1-file: modernize loose object file functions Jeff King
2019-01-07 8:37 ` [PATCH 05/11] sha1-file: modernize loose header/stream functions Jeff King
2019-01-07 8:37 ` [PATCH 06/11] sha1-file: convert pass-through functions to object_id Jeff King
2019-01-07 8:37 ` [PATCH 07/11] convert has_sha1_file() callers to has_object_file() Jeff King
2019-01-07 8:39 ` [PATCH 08/11] sha1-file: drop has_sha1_file() Jeff King
2019-01-07 8:39 ` [PATCH 09/11] sha1-file: prefer "loose object file" to "sha1 file" in messages Jeff King
2019-01-07 8:39 ` [PATCH 10/11] sha1-file: avoid "sha1 file" for generic use " Jeff King
2019-01-07 8:40 ` [PATCH 11/11] prefer "hash mismatch" to "sha1 mismatch" Jeff King
2019-01-08 16:40 ` [PATCH 0/11] jk/loose-object-cache sha1/object_id fixups René Scharfe
2019-01-08 17:39 ` Junio C Hamano
2019-01-08 18:05 ` Jeff King
2019-01-08 18:07 ` Junio C Hamano
2019-01-08 18:27 ` Derrick Stolee
2019-01-08 18:52 ` Junio C Hamano
2019-01-08 21:16 ` Jeff King
2019-01-09 21:37 ` Stefan Beller
2019-01-09 22:42 ` Stefan Beller
2019-01-10 6:17 ` Jeff King
2019-01-07 17:29 ` [PATCH 4/3] object-store: retire odb_load_loose_cache() René Scharfe
2019-01-07 19:32 ` Junio C Hamano
2019-01-07 19:29 ` jk/loose-object-cache Junio C Hamano
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=b87e7e01-baa6-6fb2-7081-0042ecd3b6b7@web.de \
--to=l.s.r@web.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.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.
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).