Skip to content

Commit

Permalink
Merge branch 'ds/repack-fixlets' into next
Browse files Browse the repository at this point in the history
Two fixes around "git repack".

* ds/repack-fixlets:
  repack: make '--quiet' disable progress
  repack: respect kept objects with '--write-midx -b'
  • Loading branch information
gitster committed Dec 27, 2021
2 parents 01f9fe1 + 47ca93d commit 8f8474a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Documentation/git-repack.txt
Expand Up @@ -76,8 +76,9 @@ to the new separate pack will be written.
linkgit:git-pack-objects[1].

-q::
Pass the `-q` option to 'git pack-objects'. See
linkgit:git-pack-objects[1].
--quiet::
Show no progress over the standard error stream and pass the `-q`
option to 'git pack-objects'. See linkgit:git-pack-objects[1].

-n::
Do not update the server information with
Expand Down
8 changes: 5 additions & 3 deletions builtin/repack.c
Expand Up @@ -612,7 +612,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
struct tempfile *refs_snapshot = NULL;
int i, ext, ret;
FILE *out;
int show_progress = isatty(2);
int show_progress;

/* variables to be filled by option parsing */
int pack_everything = 0;
Expand Down Expand Up @@ -693,7 +693,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
write_bitmaps = 0;
}
if (pack_kept_objects < 0)
pack_kept_objects = write_bitmaps > 0;
pack_kept_objects = write_bitmaps > 0 && !write_midx;

if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
Expand Down Expand Up @@ -725,6 +725,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)

prepare_pack_objects(&cmd, &po_args);

show_progress = !po_args.quiet && isatty(2);

strvec_push(&cmd.args, "--keep-true-parents");
if (!pack_kept_objects)
strvec_push(&cmd.args, "--honor-pack-keep");
Expand Down Expand Up @@ -926,7 +928,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
}
strbuf_release(&buf);
}
if (!po_args.quiet && show_progress)
if (show_progress)
opts |= PRUNE_PACKED_VERBOSE;
prune_packed_objects(opts);

Expand Down
13 changes: 13 additions & 0 deletions t/t7700-repack.sh
Expand Up @@ -5,6 +5,7 @@ test_description='git repack works correctly'
. ./test-lib.sh
. "${TEST_DIRECTORY}/lib-bitmap.sh"
. "${TEST_DIRECTORY}/lib-midx.sh"
. "${TEST_DIRECTORY}/lib-terminal.sh"

commit_and_pack () {
test_commit "$@" 1>&2 &&
Expand Down Expand Up @@ -372,4 +373,16 @@ test_expect_success '--write-midx with preferred bitmap tips' '
)
'

test_expect_success '--write-midx -b packs non-kept objects' '
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
git repack --write-midx -a -b &&
test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
'

test_expect_success TTY '--quiet disables progress' '
test_terminal env GIT_PROGRESS_DELAY=0 \
git -C midx repack -ad --quiet --write-midx 2>stderr &&
test_must_be_empty stderr
'

test_done
34 changes: 34 additions & 0 deletions t/test-lib-functions.sh
Expand Up @@ -1759,6 +1759,40 @@ test_subcommand () {
fi
}

# Check that the given command was invoked as part of the
# trace2-format trace on stdin, but without an exact set of
# arguments.
#
# test_subcommand [!] <command> <args>... < <trace>
#
# For example, to look for an invocation of "git pack-objects"
# with the "--honor-pack-keep" argument, use
#
# GIT_TRACE2_EVENT=event.log git repack ... &&
# test_subcommand git pack-objects --honor-pack-keep <event.log
#
# If the first parameter passed is !, this instead checks that
# the given command was not called.
#
test_subcommand_inexact () {
local negate=
if test "$1" = "!"
then
negate=t
shift
fi

local expr=$(printf '"%s".*' "$@")
expr="${expr%,}"

if test -n "$negate"
then
! grep "\"event\":\"child_start\".*\[$expr\]"
else
grep "\"event\":\"child_start\".*\[$expr\]"
fi
}

# Check that the given command was invoked as part of the
# trace2-format trace on stdin.
#
Expand Down

0 comments on commit 8f8474a

Please sign in to comment.