mirror of
https://github.com/git/git
synced 2024-10-01 06:05:20 +00:00
t/helper: add 'find-pack' test-tool
In a following commit, we will make it possible to separate objects in different packfiles depending on a filter. To make sure that the right objects are in the right packs, let's add a new test-tool that can display which packfile(s) a given object is in. Let's also make it possible to check if a given object is in the expected number of packfiles with a `--check-count <n>` option. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6cfcabfb9f
commit
66589f89ab
1
Makefile
1
Makefile
|
@ -800,6 +800,7 @@ TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
|
|||
TEST_BUILTINS_OBJS += test-env-helper.o
|
||||
TEST_BUILTINS_OBJS += test-example-decorate.o
|
||||
TEST_BUILTINS_OBJS += test-fast-rebase.o
|
||||
TEST_BUILTINS_OBJS += test-find-pack.o
|
||||
TEST_BUILTINS_OBJS += test-fsmonitor-client.o
|
||||
TEST_BUILTINS_OBJS += test-genrandom.o
|
||||
TEST_BUILTINS_OBJS += test-genzeros.o
|
||||
|
|
50
t/helper/test-find-pack.c
Normal file
50
t/helper/test-find-pack.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#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.hash, 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;
|
||||
}
|
|
@ -31,6 +31,7 @@ static struct test_cmd cmds[] = {
|
|||
{ "env-helper", cmd__env_helper },
|
||||
{ "example-decorate", cmd__example_decorate },
|
||||
{ "fast-rebase", cmd__fast_rebase },
|
||||
{ "find-pack", cmd__find_pack },
|
||||
{ "fsmonitor-client", cmd__fsmonitor_client },
|
||||
{ "genrandom", cmd__genrandom },
|
||||
{ "genzeros", cmd__genzeros },
|
||||
|
|
|
@ -25,6 +25,7 @@ int cmd__dump_reftable(int argc, const char **argv);
|
|||
int cmd__env_helper(int argc, const char **argv);
|
||||
int cmd__example_decorate(int argc, const char **argv);
|
||||
int cmd__fast_rebase(int argc, const char **argv);
|
||||
int cmd__find_pack(int argc, const char **argv);
|
||||
int cmd__fsmonitor_client(int argc, const char **argv);
|
||||
int cmd__genrandom(int argc, const char **argv);
|
||||
int cmd__genzeros(int argc, const char **argv);
|
||||
|
|
82
t/t0081-find-pack.sh
Executable file
82
t/t0081-find-pack.sh
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='test `test-tool find-pack`'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
test_commit one &&
|
||||
test_commit two &&
|
||||
test_commit three &&
|
||||
test_commit four &&
|
||||
test_commit five
|
||||
'
|
||||
|
||||
test_expect_success 'repack everything into a single packfile' '
|
||||
git repack -a -d --no-write-bitmap-index &&
|
||||
|
||||
head_commit_pack=$(test-tool find-pack HEAD) &&
|
||||
head_tree_pack=$(test-tool find-pack HEAD^{tree}) &&
|
||||
one_pack=$(test-tool find-pack HEAD:one.t) &&
|
||||
three_pack=$(test-tool find-pack HEAD:three.t) &&
|
||||
old_commit_pack=$(test-tool find-pack HEAD~4) &&
|
||||
|
||||
test-tool find-pack --check-count 1 HEAD &&
|
||||
test-tool find-pack --check-count=1 HEAD^{tree} &&
|
||||
! test-tool find-pack --check-count=0 HEAD:one.t &&
|
||||
! test-tool find-pack -c 2 HEAD:one.t &&
|
||||
test-tool find-pack -c 1 HEAD:three.t &&
|
||||
|
||||
# Packfile exists at the right path
|
||||
case "$head_commit_pack" in
|
||||
".git/objects/pack/pack-"*".pack") true ;;
|
||||
*) false ;;
|
||||
esac &&
|
||||
test -f "$head_commit_pack" &&
|
||||
|
||||
# Everything is in the same pack
|
||||
test "$head_commit_pack" = "$head_tree_pack" &&
|
||||
test "$head_commit_pack" = "$one_pack" &&
|
||||
test "$head_commit_pack" = "$three_pack" &&
|
||||
test "$head_commit_pack" = "$old_commit_pack"
|
||||
'
|
||||
|
||||
test_expect_success 'add more packfiles' '
|
||||
git rev-parse HEAD^{tree} HEAD:two.t HEAD:four.t >objects &&
|
||||
git pack-objects .git/objects/pack/mypackname1 >packhash1 <objects &&
|
||||
|
||||
git rev-parse HEAD~ HEAD~^{tree} HEAD:five.t >objects &&
|
||||
git pack-objects .git/objects/pack/mypackname2 >packhash2 <objects &&
|
||||
|
||||
head_commit_pack=$(test-tool find-pack HEAD) &&
|
||||
|
||||
# HEAD^{tree} is in 2 packfiles
|
||||
test-tool find-pack HEAD^{tree} >head_tree_packs &&
|
||||
grep "$head_commit_pack" head_tree_packs &&
|
||||
grep mypackname1 head_tree_packs &&
|
||||
! grep mypackname2 head_tree_packs &&
|
||||
test-tool find-pack --check-count 2 HEAD^{tree} &&
|
||||
! test-tool find-pack --check-count 1 HEAD^{tree} &&
|
||||
|
||||
# HEAD:five.t is also in 2 packfiles
|
||||
test-tool find-pack HEAD:five.t >five_packs &&
|
||||
grep "$head_commit_pack" five_packs &&
|
||||
! grep mypackname1 five_packs &&
|
||||
grep mypackname2 five_packs &&
|
||||
test-tool find-pack -c 2 HEAD:five.t &&
|
||||
! test-tool find-pack --check-count=0 HEAD:five.t
|
||||
'
|
||||
|
||||
test_expect_success 'add more commits (as loose objects)' '
|
||||
test_commit six &&
|
||||
test_commit seven &&
|
||||
|
||||
test -z "$(test-tool find-pack HEAD)" &&
|
||||
test -z "$(test-tool find-pack HEAD:six.t)" &&
|
||||
test-tool find-pack --check-count 0 HEAD &&
|
||||
test-tool find-pack -c 0 HEAD:six.t &&
|
||||
! test-tool find-pack -c 1 HEAD:seven.t
|
||||
'
|
||||
|
||||
test_done
|
Loading…
Reference in a new issue