Skip to content

Commit 88a516a

Browse files
committed
Merge branch 'ds/repack-fixlets'
Two fixes around "git repack". * ds/repack-fixlets: repack: make '--quiet' disable progress repack: respect kept objects with '--write-midx -b'
2 parents bb14cfd + 47ca93d commit 88a516a

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

Documentation/git-repack.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ to the new separate pack will be written.
7676
linkgit:git-pack-objects[1].
7777

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

8283
-n::
8384
Do not update the server information with

builtin/repack.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
612612
struct tempfile *refs_snapshot = NULL;
613613
int i, ext, ret;
614614
FILE *out;
615-
int show_progress = isatty(2);
615+
int show_progress;
616616

617617
/* variables to be filled by option parsing */
618618
int pack_everything = 0;
@@ -693,7 +693,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
693693
write_bitmaps = 0;
694694
}
695695
if (pack_kept_objects < 0)
696-
pack_kept_objects = write_bitmaps > 0;
696+
pack_kept_objects = write_bitmaps > 0 && !write_midx;
697697

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

726726
prepare_pack_objects(&cmd, &po_args);
727727

728+
show_progress = !po_args.quiet && isatty(2);
729+
728730
strvec_push(&cmd.args, "--keep-true-parents");
729731
if (!pack_kept_objects)
730732
strvec_push(&cmd.args, "--honor-pack-keep");
@@ -926,7 +928,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
926928
}
927929
strbuf_release(&buf);
928930
}
929-
if (!po_args.quiet && show_progress)
931+
if (show_progress)
930932
opts |= PRUNE_PACKED_VERBOSE;
931933
prune_packed_objects(opts);
932934

t/t7700-repack.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='git repack works correctly'
55
. ./test-lib.sh
66
. "${TEST_DIRECTORY}/lib-bitmap.sh"
77
. "${TEST_DIRECTORY}/lib-midx.sh"
8+
. "${TEST_DIRECTORY}/lib-terminal.sh"
89

910
commit_and_pack () {
1011
test_commit "$@" 1>&2 &&
@@ -372,4 +373,16 @@ test_expect_success '--write-midx with preferred bitmap tips' '
372373
)
373374
'
374375

376+
test_expect_success '--write-midx -b packs non-kept objects' '
377+
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
378+
git repack --write-midx -a -b &&
379+
test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
380+
'
381+
382+
test_expect_success TTY '--quiet disables progress' '
383+
test_terminal env GIT_PROGRESS_DELAY=0 \
384+
git -C midx repack -ad --quiet --write-midx 2>stderr &&
385+
test_must_be_empty stderr
386+
'
387+
375388
test_done

t/test-lib-functions.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,40 @@ test_subcommand () {
17591759
fi
17601760
}
17611761

1762+
# Check that the given command was invoked as part of the
1763+
# trace2-format trace on stdin, but without an exact set of
1764+
# arguments.
1765+
#
1766+
# test_subcommand [!] <command> <args>... < <trace>
1767+
#
1768+
# For example, to look for an invocation of "git pack-objects"
1769+
# with the "--honor-pack-keep" argument, use
1770+
#
1771+
# GIT_TRACE2_EVENT=event.log git repack ... &&
1772+
# test_subcommand git pack-objects --honor-pack-keep <event.log
1773+
#
1774+
# If the first parameter passed is !, this instead checks that
1775+
# the given command was not called.
1776+
#
1777+
test_subcommand_inexact () {
1778+
local negate=
1779+
if test "$1" = "!"
1780+
then
1781+
negate=t
1782+
shift
1783+
fi
1784+
1785+
local expr=$(printf '"%s".*' "$@")
1786+
expr="${expr%,}"
1787+
1788+
if test -n "$negate"
1789+
then
1790+
! grep "\"event\":\"child_start\".*\[$expr\]"
1791+
else
1792+
grep "\"event\":\"child_start\".*\[$expr\]"
1793+
fi
1794+
}
1795+
17621796
# Check that the given command was invoked as part of the
17631797
# trace2-format trace on stdin.
17641798
#

0 commit comments

Comments
 (0)