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>
This commit is contained in:
parent
162eb5f838
commit
fa5fc15d6e
1
cache.h
1
cache.h
@ -911,6 +911,7 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
|
|||||||
|
|
||||||
extern void pack_report(void);
|
extern void pack_report(void);
|
||||||
extern int open_pack_index(struct packed_git *);
|
extern int open_pack_index(struct packed_git *);
|
||||||
|
extern void close_pack_index(struct packed_git *);
|
||||||
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
|
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
|
||||||
extern void close_pack_windows(struct packed_git *);
|
extern void close_pack_windows(struct packed_git *);
|
||||||
extern void unuse_pack(struct pack_window **);
|
extern void unuse_pack(struct pack_window **);
|
||||||
|
11
sha1_file.c
11
sha1_file.c
@ -606,6 +606,14 @@ void unuse_pack(struct pack_window **w_cursor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void close_pack_index(struct packed_git *p)
|
||||||
|
{
|
||||||
|
if (p->index_data) {
|
||||||
|
munmap((void *)p->index_data, p->index_size);
|
||||||
|
p->index_data = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is used by git-repack in case a newly created pack happens to
|
* This is used by git-repack in case a newly created pack happens to
|
||||||
* contain the same set of objects as an existing one. In that case
|
* 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)
|
|||||||
close_pack_windows(p);
|
close_pack_windows(p);
|
||||||
if (p->pack_fd != -1)
|
if (p->pack_fd != -1)
|
||||||
close(p->pack_fd);
|
close(p->pack_fd);
|
||||||
if (p->index_data)
|
close_pack_index(p);
|
||||||
munmap((void *)p->index_data, p->index_size);
|
|
||||||
free(p->bad_object_sha1);
|
free(p->bad_object_sha1);
|
||||||
*pp = p->next;
|
*pp = p->next;
|
||||||
free(p);
|
free(p);
|
||||||
|
Loading…
Reference in New Issue
Block a user