#ifndef INCLUDE_pack_h__
#define INCLUDE_pack_h__
#include "common.h"
#include <zlib.h>
#include "git2/oid.h"
#include "map.h"
#include "mwindow.h"
#include "odb.h"
#include "oidmap.h"
#include "array.h"
#define GIT_PACK_FILE_MODE 0444
#define PACK_SIGNATURE 0x5041434b
#define PACK_VERSION 2
#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
struct git_pack_header {
uint32_t hdr_signature;
uint32_t hdr_version;
uint32_t hdr_entries;
};
#define PACK_IDX_SIGNATURE 0xff744f63
struct git_pack_idx_header {
uint32_t idx_signature;
uint32_t idx_version;
};
typedef struct git_pack_cache_entry {
size_t last_usage;
git_atomic refcount;
git_rawobj raw;
} git_pack_cache_entry;
struct pack_chain_elem {
git_off_t base_key;
git_off_t offset;
size_t size;
git_object_t type;
};
typedef git_array_t(struct pack_chain_elem) git_dependency_chain;
#include "offmap.h"
#include "oidmap.h"
#define GIT_PACK_CACHE_MEMORY_LIMIT 16 * 1024 * 1024
#define GIT_PACK_CACHE_SIZE_LIMIT 1024 * 1024
typedef struct {
size_t memory_used;
size_t memory_limit;
size_t use_ctr;
git_mutex lock;
git_offmap *entries;
} git_pack_cache;
struct git_pack_file {
git_mwindow_file mwf;
git_map index_map;
git_mutex lock;
git_atomic refcount;
uint32_t num_objects;
uint32_t num_bad_objects;
git_oid *bad_object_sha1;
int index_version;
git_time_t mtime;
unsigned pack_local:1, pack_keep:1, has_cache:1;
git_oidmap *idx_cache;
git_oid **oids;
git_pack_cache bases;
time_t last_freshen;
char pack_name[GIT_FLEX_ARRAY];
};
struct git_pack_entry {
git_off_t offset;
git_oid sha1;
struct git_pack_file *p;
};
typedef struct git_packfile_stream {
git_off_t curpos;
int done;
z_stream zstream;
struct git_pack_file *p;
git_mwindow *mw;
} git_packfile_stream;
size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type);
int git_packfile__name(char **out, const char *path);
int git_packfile_unpack_header(
size_t *size_p,
git_object_t *type_p,
git_mwindow_file *mwf,
git_mwindow **w_curs,
git_off_t *curpos);
int git_packfile_resolve_header(
size_t *size_p,
git_object_t *type_p,
struct git_pack_file *p,
git_off_t offset);
int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, git_off_t *obj_offset);
int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, git_off_t curpos);
ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
void git_packfile_stream_dispose(git_packfile_stream *obj);
git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
git_off_t *curpos, git_object_t type,
git_off_t delta_obj_offset);
void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
void git_packfile_free(struct git_pack_file *p);
int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);
int git_pack_entry_find(
struct git_pack_entry *e,
struct git_pack_file *p,
const git_oid *short_oid,
size_t len);
int git_pack_foreach_entry(
struct git_pack_file *p,
git_odb_foreach_cb cb,
void *data);
#endif