]> git.proxmox.com Git - libgit2.git/blame - src/odb.h
Fixed size_t format string warning
[libgit2.git] / src / odb.h
CommitLineData
bb742ede 1/*
5e0de328 2 * Copyright (C) 2009-2012 the libgit2 contributors
bb742ede
VM
3 *
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.
6 */
a7c60cfc
SP
7#ifndef INCLUDE_odb_h__
8#define INCLUDE_odb_h__
9
44908fe7
VM
10#include "git2/odb.h"
11#include "git2/oid.h"
72a3fe42 12#include "git2/types.h"
7d7cd885
VM
13
14#include "vector.h"
72a3fe42 15#include "cache.h"
18e5b854 16#include "posix.h"
7d7cd885 17
ce8cd006
BR
18#define GIT_OBJECTS_DIR "objects/"
19#define GIT_OBJECT_DIR_MODE 0777
01ad7b3a 20#define GIT_OBJECT_FILE_MODE 0444
ce8cd006 21
72a3fe42
VM
22/* DO NOT EXPORT */
23typedef struct {
87d9869f
VM
24 void *data; /**< Raw, decompressed object data. */
25 size_t len; /**< Total number of bytes in data. */
26 git_otype type; /**< Type of this object. */
72a3fe42
VM
27} git_rawobj;
28
29/* EXPORT */
30struct git_odb_object {
31 git_cached_obj cached;
32 git_rawobj raw;
33};
34
35/* EXPORT */
7d7cd885 36struct git_odb {
9462c471 37 git_refcount rc;
7d7cd885 38 git_vector backends;
72a3fe42 39 git_cache cache;
7d7cd885
VM
40};
41
f19e3ca2
VM
42/*
43 * Hash a git_rawobj internally.
44 * The `git_rawobj` is supposed to be previously initialized
45 */
18e5b854 46int git_odb__hashobj(git_oid *id, git_rawobj *obj);
f19e3ca2 47
f56f8585
CMN
48/*
49 * Format the object header such as it would appear in the on-disk object
50 */
51int git_odb__format_object_header(char *hdr, size_t n, size_t obj_len, git_otype obj_type);
f19e3ca2
VM
52/*
53 * Hash an open file descriptor.
54 * This is a performance call when the contents of a fd need to be hashed,
55 * but the fd is already open and we have the size of the contents.
56 *
57 * Saves us some `stat` calls.
58 *
59 * The fd is never closed, not even on error. It must be opened and closed
60 * by the caller
61 */
18e5b854 62int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type);
7d7cd885 63
f19e3ca2 64/*
60b9d3fc
RB
65 * Hash an open file descriptor applying an array of filters
66 * Acts just like git_odb__hashfd with the addition of filters...
67 */
68int git_odb__hashfd_filtered(
69 git_oid *out, git_file fd, size_t len, git_otype type, git_vector *filters);
70
71/*
72 * Hash a `path`, assuming it could be a POSIX symlink: if the path is a
73 * symlink, then the raw contents of the symlink will be hashed. Otherwise,
74 * this will fallback to `git_odb__hashfd`.
f19e3ca2 75 *
60b9d3fc
RB
76 * The hash type for this call is always `GIT_OBJ_BLOB` because symlinks may
77 * only point to blobs.
f19e3ca2
VM
78 */
79int git_odb__hashlink(git_oid *out, const char *path);
80
e1de726c
RB
81/*
82 * Generate a GIT_ENOTFOUND error for the ODB.
83 */
282283ac 84int git_odb__error_notfound(const char *message, const git_oid *oid);
e1de726c
RB
85
86/*
87 * Generate a GIT_EAMBIGUOUS error for the ODB.
88 */
89int git_odb__error_ambiguous(const char *message);
90
c6ac28fd
RB
91/*
92 * Attempt to read object header or just return whole object if it could
93 * not be read.
94 */
95int git_odb__read_header_or_object(
96 git_odb_object **out, size_t *len_p, git_otype *type_p,
97 git_odb *db, const git_oid *id);
98
a7c60cfc 99#endif