Skip to content

Commit c46f849

Browse files
committed
Merge branch 'jx/pack-redundant-on-single-pack'
"git pack-redandant" when there is only one packfile used to crash, which has been corrected. * jx/pack-redundant-on-single-pack: pack-redundant: fix crash when one packfile in repo
2 parents 6d3ef5b + 0696232 commit c46f849

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

builtin/pack-redundant.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ static void cmp_local_packs(void)
473473
{
474474
struct pack_list *subset, *pl = local_packs;
475475

476+
/* only one packfile */
477+
if (!pl->next) {
478+
llist_init(&pl->unique_objects);
479+
return;
480+
}
481+
476482
while ((subset = pl)) {
477483
while ((subset = subset->next))
478484
cmp_two_packs(pl, subset);

t/t5323-pack-redundant.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,28 @@ test_expect_success 'setup master repo' '
112112
create_commits_in "$master_repo" A B C D E F G H I J K L M N O P Q R
113113
'
114114

115+
test_expect_success 'master: pack-redundant works with no packfile' '
116+
(
117+
cd "$master_repo" &&
118+
cat >expect <<-EOF &&
119+
fatal: Zero packs found!
120+
EOF
121+
test_must_fail git pack-redundant --all >actual 2>&1 &&
122+
test_cmp expect actual
123+
)
124+
'
125+
115126
#############################################################################
116127
# Chart of packs and objects for this test case
117128
#
118129
# | T A B C D E F G H I J K L M N O P Q R
119130
# ----+--------------------------------------
120131
# P1 | x x x x x x x x
121-
# P2 | x x x x x x x
122-
# P3 | x x x x x x
123132
# ----+--------------------------------------
124-
# ALL | x x x x x x x x x x x x x x x
133+
# ALL | x x x x x x x x
125134
#
126135
#############################################################################
127-
test_expect_success 'master: no redundant for pack 1, 2, 3' '
136+
test_expect_success 'master: pack-redundant works with one packfile' '
128137
create_pack_in "$master_repo" P1 <<-EOF &&
129138
$T
130139
$A
@@ -135,6 +144,26 @@ test_expect_success 'master: no redundant for pack 1, 2, 3' '
135144
$F
136145
$R
137146
EOF
147+
(
148+
cd "$master_repo" &&
149+
git pack-redundant --all >out &&
150+
test_must_be_empty out
151+
)
152+
'
153+
154+
#############################################################################
155+
# Chart of packs and objects for this test case
156+
#
157+
# | T A B C D E F G H I J K L M N O P Q R
158+
# ----+--------------------------------------
159+
# P1 | x x x x x x x x
160+
# P2 | x x x x x x x
161+
# P3 | x x x x x x
162+
# ----+--------------------------------------
163+
# ALL | x x x x x x x x x x x x x x x
164+
#
165+
#############################################################################
166+
test_expect_success 'master: no redundant for pack 1, 2, 3' '
138167
create_pack_in "$master_repo" P2 <<-EOF &&
139168
$B
140169
$C

0 commit comments

Comments
 (0)