Skip to content

Commit 51cf315

Browse files
committed
Merge branch 'jk/repack-silence-auto-bitmap-warning'
Squelch unneeded and misleading warnings from "repack" when the command attempts to generate pack bitmaps without explicitly asked for by the user. * jk/repack-silence-auto-bitmap-warning: repack: simplify handling of auto-bitmaps and .keep files repack: silence warnings when auto-enabled bitmaps cannot be built t7700: clean up .keep file in bitmap-writing test
2 parents 49541db + 7ff024e commit 51cf315

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

builtin/pack-objects.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ static off_t reuse_packfile_offset;
9696

9797
static int use_bitmap_index_default = 1;
9898
static int use_bitmap_index = -1;
99-
static int write_bitmap_index;
99+
static enum {
100+
WRITE_BITMAP_FALSE = 0,
101+
WRITE_BITMAP_QUIET,
102+
WRITE_BITMAP_TRUE,
103+
} write_bitmap_index;
100104
static uint16_t write_bitmap_options = BITMAP_OPT_HASH_CACHE;
101105

102106
static int exclude_promisor_objects;
@@ -892,7 +896,8 @@ static void write_pack_file(void)
892896
nr_written, oid.hash, offset);
893897
close(fd);
894898
if (write_bitmap_index) {
895-
warning(_(no_split_warning));
899+
if (write_bitmap_index != WRITE_BITMAP_QUIET)
900+
warning(_(no_split_warning));
896901
write_bitmap_index = 0;
897902
}
898903
}
@@ -1176,7 +1181,8 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
11761181
if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) {
11771182
/* The pack is missing an object, so it will not have closure */
11781183
if (write_bitmap_index) {
1179-
warning(_(no_closure_warning));
1184+
if (write_bitmap_index != WRITE_BITMAP_QUIET)
1185+
warning(_(no_closure_warning));
11801186
write_bitmap_index = 0;
11811187
}
11821188
return 0;
@@ -3313,8 +3319,13 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
33133319
N_("do not hide commits by grafts"), 0),
33143320
OPT_BOOL(0, "use-bitmap-index", &use_bitmap_index,
33153321
N_("use a bitmap index if available to speed up counting objects")),
3316-
OPT_BOOL(0, "write-bitmap-index", &write_bitmap_index,
3317-
N_("write a bitmap index together with the pack index")),
3322+
OPT_SET_INT(0, "write-bitmap-index", &write_bitmap_index,
3323+
N_("write a bitmap index together with the pack index"),
3324+
WRITE_BITMAP_TRUE),
3325+
OPT_SET_INT_F(0, "write-bitmap-index-quiet",
3326+
&write_bitmap_index,
3327+
N_("write a bitmap index if possible"),
3328+
WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN),
33183329
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
33193330
{ OPTION_CALLBACK, 0, "missing", NULL, N_("action"),
33203331
N_("handling for missing objects"), PARSE_OPT_NONEG,

builtin/repack.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ static void remove_pack_on_signal(int signo)
8989
raise(signo);
9090
}
9191

92-
static int has_pack_keep_file(void)
93-
{
94-
struct packed_git *p;
95-
96-
for (p = get_all_packs(the_repository); p; p = p->next) {
97-
if (p->pack_keep)
98-
return 1;
99-
}
100-
return 0;
101-
}
102-
10392
/*
10493
* Adds all packs hex strings to the fname list, which do not
10594
* have a corresponding .keep file. These packs are not to
@@ -345,13 +334,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
345334
die(_("--keep-unreachable and -A are incompatible"));
346335

347336
if (write_bitmaps < 0) {
348-
write_bitmaps = (pack_everything & ALL_INTO_ONE) &&
349-
is_bare_repository() &&
350-
keep_pack_list.nr == 0 &&
351-
!has_pack_keep_file();
337+
if (!(pack_everything & ALL_INTO_ONE) ||
338+
!is_bare_repository())
339+
write_bitmaps = 0;
352340
}
353341
if (pack_kept_objects < 0)
354-
pack_kept_objects = write_bitmaps;
342+
pack_kept_objects = write_bitmaps > 0;
355343

356344
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE))
357345
die(_(incremental_bitmap_conflict_error));
@@ -375,8 +363,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
375363
argv_array_push(&cmd.args, "--indexed-objects");
376364
if (repository_format_partial_clone)
377365
argv_array_push(&cmd.args, "--exclude-promisor-objects");
378-
if (write_bitmaps)
366+
if (write_bitmaps > 0)
379367
argv_array_push(&cmd.args, "--write-bitmap-index");
368+
else if (write_bitmaps < 0)
369+
argv_array_push(&cmd.args, "--write-bitmap-index-quiet");
380370
if (use_delta_islands)
381371
argv_array_push(&cmd.args, "--delta-islands");
382372

t/t7700-repack.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,23 @@ test_expect_success 'no bitmaps created if .keep files present' '
243243
pack=$(ls bare.git/objects/pack/*.pack) &&
244244
test_path_is_file "$pack" &&
245245
keep=${pack%.pack}.keep &&
246+
test_when_finished "rm -f \"\$keep\"" &&
246247
>"$keep" &&
247-
git -C bare.git repack -ad &&
248+
git -C bare.git repack -ad 2>stderr &&
249+
test_must_be_empty stderr &&
248250
find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
249251
test_must_be_empty actual
250252
'
251253

254+
test_expect_success 'auto-bitmaps do not complain if unavailable' '
255+
test_config -C bare.git pack.packSizeLimit 1M &&
256+
blob=$(test-tool genrandom big $((1024*1024)) |
257+
git -C bare.git hash-object -w --stdin) &&
258+
git -C bare.git update-ref refs/tags/big $blob &&
259+
git -C bare.git repack -ad 2>stderr &&
260+
test_must_be_empty stderr &&
261+
find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
262+
test_must_be_empty actual
263+
'
264+
252265
test_done

0 commit comments

Comments
 (0)