]> git.proxmox.com Git - libgit2.git/blame - src/pack.h
fileops/repository: create (most) directories with 0777 permissions
[libgit2.git] / src / pack.h
CommitLineData
c7c9e183 1/*
bb742ede 2 * Copyright (C) 2009-2011 the libgit2 contributors
c7c9e183 3 *
bb742ede
VM
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
c7c9e183
CMN
6 */
7
8#ifndef INCLUDE_pack_h__
9#define INCLUDE_pack_h__
10
11#include "git2/oid.h"
12
13#include "common.h"
14#include "map.h"
15#include "mwindow.h"
7d0cdf82 16#include "odb.h"
c7c9e183
CMN
17
18#define PACK_SIGNATURE 0x5041434b /* "PACK" */
19#define PACK_VERSION 2
20#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
a070f152 21struct git_pack_header {
c7c9e183
CMN
22 uint32_t hdr_signature;
23 uint32_t hdr_version;
24 uint32_t hdr_entries;
25};
26
27/*
28 * The first four bytes of index formats later than version 1 should
29 * start with this signature, as all older git binaries would find this
30 * value illegal and abort reading the file.
31 *
32 * This is the case because the number of objects in a packfile
33 * cannot exceed 1,431,660,000 as every object would need at least
34 * 3 bytes of data and the overall packfile cannot exceed 4 GiB with
35 * version 1 of the index file due to the offsets limited to 32 bits.
36 * Clearly the signature exceeds this maximum.
37 *
38 * Very old git binaries will also compare the first 4 bytes to the
39 * next 4 bytes in the index and abort with a "non-monotonic index"
40 * error if the second 4 byte word is smaller than the first 4
87d9869f 41 * byte word. This would be true in the proposed future index
c7c9e183
CMN
42 * format as idx_signature would be greater than idx_version.
43 */
44
45#define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */
46
a070f152 47struct git_pack_idx_header {
c7c9e183
CMN
48 uint32_t idx_signature;
49 uint32_t idx_version;
50};
51
a070f152 52struct git_pack_file {
c7c9e183 53 git_mwindow_file mwf;
c7c9e183
CMN
54 git_map index_map;
55
56 uint32_t num_objects;
57 uint32_t num_bad_objects;
58 git_oid *bad_object_sha1; /* array of git_oid */
59
60 int index_version;
61 git_time_t mtime;
c1af5a39 62 unsigned pack_local:1, pack_keep:1, has_cache:1;
c7c9e183 63 git_oid sha1;
c1af5a39 64 git_vector cache;
c7c9e183
CMN
65
66 /* something like ".git/objects/pack/xxxxx.pack" */
67 char pack_name[GIT_FLEX_ARRAY]; /* more */
68};
69
a070f152 70struct git_pack_entry {
c7c9e183
CMN
71 off_t offset;
72 git_oid sha1;
a070f152 73 struct git_pack_file *p;
c7c9e183
CMN
74};
75
7d0cdf82
CMN
76int git_packfile_unpack_header(
77 size_t *size_p,
78 git_otype *type_p,
79 git_mwindow_file *mwf,
80 git_mwindow **w_curs,
81 off_t *curpos);
82
b5b474dd 83int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, off_t *obj_offset);
7d0cdf82 84
a070f152 85off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
7d0cdf82
CMN
86 off_t *curpos, git_otype type,
87 off_t delta_obj_offset);
88
a070f152
CMN
89void packfile_free(struct git_pack_file *p);
90int git_packfile_check(struct git_pack_file **pack_out, const char *path);
91int git_pack_entry_find(
92 struct git_pack_entry *e,
93 struct git_pack_file *p,
94 const git_oid *short_oid,
95 unsigned int len);
96
c7c9e183 97#endif