Skip to content

Commit 7b64469

Browse files
spearcegitster
authored andcommitted
Allow parse_pack_index on temporary files
The easiest way to verify a pack index is to open it through the standard parse_pack_index function, permitting the header check to happen when the file is mapped. However, the dumb HTTP client needs to verify a pack index before its moved into its proper file name within the objects/pack directory, to prevent a corrupt index from being made available. So permit the caller to specify the exact path of the index file. For now we're still using the final destination name within the sole call site in http.c, but eventually we will start to parse the temporary path instead. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b0aa72 commit 7b64469

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ struct extra_have_objects {
900900
extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags, struct extra_have_objects *);
901901
extern int server_supports(const char *feature);
902902

903-
extern struct packed_git *parse_pack_index(unsigned char *sha1);
903+
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
904904

905905
extern void prepare_packed_git(void);
906906
extern void reprepare_packed_git(void);

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
932932
if (fetch_pack_index(sha1, base_url))
933933
return -1;
934934

935-
new_pack = parse_pack_index(sha1);
935+
new_pack = parse_pack_index(sha1, sha1_pack_index_name(sha1));
936936
if (!new_pack)
937937
return -1; /* parse_pack_index() already issued error message */
938938
new_pack->next = *packs_head;

sha1_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,8 @@ struct packed_git *add_packed_git(const char *path, int path_len, int local)
845845
return p;
846846
}
847847

848-
struct packed_git *parse_pack_index(unsigned char *sha1)
848+
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
849849
{
850-
const char *idx_path = sha1_pack_index_name(sha1);
851850
const char *path = sha1_pack_name(sha1);
852851
struct packed_git *p = alloc_packed_git(strlen(path) + 1);
853852

0 commit comments

Comments
 (0)