Skip to content

Commit 7b3aa75

Browse files
jonathantanmygitster
authored andcommitted
pack: move get_size_from_delta()
Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32b42e1 commit 7b3aa75

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *)
16631663

16641664
extern int is_pack_valid(struct packed_git *);
16651665
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
1666-
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
16671666
extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
16681667

16691668
/*

packfile.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "dir.h"
55
#include "mergesort.h"
66
#include "packfile.h"
7+
#include "delta.h"
78

89
char *odb_pack_name(struct strbuf *buf,
910
const unsigned char *sha1,
@@ -909,3 +910,42 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
909910
*sizep = size;
910911
return used;
911912
}
913+
914+
unsigned long get_size_from_delta(struct packed_git *p,
915+
struct pack_window **w_curs,
916+
off_t curpos)
917+
{
918+
const unsigned char *data;
919+
unsigned char delta_head[20], *in;
920+
git_zstream stream;
921+
int st;
922+
923+
memset(&stream, 0, sizeof(stream));
924+
stream.next_out = delta_head;
925+
stream.avail_out = sizeof(delta_head);
926+
927+
git_inflate_init(&stream);
928+
do {
929+
in = use_pack(p, w_curs, curpos, &stream.avail_in);
930+
stream.next_in = in;
931+
st = git_inflate(&stream, Z_FINISH);
932+
curpos += stream.next_in - in;
933+
} while ((st == Z_OK || st == Z_BUF_ERROR) &&
934+
stream.total_out < sizeof(delta_head));
935+
git_inflate_end(&stream);
936+
if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
937+
error("delta data unpack-initial failed");
938+
return 0;
939+
}
940+
941+
/* Examine the initial part of the delta to figure out
942+
* the result size.
943+
*/
944+
data = delta_head;
945+
946+
/* ignore base size */
947+
get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
948+
949+
/* Read the result size */
950+
return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
951+
}

packfile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern void unuse_pack(struct pack_window **);
6363
extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
6464

6565
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
66+
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
6667

6768
extern void release_pack_memory(size_t);
6869

sha1_file.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,45 +1101,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
11011101
return parse_sha1_header_extended(hdr, &oi, 0);
11021102
}
11031103

1104-
unsigned long get_size_from_delta(struct packed_git *p,
1105-
struct pack_window **w_curs,
1106-
off_t curpos)
1107-
{
1108-
const unsigned char *data;
1109-
unsigned char delta_head[20], *in;
1110-
git_zstream stream;
1111-
int st;
1112-
1113-
memset(&stream, 0, sizeof(stream));
1114-
stream.next_out = delta_head;
1115-
stream.avail_out = sizeof(delta_head);
1116-
1117-
git_inflate_init(&stream);
1118-
do {
1119-
in = use_pack(p, w_curs, curpos, &stream.avail_in);
1120-
stream.next_in = in;
1121-
st = git_inflate(&stream, Z_FINISH);
1122-
curpos += stream.next_in - in;
1123-
} while ((st == Z_OK || st == Z_BUF_ERROR) &&
1124-
stream.total_out < sizeof(delta_head));
1125-
git_inflate_end(&stream);
1126-
if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
1127-
error("delta data unpack-initial failed");
1128-
return 0;
1129-
}
1130-
1131-
/* Examine the initial part of the delta to figure out
1132-
* the result size.
1133-
*/
1134-
data = delta_head;
1135-
1136-
/* ignore base size */
1137-
get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1138-
1139-
/* Read the result size */
1140-
return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1141-
}
1142-
11431104
static off_t get_delta_base(struct packed_git *p,
11441105
struct pack_window **w_curs,
11451106
off_t *curpos,

0 commit comments

Comments
 (0)