Merge branch 'az/grep-group-error-message-update'
[alt-git.git] / object-file.h
blobd6414610f80b73a9dc7d04d1587c43c20d76d764
1 #ifndef OBJECT_FILE_H
2 #define OBJECT_FILE_H
4 #include "git-zlib.h"
5 #include "object.h"
7 struct index_state;
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.
13 * Its default value is 1.
15 extern int fetch_if_missing;
17 #define HASH_WRITE_OBJECT 1
18 #define HASH_FORMAT_CHECK 2
19 #define HASH_RENORMALIZE 4
20 #define HASH_SILENT 8
21 int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
22 int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
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.
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.
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.
46 enum scld_error {
47 SCLD_OK = 0,
48 SCLD_FAILED = -1,
49 SCLD_PERMS = -2,
50 SCLD_EXISTS = -3,
51 SCLD_VANISHED = -4
53 enum scld_error safe_create_leading_directories(char *path);
54 enum scld_error safe_create_leading_directories_const(const char *path);
55 enum scld_error safe_create_leading_directories_no_share(char *path);
57 int mkdir_in_gitdir(const char *path);
59 int git_open_cloexec(const char *name, int flags);
60 #define git_open(name) git_open_cloexec(name, O_RDONLY)
62 /**
63 * unpack_loose_header() initializes the data stream needed to unpack
64 * a loose object header.
66 * Returns:
68 * - ULHR_OK on success
69 * - ULHR_BAD on error
70 * - ULHR_TOO_LONG if the header was too long
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.
79 enum unpack_loose_header_result {
80 ULHR_OK,
81 ULHR_BAD,
82 ULHR_TOO_LONG,
84 enum 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);
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().
99 struct object_info;
100 int parse_loose_header(const char *hdr, struct object_info *oi);
103 * With in-core object data in "buf", rehash it to make sure the
104 * object name actually matches "oid" to detect object corruption.
106 * A negative value indicates an error, usually that the OID is not
107 * what we expected, but it might also indicate another error.
109 int check_object_signature(struct repository *r, const struct object_id *oid,
110 void *map, unsigned long size,
111 enum object_type type);
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.
118 int stream_object_signature(struct repository *r, const struct object_id *oid);
120 int finalize_object_file(const char *tmpfile, const char *filename);
122 /* Helper to check and "touch" a file */
123 int check_and_freshen_file(const char *fn, int freshen);
125 void *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);
131 #endif /* OBJECT_FILE_H */