pack: move get_size_from_delta()
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
32b42e152f
commit
7b3aa75df7
1
cache.h
1
cache.h
|
@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *)
|
||||||
|
|
||||||
extern int is_pack_valid(struct packed_git *);
|
extern int is_pack_valid(struct packed_git *);
|
||||||
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
|
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
|
||||||
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
|
|
||||||
extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
|
extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
40
packfile.c
40
packfile.c
|
@ -4,6 +4,7 @@
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "mergesort.h"
|
#include "mergesort.h"
|
||||||
#include "packfile.h"
|
#include "packfile.h"
|
||||||
|
#include "delta.h"
|
||||||
|
|
||||||
char *odb_pack_name(struct strbuf *buf,
|
char *odb_pack_name(struct strbuf *buf,
|
||||||
const unsigned char *sha1,
|
const unsigned char *sha1,
|
||||||
|
@ -909,3 +910,42 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
|
||||||
*sizep = size;
|
*sizep = size;
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long get_size_from_delta(struct packed_git *p,
|
||||||
|
struct pack_window **w_curs,
|
||||||
|
off_t curpos)
|
||||||
|
{
|
||||||
|
const unsigned char *data;
|
||||||
|
unsigned char delta_head[20], *in;
|
||||||
|
git_zstream stream;
|
||||||
|
int st;
|
||||||
|
|
||||||
|
memset(&stream, 0, sizeof(stream));
|
||||||
|
stream.next_out = delta_head;
|
||||||
|
stream.avail_out = sizeof(delta_head);
|
||||||
|
|
||||||
|
git_inflate_init(&stream);
|
||||||
|
do {
|
||||||
|
in = use_pack(p, w_curs, curpos, &stream.avail_in);
|
||||||
|
stream.next_in = in;
|
||||||
|
st = git_inflate(&stream, Z_FINISH);
|
||||||
|
curpos += stream.next_in - in;
|
||||||
|
} while ((st == Z_OK || st == Z_BUF_ERROR) &&
|
||||||
|
stream.total_out < sizeof(delta_head));
|
||||||
|
git_inflate_end(&stream);
|
||||||
|
if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
|
||||||
|
error("delta data unpack-initial failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Examine the initial part of the delta to figure out
|
||||||
|
* the result size.
|
||||||
|
*/
|
||||||
|
data = delta_head;
|
||||||
|
|
||||||
|
/* ignore base size */
|
||||||
|
get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
|
||||||
|
|
||||||
|
/* Read the result size */
|
||||||
|
return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
|
||||||
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ extern void unuse_pack(struct pack_window **);
|
||||||
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
|
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
|
||||||
|
|
||||||
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
|
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
|
||||||
|
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
|
||||||
|
|
||||||
extern void release_pack_memory(size_t);
|
extern void release_pack_memory(size_t);
|
||||||
|
|
||||||
|
|
39
sha1_file.c
39
sha1_file.c
|
@ -1101,45 +1101,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
|
||||||
return parse_sha1_header_extended(hdr, &oi, 0);
|
return parse_sha1_header_extended(hdr, &oi, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long get_size_from_delta(struct packed_git *p,
|
|
||||||
struct pack_window **w_curs,
|
|
||||||
off_t curpos)
|
|
||||||
{
|
|
||||||
const unsigned char *data;
|
|
||||||
unsigned char delta_head[20], *in;
|
|
||||||
git_zstream stream;
|
|
||||||
int st;
|
|
||||||
|
|
||||||
memset(&stream, 0, sizeof(stream));
|
|
||||||
stream.next_out = delta_head;
|
|
||||||
stream.avail_out = sizeof(delta_head);
|
|
||||||
|
|
||||||
git_inflate_init(&stream);
|
|
||||||
do {
|
|
||||||
in = use_pack(p, w_curs, curpos, &stream.avail_in);
|
|
||||||
stream.next_in = in;
|
|
||||||
st = git_inflate(&stream, Z_FINISH);
|
|
||||||
curpos += stream.next_in - in;
|
|
||||||
} while ((st == Z_OK || st == Z_BUF_ERROR) &&
|
|
||||||
stream.total_out < sizeof(delta_head));
|
|
||||||
git_inflate_end(&stream);
|
|
||||||
if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
|
|
||||||
error("delta data unpack-initial failed");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Examine the initial part of the delta to figure out
|
|
||||||
* the result size.
|
|
||||||
*/
|
|
||||||
data = delta_head;
|
|
||||||
|
|
||||||
/* ignore base size */
|
|
||||||
get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
|
|
||||||
|
|
||||||
/* Read the result size */
|
|
||||||
return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
|
|
||||||
}
|
|
||||||
|
|
||||||
static off_t get_delta_base(struct packed_git *p,
|
static off_t get_delta_base(struct packed_git *p,
|
||||||
struct pack_window **w_curs,
|
struct pack_window **w_curs,
|
||||||
off_t *curpos,
|
off_t *curpos,
|
||||||
|
|
Loading…
Reference in New Issue