server-info: do not list unlinked packs
Having non-existent packs in objects/info/packs causes dumb HTTP clients to abort. v2: use single loop with ALLOC_GROW as suggested by Jeff King Signed-off-by: Eric Wong <e@80x24.org> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
May 23, 2019 at 17:27 UTC
e941c48d49ebe24404515acf258d8003f2374627
2 files changed
+9
-11
server-info.c
+7
-11
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "dir.h"
3
#include "repository.h"
4
#include "refs.h"
5
#include "object.h"
@@ -191,26 +192,21 @@ static void init_pack_info(const char *infofile, int force)
192
{
193
struct packed_git *p;
194
int stale;
194
- int i = 0;
195
+ int i;
196
+ size_t alloc = 0;
197
198
for (p = get_all_packs(the_repository); p; p = p->next) {
199
/* we ignore things on alternate path since they are
200
* not available to the pullers in general.
201
*/
200
- if (!p->pack_local)
201
- continue;
202
- i++;
203
- }
204
- num_pack = i;
205
- info = xcalloc(num_pack, sizeof(struct pack_info *));
206
- for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
207
- if (!p->pack_local)
202
+ if (!p->pack_local || !file_exists(p->pack_name))
203
continue;
209
- assert(i < num_pack);
204
+
205
+ i = num_pack++;
206
+ ALLOC_GROW(info, num_pack, alloc);
207
info[i] = xcalloc(1, sizeof(struct pack_info));
208
info[i]->p = p;
209
info[i]->old_num = -1;
213
- i++;
210
}
211
212
if (infofile && !force)
t/t6500-gc.sh
+2
@@ -71,6 +71,8 @@ test_expect_success 'gc --keep-largest-pack' '
71
git gc --keep-largest-pack &&
72
( cd .git/objects/pack && ls *.pack ) >pack-list &&
73
test_line_count = 2 pack-list &&
74
+ awk "/^P /{print \$2}" <.git/objects/info/packs >pack-info &&
75
+ test_line_count = 2 pack-info &&
76
test_path_is_file $BASE_PACK &&
77
git fsck
78
)