
The main function we use to search a pack index for an object is find_pack_entry_one(). That function still takes a bare pointer to the hash, despite the fact that its underlying bsearch_pack() function needs an object_id struct. And so we end up making an extra copy of the hash into the struct just to do a lookup. As it turns out, all callers but one already have such an object_id. So we can just take a pointer to that struct and use it directly. This avoids the extra copy and provides a more type-safe interface. The one exception is get_delta_base() in packfile.c, when we are chasing a REF_DELTA from inside the pack (and thus we have a pointer directly to the mmap'd pack memory, not a struct). We can just bump the hashcpy() from inside find_pack_entry_one() to this one caller that needs it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com>
53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
#include "test-tool.h"
|
|
#include "object-name.h"
|
|
#include "object-store.h"
|
|
#include "packfile.h"
|
|
#include "parse-options.h"
|
|
#include "setup.h"
|
|
|
|
/*
|
|
* Display the path(s), one per line, of the packfile(s) containing
|
|
* the given object.
|
|
*
|
|
* If '--check-count <n>' is passed, then error out if the number of
|
|
* packfiles containing the object is not <n>.
|
|
*/
|
|
|
|
static const char *find_pack_usage[] = {
|
|
"test-tool find-pack [--check-count <n>] <object>",
|
|
NULL
|
|
};
|
|
|
|
int cmd__find_pack(int argc, const char **argv)
|
|
{
|
|
struct object_id oid;
|
|
struct packed_git *p;
|
|
int count = -1, actual_count = 0;
|
|
const char *prefix = setup_git_directory();
|
|
|
|
struct option options[] = {
|
|
OPT_INTEGER('c', "check-count", &count, "expected number of packs"),
|
|
OPT_END(),
|
|
};
|
|
|
|
argc = parse_options(argc, argv, prefix, options, find_pack_usage, 0);
|
|
if (argc != 1)
|
|
usage(find_pack_usage[0]);
|
|
|
|
if (repo_get_oid(the_repository, argv[0], &oid))
|
|
die("cannot parse %s as an object name", argv[0]);
|
|
|
|
for (p = get_all_packs(the_repository); p; p = p->next)
|
|
if (find_pack_entry_one(&oid, p)) {
|
|
printf("%s\n", p->pack_name);
|
|
actual_count++;
|
|
}
|
|
|
|
if (count > -1 && count != actual_count)
|
|
die("bad packfile count %d instead of %d", actual_count, count);
|
|
|
|
return 0;
|
|
}
|