]>
Commit | Line | Data |
---|---|---|
f5918330 | 1 | /* |
5e0de328 | 2 | * Copyright (C) 2009-2012 the libgit2 contributors |
f5918330 | 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. | |
f5918330 | 6 | */ |
237da401 VM |
7 | #ifndef INCLUDE_git_blob_h__ |
8 | #define INCLUDE_git_blob_h__ | |
9 | ||
10 | #include "common.h" | |
d12299fe | 11 | #include "types.h" |
237da401 | 12 | #include "oid.h" |
5de079b8 | 13 | #include "object.h" |
237da401 VM |
14 | |
15 | /** | |
f5918330 | 16 | * @file git2/blob.h |
237da401 VM |
17 | * @brief Git blob load and write routines |
18 | * @defgroup git_blob Git blob load and write routines | |
19 | * @ingroup Git | |
20 | * @{ | |
21 | */ | |
22 | GIT_BEGIN_DECL | |
23 | ||
237da401 VM |
24 | /** |
25 | * Lookup a blob object from a repository. | |
237da401 VM |
26 | * |
27 | * @param blob pointer to the looked up blob | |
28 | * @param repo the repo to use when locating the blob. | |
29 | * @param id identity of the blob to locate. | |
d9111722 | 30 | * @return GIT_SUCCESS or an error code |
237da401 | 31 | */ |
e52ed7a5 VM |
32 | GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id) |
33 | { | |
5de079b8 | 34 | return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB); |
e52ed7a5 | 35 | } |
237da401 | 36 | |
790c6c95 MP |
37 | /** |
38 | * Lookup a blob object from a repository, | |
39 | * given a prefix of its identifier (short id). | |
40 | * | |
41 | * @see git_object_lookup_prefix | |
42 | * | |
43 | * @param blob pointer to the looked up blob | |
44 | * @param repo the repo to use when locating the blob. | |
45 | * @param id identity of the blob to locate. | |
46 | * @param len the length of the short identifier | |
d9111722 | 47 | * @return GIT_SUCCESS or an error code |
790c6c95 MP |
48 | */ |
49 | GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, unsigned int len) | |
50 | { | |
51 | return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB); | |
52 | } | |
53 | ||
b0b83135 CMN |
54 | /** |
55 | * Close an open blob | |
56 | * | |
45e79e37 | 57 | * This is a wrapper around git_object_free() |
b0b83135 CMN |
58 | * |
59 | * IMPORTANT: | |
60 | * It *is* necessary to call this method when you stop | |
61 | * using a blob. Failure to do so will cause a memory leak. | |
62 | * | |
63 | * @param blob the blob to close | |
64 | */ | |
65 | ||
45e79e37 | 66 | GIT_INLINE(void) git_blob_free(git_blob *blob) |
b0b83135 | 67 | { |
45e79e37 | 68 | git_object_free((git_object *) blob); |
b0b83135 CMN |
69 | } |
70 | ||
71 | ||
237da401 | 72 | /** |
30b171a1 | 73 | * Get a read-only buffer with the raw content of a blob. |
237da401 | 74 | * |
30b171a1 VM |
75 | * A pointer to the raw content of a blob is returned; |
76 | * this pointer is owned internally by the object and shall | |
77 | * not be free'd. The pointer may be invalidated at a later | |
72a3fe42 | 78 | * time. |
237da401 VM |
79 | * |
80 | * @param blob pointer to the blob | |
30b171a1 | 81 | * @return the pointer; NULL if the blob has no contents |
237da401 | 82 | */ |
3490188b | 83 | GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob); |
237da401 VM |
84 | |
85 | /** | |
86 | * Get the size in bytes of the contents of a blob | |
87 | * | |
88 | * @param blob pointer to the blob | |
89 | * @return size on bytes | |
90 | */ | |
26e74c6a | 91 | GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob); |
237da401 VM |
92 | |
93 | /** | |
94 | * Read a file from the working folder of a repository | |
72a3fe42 | 95 | * and write it to the Object Database as a loose blob |
237da401 | 96 | * |
72a3fe42 VM |
97 | * @param oid return the id of the written blob |
98 | * @param repo repository where the blob will be written. | |
99 | * this repository cannot be bare | |
100 | * @param path file from which the blob will be created, | |
101 | * relative to the repository's working dir | |
d9111722 | 102 | * @return GIT_SUCCESS or an error code |
72a3fe42 VM |
103 | */ |
104 | GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path); | |
105 | ||
106 | ||
107 | /** | |
108 | * Write an in-memory buffer to the ODB as a blob | |
109 | * | |
110 | * @param oid return the oid of the written blob | |
111 | * @param repo repository where to blob will be written | |
112 | * @param buffer data to be written into the blob | |
113 | * @param len length of the data | |
d9111722 | 114 | * @return GIT_SUCCESS or an error code |
237da401 | 115 | */ |
72a3fe42 | 116 | GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len); |
237da401 VM |
117 | |
118 | /** @} */ | |
119 | GIT_END_DECL | |
120 | #endif |