@matheusbsbs / matheus-bagliano / commits / fa5fc15d6e
Fork 0

Introduce close_pack_index to permit replacement

By closing the pack index, a caller can later overwrite the index with an updated index file, possibly after converting from v1 to the v2 format. Because p->index_data is NULL after close, on the next access the index will be opened again and the other members will be updated with new data. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Apr 19, 2010 at 07:23 UTC fa5fc15d6ecfb9452c578bb4c80e98ccca12750c
2 files changed +10 -2
cache.h
+1
@@ -911,6 +911,7 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
911
912 extern void pack_report(void);
913 extern int open_pack_index(struct packed_git *);
914 +extern void close_pack_index(struct packed_git *);
915 extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
916 extern void close_pack_windows(struct packed_git *);
917 extern void unuse_pack(struct pack_window **);
sha1_file.c
+9 -2
@@ -606,6 +606,14 @@ void unuse_pack(struct pack_window **w_cursor)
606 }
607 }
608
609 +void close_pack_index(struct packed_git *p)
610 +{
611 + if (p->index_data) {
612 + munmap((void *)p->index_data, p->index_size);
613 + p->index_data = NULL;
614 + }
615 +}
616 +
617 /*
618 * This is used by git-repack in case a newly created pack happens to
619 * contain the same set of objects as an existing one. In that case
@@ -627,8 +635,7 @@ void free_pack_by_name(const char *pack_name)
635 close_pack_windows(p);
636 if (p->pack_fd != -1)
637 close(p->pack_fd);
630 - if (p->index_data)
631 - munmap((void *)p->index_data, p->index_size);
638 + close_pack_index(p);
639 free(p->bad_object_sha1);
640 *pp = p->next;
641 free(p);