Skip to content

Commit f965c52

Browse files
npitregitster
authored andcommitted
move encode_in_pack_object_header() to a better place
Commit 1b22b6c made duplicated versions of encode_header() into a common version called encode_in_pack_object_header(). There is however a better location that sha1_file.c for such a function though, as sha1_file.c contains nothing related to the creation of packs, and it is quite populated already. Also the comment that was moved to the header file should really remain near the function as it covers implementation details and provides no information about the actual function interface. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1b22b6c commit f965c52

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

cache.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -911,14 +911,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign
911911
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
912912
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
913913
extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
914-
/*
915-
* The per-object header is a pretty dense thing, which is
916-
* - first byte: low four bits are "size", then three bits of "type",
917-
* and the high bit is "size continues".
918-
* - each byte afterwards: low seven bits are size continuation,
919-
* with the high bit being "size continues"
920-
*/
921-
int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr);
922914

923915
/* Dumb servers support */
924916
extern int update_server_info(int);

pack-write.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,30 @@ char *index_pack_lockfile(int ip_out)
253253
}
254254
return NULL;
255255
}
256+
257+
/*
258+
* The per-object header is a pretty dense thing, which is
259+
* - first byte: low four bits are "size", then three bits of "type",
260+
* and the high bit is "size continues".
261+
* - each byte afterwards: low seven bits are size continuation,
262+
* with the high bit being "size continues"
263+
*/
264+
int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr)
265+
{
266+
int n = 1;
267+
unsigned char c;
268+
269+
if (type < OBJ_COMMIT || type > OBJ_REF_DELTA)
270+
die("bad type %d", type);
271+
272+
c = (type << 4) | (size & 15);
273+
size >>= 4;
274+
while (size) {
275+
*hdr++ = c | 0x80;
276+
c = size & 0x7f;
277+
size >>= 7;
278+
n++;
279+
}
280+
*hdr = c;
281+
return n;
282+
}

pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off
6060
extern int verify_pack(struct packed_git *);
6161
extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
6262
extern char *index_pack_lockfile(int fd);
63+
extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned char *);
6364

6465
#define PH_ERROR_EOF (-1)
6566
#define PH_ERROR_PACK_SIGNATURE (-2)

sha1_file.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,26 +1475,6 @@ const char *packed_object_info_detail(struct packed_git *p,
14751475
}
14761476
}
14771477

1478-
int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr)
1479-
{
1480-
int n = 1;
1481-
unsigned char c;
1482-
1483-
if (type < OBJ_COMMIT || type > OBJ_REF_DELTA)
1484-
die("bad type %d", type);
1485-
1486-
c = (type << 4) | (size & 15);
1487-
size >>= 4;
1488-
while (size) {
1489-
*hdr++ = c | 0x80;
1490-
c = size & 0x7f;
1491-
size >>= 7;
1492-
n++;
1493-
}
1494-
*hdr = c;
1495-
return n;
1496-
}
1497-
14981478
static int packed_object_info(struct packed_git *p, off_t obj_offset,
14991479
unsigned long *sizep)
15001480
{

0 commit comments

Comments
 (0)