From: Junio C Hamano <gitster@pobox.com>
To: Jiang Xin <worldhello.net@gmail.com>
Cc: Git List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
"Daniel C . Klauer" <daniel.c.klauer@web.de>,
Jiang Xin <zhiyou.jx@alibaba-inc.com>
Subject: Re: [PATCH v2] pack-redundant: fix crash when one packfile in repo
Date: Wed, 16 Dec 2020 22:08:11 -0800 [thread overview]
Message-ID: <xmqqczz9yng4.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201217015709.28827-1-worldhello.net@gmail.com> (Jiang Xin's message of "Wed, 16 Dec 2020 20:57:09 -0500")
Jiang Xin <worldhello.net@gmail.com> writes:
> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
>
> Command `git pack-redundant --all` will crash if there is only one
> packfile in the repository. This is because, if there is only one
> packfile in local_packs, `cmp_local_packs` will do nothing and will
> leave `pl->unique_objects` as uninitialized.
>
> Also add testcases for repository with no packfile and one packfile
> in t5323.
>
> Reported-by: Daniel C. Klauer <daniel.c.klauer@web.de>
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> ---
> builtin/pack-redundant.c | 6 ++++++
> t/t5323-pack-redundant.sh | 37 +++++++++++++++++++++++++++++++++----
> 2 files changed, 39 insertions(+), 4 deletions(-)
Thanks.
>
> diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
> index 178e3409b7..690775fa82 100644
> --- a/builtin/pack-redundant.c
> +++ b/builtin/pack-redundant.c
> @@ -473,6 +473,12 @@ static void cmp_local_packs(void)
> {
> struct pack_list *subset, *pl = local_packs;
>
> + /* only one packfile */
> + if (!pl->next) {
> + llist_init(&pl->unique_objects);
> + return;
> + }
> +
> while ((subset = pl)) {
> while ((subset = subset->next))
> cmp_two_packs(pl, subset);
> diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh
> index 6b4d1ca353..7e3340843f 100755
> --- a/t/t5323-pack-redundant.sh
> +++ b/t/t5323-pack-redundant.sh
> @@ -112,19 +112,28 @@ test_expect_success 'setup master repo' '
> create_commits_in "$master_repo" A B C D E F G H I J K L M N O P Q R
> '
>
> +test_expect_success 'master: pack-redundant works with no packfile' '
> + (
> + cd "$master_repo" &&
> + cat >expect <<-EOF &&
> + fatal: Zero packs found!
> + EOF
> + test_must_fail git pack-redundant --all >actual 2>&1 &&
> + test_cmp expect actual
> + )
> +'
> +
> #############################################################################
> # Chart of packs and objects for this test case
> #
> # | T A B C D E F G H I J K L M N O P Q R
> # ----+--------------------------------------
> # P1 | x x x x x x x x
> -# P2 | x x x x x x x
> -# P3 | x x x x x x
> # ----+--------------------------------------
> -# ALL | x x x x x x x x x x x x x x x
> +# ALL | x x x x x x x x
> #
> #############################################################################
> -test_expect_success 'master: no redundant for pack 1, 2, 3' '
> +test_expect_success 'master: pack-redundant works with one packfile' '
> create_pack_in "$master_repo" P1 <<-EOF &&
> $T
> $A
> @@ -135,6 +144,26 @@ test_expect_success 'master: no redundant for pack 1, 2, 3' '
> $F
> $R
> EOF
> + (
> + cd "$master_repo" &&
> + git pack-redundant --all >out &&
> + test_must_be_empty out
> + )
> +'
> +
> +#############################################################################
> +# Chart of packs and objects for this test case
> +#
> +# | T A B C D E F G H I J K L M N O P Q R
> +# ----+--------------------------------------
> +# P1 | x x x x x x x x
> +# P2 | x x x x x x x
> +# P3 | x x x x x x
> +# ----+--------------------------------------
> +# ALL | x x x x x x x x x x x x x x x
> +#
> +#############################################################################
> +test_expect_success 'master: no redundant for pack 1, 2, 3' '
> create_pack_in "$master_repo" P2 <<-EOF &&
> $B
> $C
next prev parent reply other threads:[~2020-12-17 6:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-15 17:34 bug report: "git pack-redundant --all" crash in minimize() Daniel C. Klauer
2020-12-15 18:21 ` Jeff King
2020-12-15 22:32 ` Junio C Hamano
2020-12-16 9:21 ` Jiang Xin
2020-12-16 10:09 ` [PATCH] pack-redundant: fix crash when one packfile in repo Jiang Xin
2020-12-16 17:32 ` Junio C Hamano
2020-12-17 1:57 ` [PATCH v2] " Jiang Xin
2020-12-17 6:08 ` Junio C Hamano [this message]
2020-12-16 18:46 ` [PATCH] " Jeff King
2020-12-16 13:22 ` bug report: "git pack-redundant --all" crash in minimize() Daniel Klauer
2020-12-16 19:00 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqczz9yng4.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=daniel.c.klauer@web.de \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=worldhello.net@gmail.com \
--cc=zhiyou.jx@alibaba-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).