]> git.ipfire.org Git - thirdparty/git.git/blame - object-file.h
khash: name the structs that khash declares
[thirdparty/git.git] / object-file.h
CommitLineData
87bed179
EN
1#ifndef OBJECT_FILE_H
2#define OBJECT_FILE_H
3
4#include "git-zlib.h"
5#include "object.h"
6
d1cbe1e6
EN
7struct index_state;
8
87bed179
EN
9/*
10 * Set this to 0 to prevent oid_object_info_extended() from fetching missing
11 * blobs. This has a difference only if extensions.partialClone is set.
12 *
13 * Its default value is 1.
14 */
15extern int fetch_if_missing;
16
17#define HASH_WRITE_OBJECT 1
18#define HASH_FORMAT_CHECK 2
19#define HASH_RENORMALIZE 4
20#define HASH_SILENT 8
21int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
22int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
23
24/*
25 * Create the directory containing the named path, using care to be
26 * somewhat safe against races. Return one of the scld_error values to
27 * indicate success/failure. On error, set errno to describe the
28 * problem.
29 *
30 * SCLD_VANISHED indicates that one of the ancestor directories of the
31 * path existed at one point during the function call and then
32 * suddenly vanished, probably because another process pruned the
33 * directory while we were working. To be robust against this kind of
34 * race, callers might want to try invoking the function again when it
35 * returns SCLD_VANISHED.
36 *
37 * safe_create_leading_directories() temporarily changes path while it
38 * is working but restores it before returning.
39 * safe_create_leading_directories_const() doesn't modify path, even
40 * temporarily. Both these variants adjust the permissions of the
41 * created directories to honor core.sharedRepository, so they are best
42 * suited for files inside the git dir. For working tree files, use
43 * safe_create_leading_directories_no_share() instead, as it ignores
44 * the core.sharedRepository setting.
45 */
46enum scld_error {
47 SCLD_OK = 0,
48 SCLD_FAILED = -1,
49 SCLD_PERMS = -2,
50 SCLD_EXISTS = -3,
51 SCLD_VANISHED = -4
52};
53enum scld_error safe_create_leading_directories(char *path);
54enum scld_error safe_create_leading_directories_const(const char *path);
55enum scld_error safe_create_leading_directories_no_share(char *path);
56
57int mkdir_in_gitdir(const char *path);
58
59int git_open_cloexec(const char *name, int flags);
60#define git_open(name) git_open_cloexec(name, O_RDONLY)
61
62/**
63 * unpack_loose_header() initializes the data stream needed to unpack
64 * a loose object header.
65 *
66 * Returns:
67 *
68 * - ULHR_OK on success
69 * - ULHR_BAD on error
70 * - ULHR_TOO_LONG if the header was too long
71 *
72 * It will only parse up to MAX_HEADER_LEN bytes unless an optional
73 * "hdrbuf" argument is non-NULL. This is intended for use with
74 * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error)
75 * reporting. The full header will be extracted to "hdrbuf" for use
76 * with parse_loose_header(), ULHR_TOO_LONG will still be returned
77 * from this function to indicate that the header was too long.
78 */
79enum unpack_loose_header_result {
80 ULHR_OK,
81 ULHR_BAD,
82 ULHR_TOO_LONG,
83};
84enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
85 unsigned char *map,
86 unsigned long mapsize,
87 void *buffer,
88 unsigned long bufsiz,
89 struct strbuf *hdrbuf);
90
91/**
92 * parse_loose_header() parses the starting "<type> <len>\0" of an
93 * object. If it doesn't follow that format -1 is returned. To check
94 * the validity of the <type> populate the "typep" in the "struct
95 * object_info". It will be OBJ_BAD if the object type is unknown. The
96 * parsed <len> can be retrieved via "oi->sizep", and from there
97 * passed to unpack_loose_rest().
98 */
99struct object_info;
100int parse_loose_header(const char *hdr, struct object_info *oi);
101
102/**
103 * With in-core object data in "buf", rehash it to make sure the
104 * object name actually matches "oid" to detect object corruption.
105 *
106 * A negative value indicates an error, usually that the OID is not
107 * what we expected, but it might also indicate another error.
108 */
109int check_object_signature(struct repository *r, const struct object_id *oid,
110 void *map, unsigned long size,
111 enum object_type type);
112
113/**
114 * A streaming version of check_object_signature().
115 * Try reading the object named with "oid" using
116 * the streaming interface and rehash it to do the same.
117 */
118int stream_object_signature(struct repository *r, const struct object_id *oid);
119
120int finalize_object_file(const char *tmpfile, const char *filename);
121
122/* Helper to check and "touch" a file */
123int check_and_freshen_file(const char *fn, int freshen);
124
125void *read_object_with_reference(struct repository *r,
126 const struct object_id *oid,
127 enum object_type required_type,
128 unsigned long *size,
129 struct object_id *oid_ret);
130
131#endif /* OBJECT_FILE_H */