@matheusbsbs / matheus-bagliano / commits / 4b480c6716
Fork 0

discard revindex data when pack list changes

This is needed to fix verify-pack -v with multiple pack arguments. Also, in theory, revindex data (if any) must be discarded whenever reprepare_packed_git() is called. In practice this is hard to trigger though. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Aug 22, 2008 at 15:45 UTC 4b480c6716a7d8e20e7e510827ea81e7939f335a
5 files changed +22 -1
builtin-verify-pack.c
+2 -1
@@ -1,7 +1,7 @@
1 #include "builtin.h"
2 #include "cache.h"
3 #include "pack.h"
4 -
4 +#include "pack-revindex.h"
5
6 #define MAX_CHAIN 50
7
@@ -129,6 +129,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
129 else {
130 if (verify_one_pack(argv[1], verbose))
131 err = 1;
132 + discard_revindex();
133 nothing_done = 0;
134 }
135 argc--; argv++;
pack-revindex.c
+12
@@ -142,3 +142,15 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
142 } while (lo < hi);
143 die("internal error: pack revindex corrupt");
144 }
145 +
146 +void discard_revindex(void)
147 +{
148 + if (pack_revindex_hashsz) {
149 + int i;
150 + for (i = 0; i < pack_revindex_hashsz; i++)
151 + if (pack_revindex[i].revindex)
152 + free(pack_revindex[i].revindex);
153 + free(pack_revindex);
154 + pack_revindex_hashsz = 0;
155 + }
156 +}
pack-revindex.h
+1
@@ -7,5 +7,6 @@ struct revindex_entry {
7 };
8
9 struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs);
10 +void discard_revindex(void);
11
12 #endif
sha1_file.c
+1
@@ -990,6 +990,7 @@ void prepare_packed_git(void)
990
991 void reprepare_packed_git(void)
992 {
993 + discard_revindex();
994 prepare_packed_git_run_once = 0;
995 prepare_packed_git();
996 }
t/t5300-pack-object.sh
+6
@@ -186,6 +186,12 @@ test_expect_success \
186 test-2-${packname_2}.idx \
187 test-3-${packname_3}.idx'
188
189 +test_expect_success \
190 + 'verify pack -v' \
191 + 'git verify-pack -v test-1-${packname_1}.idx \
192 + test-2-${packname_2}.idx \
193 + test-3-${packname_3}.idx'
194 +
195 test_expect_success \
196 'verify-pack catches mismatched .idx and .pack files' \
197 'cat test-1-${packname_1}.idx >test-3.idx &&