/* The maximum size for an object header. */
#define MAX_HEADER_LEN 32
+static struct oidtree *odb_source_loose_cache(struct odb_source *source,
+ const struct object_id *oid);
+
static int get_conv_flags(unsigned flags)
{
if (flags & INDEX_RENORMALIZE)
}
}
+static int for_each_prefixed_object_wrapper_cb(const struct object_id *oid,
+ void *cb_data)
+{
+ struct for_each_object_wrapper_data *data = cb_data;
+ if (data->request) {
+ struct object_info oi = *data->request;
+
+ if (odb_source_loose_read_object_info(data->source,
+ oid, &oi, 0) < 0)
+ return -1;
+
+ return data->cb(oid, &oi, data->cb_data);
+ } else {
+ return data->cb(oid, NULL, data->cb_data);
+ }
+}
+
int odb_source_loose_for_each_object(struct odb_source *source,
const struct object_info *request,
odb_for_each_object_cb cb,
if ((opts->flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !source->local)
return 0;
+ if (opts->prefix)
+ return oidtree_each(odb_source_loose_cache(source, opts->prefix),
+ opts->prefix, opts->prefix_hex_len,
+ for_each_prefixed_object_wrapper_cb, &data);
+
return for_each_loose_file_in_source(source, for_each_object_wrapper_cb,
NULL, NULL, &data);
}
return 0;
}
-struct oidtree *odb_source_loose_cache(struct odb_source *source,
- const struct object_id *oid)
+static struct oidtree *odb_source_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
struct odb_source_files *files = odb_source_files_downcast(source);
int subdir_nr = oid->hash[0];
struct odb_write_stream *stream, size_t len,
struct object_id *oid);
-/*
- * Populate and return the loose object cache array corresponding to the
- * given object ID.
- */
-struct oidtree *odb_source_loose_cache(struct odb_source *source,
- const struct object_id *oid);
-
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
#include "remote.h"
#include "dir.h"
#include "oid-array.h"
-#include "oidtree.h"
#include "packfile.h"
#include "pretty.h"
#include "object-file.h"
static int match_hash(unsigned, const unsigned char *, const unsigned char *);
-static int match_prefix(const struct object_id *oid, void *arg)
+static int match_prefix(const struct object_id *oid, struct object_info *oi UNUSED, void *arg)
{
struct disambiguate_state *ds = arg;
/* no need to call match_hash, oidtree_each did prefix match */
static void find_short_object_filename(struct disambiguate_state *ds)
{
+ struct odb_for_each_object_options opts = {
+ .prefix = &ds->bin_pfx,
+ .prefix_hex_len = ds->len,
+ };
struct odb_source *source;
for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
- oidtree_each(odb_source_loose_cache(source, &ds->bin_pfx),
- &ds->bin_pfx, ds->len, match_prefix, ds);
+ odb_source_loose_for_each_object(source, NULL, match_prefix, ds, &opts);
}
static int match_hash(unsigned len, const unsigned char *a, const unsigned char *b)
struct odb_for_each_object_options {
/* A bitfield of `odb_for_each_object_flags`. */
enum odb_for_each_object_flags flags;
+
+ /*
+ * If set, only iterate through objects whose first `prefix_hex_len`
+ * hex characters matches the given prefix.
+ */
+ const struct object_id *prefix;
+ size_t prefix_hex_len;
};
/*