Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-12 17:50:56 +0300
committerJunio C Hamano <gitster@pobox.com>2018-11-13 08:22:03 +0300
commit3a2e08245cfccd932bb3ff78521e07d4a38c2834 (patch)
treeeedf38839cf088ba390bfe12230bccaf5885427d /sha1-name.c
parentf0eaf638195a6510254b075026dcad955b8b607d (diff)
object-store: provide helpers for loose_objects_cache
Our object_directory struct has a loose objects cache that all users of the struct can see. But the only one that knows how to load the cache is find_short_object_filename(). Let's extract that logic in to a reusable function. While we're at it, let's also reset the cache when we re-read the object directories. This shouldn't have an impact on performance, as re-reads are meant to be rare (and are already expensive, so we avoid them with things like OBJECT_INFO_QUICK). Since the cache is already meant to be an approximation, it's tempting to skip even this bit of safety. But it's necessary to allow more code to use it. For instance, fetch-pack explicitly re-reads the object directory after performing its fetch, and would be confused if we didn't clear the cache. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-name.c')
-rw-r--r--sha1-name.c21
1 files changed, 1 insertions, 20 deletions
diff --git a/sha1-name.c b/sha1-name.c
index 358ca5e288..b24502811b 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -83,36 +83,19 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
/* otherwise, current can be discarded and candidate is still good */
}
-static int append_loose_object(const struct object_id *oid, const char *path,
- void *data)
-{
- oid_array_append(data, oid);
- return 0;
-}
-
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;
- struct strbuf buf = STRBUF_INIT;
for (odb = the_repository->objects->odb;
odb && !ds->ambiguous;
odb = odb->next) {
int pos;
- if (!odb->loose_objects_subdir_seen[subdir_nr]) {
- strbuf_reset(&buf);
- strbuf_addstr(&buf, odb->path);
- for_each_file_in_obj_subdir(subdir_nr, &buf,
- append_loose_object,
- NULL, NULL,
- &odb->loose_objects_cache);
- odb->loose_objects_subdir_seen[subdir_nr] = 1;
- }
-
+ odb_load_loose_cache(odb, subdir_nr);
pos = oid_array_lookup(&odb->loose_objects_cache, &ds->bin_pfx);
if (pos < 0)
pos = -1 - pos;
@@ -125,8 +108,6 @@ static void find_short_object_filename(struct disambiguate_state *ds)
pos++;
}
}
-
- strbuf_release(&buf);
}
static int match_sha(unsigned len, const unsigned char *a, const unsigned char *b)