Skip to content

Commit

Permalink
server-info: do not list unlinked packs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Wong authored and gitster committed May 28, 2019
1 parent aa25c82 commit e941c48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 7 additions & 11 deletions server-info.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "dir.h"
#include "repository.h"
#include "refs.h"
#include "object.h"
Expand Down Expand Up @@ -191,26 +192,21 @@ static void init_pack_info(const char *infofile, int force)
{
struct packed_git *p;
int stale;
int i = 0;
int i;
size_t alloc = 0;

for (p = get_all_packs(the_repository); p; p = p->next) {
/* we ignore things on alternate path since they are
* not available to the pullers in general.
*/
if (!p->pack_local)
continue;
i++;
}
num_pack = i;
info = xcalloc(num_pack, sizeof(struct pack_info *));
for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
if (!p->pack_local)
if (!p->pack_local || !file_exists(p->pack_name))
continue;
assert(i < num_pack);

i = num_pack++;
ALLOC_GROW(info, num_pack, alloc);
info[i] = xcalloc(1, sizeof(struct pack_info));
info[i]->p = p;
info[i]->old_num = -1;
i++;
}

if (infofile && !force)
Expand Down
2 changes: 2 additions & 0 deletions t/t6500-gc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ test_expect_success 'gc --keep-largest-pack' '
git gc --keep-largest-pack &&
( cd .git/objects/pack && ls *.pack ) >pack-list &&
test_line_count = 2 pack-list &&
awk "/^P /{print \$2}" <.git/objects/info/packs >pack-info &&
test_line_count = 2 pack-info &&
test_path_is_file $BASE_PACK &&
git fsck
)
Expand Down

0 comments on commit e941c48

Please sign in to comment.