Skip to content

Commit 32b42e1

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

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
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 unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
16671666
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
16681667
extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
16691668

packfile.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,3 +884,28 @@ void reprepare_packed_git(void)
884884
prepare_packed_git_run_once = 0;
885885
prepare_packed_git();
886886
}
887+
888+
unsigned long unpack_object_header_buffer(const unsigned char *buf,
889+
unsigned long len, enum object_type *type, unsigned long *sizep)
890+
{
891+
unsigned shift;
892+
unsigned long size, c;
893+
unsigned long used = 0;
894+
895+
c = buf[used++];
896+
*type = (c >> 4) & 7;
897+
size = c & 15;
898+
shift = 4;
899+
while (c & 0x80) {
900+
if (len <= used || bitsizeof(long) <= shift) {
901+
error("bad object header");
902+
size = used = 0;
903+
break;
904+
}
905+
c = buf[used++];
906+
size += (c & 0x7f) << shift;
907+
shift += 7;
908+
}
909+
*sizep = size;
910+
return used;
911+
}

packfile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ extern void close_all_packs(void);
6262
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

65+
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
66+
6567
extern void release_pack_memory(size_t);
6668

6769
extern int open_packed_git(struct packed_git *p);

sha1_file.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -915,31 +915,6 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
915915
return map_sha1_file_1(NULL, sha1, size);
916916
}
917917

918-
unsigned long unpack_object_header_buffer(const unsigned char *buf,
919-
unsigned long len, enum object_type *type, unsigned long *sizep)
920-
{
921-
unsigned shift;
922-
unsigned long size, c;
923-
unsigned long used = 0;
924-
925-
c = buf[used++];
926-
*type = (c >> 4) & 7;
927-
size = c & 15;
928-
shift = 4;
929-
while (c & 0x80) {
930-
if (len <= used || bitsizeof(long) <= shift) {
931-
error("bad object header");
932-
size = used = 0;
933-
break;
934-
}
935-
c = buf[used++];
936-
size += (c & 0x7f) << shift;
937-
shift += 7;
938-
}
939-
*sizep = size;
940-
return used;
941-
}
942-
943918
static int unpack_sha1_short_header(git_zstream *stream,
944919
unsigned char *map, unsigned long mapsize,
945920
void *buffer, unsigned long bufsiz)

0 commit comments

Comments
 (0)