]>
git.proxmox.com Git - libgit2.git/blob - src/reader.h
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_reader_h__
8 #define INCLUDE_reader_h__
12 /* Returned when the workdir does not match the index */
13 #define GIT_READER_MISMATCH 1
15 typedef struct git_reader git_reader
;
18 * The `git_reader` structure is a generic interface for reading the
19 * contents of a file by its name, and implementations are provided
20 * for reading out of a tree, the index, and the working directory.
22 * Note that the reader implementation is meant to have a short
23 * lifecycle and does not increase the refcount of the object that
24 * it's reading. Callers should ensure that they do not use a
25 * reader after disposing the underlying object that it reads.
28 int (*read
)(git_buf
*out
, git_oid
*out_oid
, git_filemode_t
*mode
, git_reader
*reader
, const char *filename
);
32 * Create a `git_reader` that will allow random access to the given
33 * tree. Paths requested via `git_reader_read` will be rooted at this
34 * tree, callers are not expected to recurse through tree lookups. Thus,
35 * you can request to read `/src/foo.c` and the tree provided to this
36 * function will be searched to find another tree named `src`, which
37 * will then be opened to find `foo.c`.
39 * @param out The reader for the given tree
40 * @param tree The tree object to read
41 * @return 0 on success, or an error code < 0
43 extern int git_reader_for_tree(
48 * Create a `git_reader` that will allow random access to the given
49 * index, or the repository's index.
51 * @param out The reader for the given index
52 * @param repo The repository containing the index
53 * @param index The index to read, or NULL to use the repository's index
54 * @return 0 on success, or an error code < 0
56 extern int git_reader_for_index(
62 * Create a `git_reader` that will allow random access to the given
63 * repository's working directory. Note that the contents are read
64 * in repository format, meaning any workdir -> odb filters are
67 * If `validate_index` is set to true, reads of files will hash the
68 * on-disk contents and ensure that the resulting object ID matches
69 * the repository's index. This ensures that the working directory
70 * is unmodified from the index contents.
72 * @param out The reader for the given working directory
73 * @param repo The repository containing the working directory
74 * @param validate_index If true, the working directory contents will
75 * be compared to the index contents during read to ensure that
76 * the working directory is unmodified.
77 * @return 0 on success, or an error code < 0
79 extern int git_reader_for_workdir(
85 * Read the given filename from the reader and populate the given buffer
86 * with the contents and the given oid with the object ID.
88 * @param out The buffer to populate with the file contents
89 * @param out_id The oid to populate with the object ID
90 * @param reader The reader to read
91 * @param filename The filename to read from the reader
93 extern int git_reader_read(
96 git_filemode_t
*out_filemode
,
98 const char *filename
);
101 * Free the given reader and any associated objects.
103 * @param reader The reader to free
105 extern void git_reader_free(git_reader
*reader
);