mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'jk/repack-keep-unreachable'
"git repack" learned the "--keep-unreachable" option, which sends loose unreachable objects to a pack instead of leaving them loose. This helps heuristics based on the number of loose objects (e.g. "gc --auto"). * jk/repack-keep-unreachable: repack: extend --keep-unreachable to loose objects repack: add --keep-unreachable option repack: document --unpack-unreachable option
This commit is contained in:
commit
979f030359
|
@ -128,6 +128,19 @@ other objects in that pack they already have locally.
|
|||
with `-b` or `repack.writeBitmaps`, as it ensures that the
|
||||
bitmapped packfile has the necessary objects.
|
||||
|
||||
--unpack-unreachable=<when>::
|
||||
When loosening unreachable objects, do not bother loosening any
|
||||
objects older than `<when>`. This can be used to optimize out
|
||||
the write of any objects that would be immediately pruned by
|
||||
a follow-up `git prune`.
|
||||
|
||||
-k::
|
||||
--keep-unreachable::
|
||||
When used with `-ad`, any unreachable objects from existing
|
||||
packs will be appended to the end of the packfile instead of
|
||||
being removed. In addition, any unreachable loose objects will
|
||||
be packed (and their loose counterparts removed).
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ static int non_empty;
|
|||
static int reuse_delta = 1, reuse_object = 1;
|
||||
static int keep_unreachable, unpack_unreachable, include_tag;
|
||||
static unsigned long unpack_unreachable_expiration;
|
||||
static int pack_loose_unreachable;
|
||||
static int local;
|
||||
static int incremental;
|
||||
static int ignore_packed_keep;
|
||||
|
@ -2378,6 +2379,32 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
|
|||
free(in_pack.array);
|
||||
}
|
||||
|
||||
static int add_loose_object(const unsigned char *sha1, const char *path,
|
||||
void *data)
|
||||
{
|
||||
enum object_type type = sha1_object_info(sha1, NULL);
|
||||
|
||||
if (type < 0) {
|
||||
warning("loose object at %s could not be examined", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
add_object_entry(sha1, type, "", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We actually don't even have to worry about reachability here.
|
||||
* add_object_entry will weed out duplicates, so we just add every
|
||||
* loose object we find.
|
||||
*/
|
||||
static void add_unreachable_loose_objects(void)
|
||||
{
|
||||
for_each_loose_file_in_objdir(get_object_directory(),
|
||||
add_loose_object,
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
|
||||
{
|
||||
static struct packed_git *last_found = (void *)1;
|
||||
|
@ -2547,6 +2574,8 @@ static void get_object_list(int ac, const char **av)
|
|||
|
||||
if (keep_unreachable)
|
||||
add_objects_in_unpacked_packs(&revs);
|
||||
if (pack_loose_unreachable)
|
||||
add_unreachable_loose_objects();
|
||||
if (unpack_unreachable)
|
||||
loosen_unused_packed_objects(&revs);
|
||||
|
||||
|
@ -2647,6 +2676,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||
N_("include tag objects that refer to objects to be packed")),
|
||||
OPT_BOOL(0, "keep-unreachable", &keep_unreachable,
|
||||
N_("keep unreachable objects")),
|
||||
OPT_BOOL(0, "pack-loose-unreachable", &pack_loose_unreachable,
|
||||
N_("pack loose unreachable objects")),
|
||||
{ OPTION_CALLBACK, 0, "unpack-unreachable", NULL, N_("time"),
|
||||
N_("unpack unreachable objects newer than <time>"),
|
||||
PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
|
||||
|
|
|
@ -146,6 +146,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||
int pack_everything = 0;
|
||||
int delete_redundant = 0;
|
||||
const char *unpack_unreachable = NULL;
|
||||
int keep_unreachable = 0;
|
||||
const char *window = NULL, *window_memory = NULL;
|
||||
const char *depth = NULL;
|
||||
const char *max_pack_size = NULL;
|
||||
|
@ -175,6 +176,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||
N_("write bitmap index")),
|
||||
OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
|
||||
N_("with -A, do not loosen objects older than this")),
|
||||
OPT_BOOL('k', "keep-unreachable", &keep_unreachable,
|
||||
N_("with -a, repack unreachable objects")),
|
||||
OPT_STRING(0, "window", &window, N_("n"),
|
||||
N_("size of the window used for delta compression")),
|
||||
OPT_STRING(0, "window-memory", &window_memory, N_("bytes"),
|
||||
|
@ -196,6 +199,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||
if (delete_redundant && repository_format_precious_objects)
|
||||
die(_("cannot delete packs in a precious-objects repo"));
|
||||
|
||||
if (keep_unreachable &&
|
||||
(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
|
||||
die(_("--keep-unreachable and -A are incompatible"));
|
||||
|
||||
if (pack_kept_objects < 0)
|
||||
pack_kept_objects = write_bitmaps;
|
||||
|
||||
|
@ -239,6 +246,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||
} else if (pack_everything & LOOSEN_UNREACHABLE) {
|
||||
argv_array_push(&cmd.args,
|
||||
"--unpack-unreachable");
|
||||
} else if (keep_unreachable) {
|
||||
argv_array_push(&cmd.args, "--keep-unreachable");
|
||||
argv_array_push(&cmd.args, "--pack-loose-unreachable");
|
||||
} else {
|
||||
argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
|
||||
}
|
||||
|
|
|
@ -122,4 +122,32 @@ test_expect_success 'keep packed objects found only in index' '
|
|||
git cat-file blob :file
|
||||
'
|
||||
|
||||
test_expect_success 'repack -k keeps unreachable packed objects' '
|
||||
# create packed-but-unreachable object
|
||||
sha1=$(echo unreachable-packed | git hash-object -w --stdin) &&
|
||||
pack=$(echo $sha1 | git pack-objects .git/objects/pack/pack) &&
|
||||
git prune-packed &&
|
||||
|
||||
# -k should keep it
|
||||
git repack -adk &&
|
||||
git cat-file -p $sha1 &&
|
||||
|
||||
# and double check that without -k it would have been removed
|
||||
git repack -ad &&
|
||||
test_must_fail git cat-file -p $sha1
|
||||
'
|
||||
|
||||
test_expect_success 'repack -k packs unreachable loose objects' '
|
||||
# create loose unreachable object
|
||||
sha1=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
|
||||
objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
|
||||
test_path_is_file $objpath &&
|
||||
|
||||
# and confirm that the loose object goes away, but we can
|
||||
# still access it (ergo, it is packed)
|
||||
git repack -adk &&
|
||||
test_path_is_missing $objpath &&
|
||||
git cat-file -p $sha1
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue