Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 8610d88

Browse files
committed
libgit2 1.2.0
1 parent 05f4195 commit 8610d88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1396
-335
lines changed

include/git2/apply.h

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int ver
100100
* @param preimage the tree to apply the diff to
101101
* @param diff the diff to apply
102102
* @param options the options for the apply (or null for defaults)
103+
* @return 0 or an error code
103104
*/
104105
GIT_EXTERN(int) git_apply_to_tree(
105106
git_index **out,
@@ -137,6 +138,7 @@ typedef enum {
137138
* @param diff the diff to apply
138139
* @param location the location to apply (workdir, index or both)
139140
* @param options the options for the apply (or null for defaults)
141+
* @return 0 or an error code
140142
*/
141143
GIT_EXTERN(int) git_apply(
142144
git_repository *repo,

include/git2/attr.h

+89
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,32 @@ GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr);
130130
*
131131
* Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes
132132
* from a `.gitattributes` file in the repository at the HEAD revision.
133+
*
134+
* Passing the `GIT_ATTR_CHECK_INCLUDE_COMMIT` flag will use attributes
135+
* from a `.gitattributes` file in a specific commit.
133136
*/
134137
#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
135138
#define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3)
139+
#define GIT_ATTR_CHECK_INCLUDE_COMMIT (1 << 4)
140+
141+
/**
142+
* An options structure for querying attributes.
143+
*/
144+
typedef struct {
145+
unsigned int version;
146+
147+
/** A combination of GIT_ATTR_CHECK flags */
148+
unsigned int flags;
149+
150+
/**
151+
* The commit to load attributes from, when
152+
* `GIT_ATTR_CHECK_INCLUDE_COMMIT` is specified.
153+
*/
154+
git_oid *commit_id;
155+
} git_attr_options;
156+
157+
#define GIT_ATTR_OPTIONS_VERSION 1
158+
#define GIT_ATTR_OPTIONS_INIT {GIT_ATTR_OPTIONS_VERSION}
136159

137160
/**
138161
* Look up the value of one git attribute for path.
@@ -156,6 +179,28 @@ GIT_EXTERN(int) git_attr_get(
156179
const char *path,
157180
const char *name);
158181

182+
/**
183+
* Look up the value of one git attribute for path with extended options.
184+
*
185+
* @param value_out Output of the value of the attribute. Use the GIT_ATTR_...
186+
* macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just
187+
* use the string value for attributes set to a value. You
188+
* should NOT modify or free this value.
189+
* @param repo The repository containing the path.
190+
* @param opts The `git_attr_options` to use when querying these attributes.
191+
* @param path The path to check for attributes. Relative paths are
192+
* interpreted relative to the repo root. The file does
193+
* not have to exist, but if it does not, then it will be
194+
* treated as a plain file (not a directory).
195+
* @param name The name of the attribute to look up.
196+
*/
197+
GIT_EXTERN(int) git_attr_get_ext(
198+
const char **value_out,
199+
git_repository *repo,
200+
git_attr_options *opts,
201+
const char *path,
202+
const char *name);
203+
159204
/**
160205
* Look up a list of git attributes for path.
161206
*
@@ -193,6 +238,30 @@ GIT_EXTERN(int) git_attr_get_many(
193238
size_t num_attr,
194239
const char **names);
195240

241+
/**
242+
* Look up a list of git attributes for path with extended options.
243+
*
244+
* @param values_out An array of num_attr entries that will have string
245+
* pointers written into it for the values of the attributes.
246+
* You should not modify or free the values that are written
247+
* into this array (although of course, you should free the
248+
* array itself if you allocated it).
249+
* @param repo The repository containing the path.
250+
* @param opts The `git_attr_options` to use when querying these attributes.
251+
* @param path The path inside the repo to check attributes. This
252+
* does not have to exist, but if it does not, then
253+
* it will be treated as a plain file (i.e. not a directory).
254+
* @param num_attr The number of attributes being looked up
255+
* @param names An array of num_attr strings containing attribute names.
256+
*/
257+
GIT_EXTERN(int) git_attr_get_many_ext(
258+
const char **values_out,
259+
git_repository *repo,
260+
git_attr_options *opts,
261+
const char *path,
262+
size_t num_attr,
263+
const char **names);
264+
196265
/**
197266
* The callback used with git_attr_foreach.
198267
*
@@ -231,6 +300,26 @@ GIT_EXTERN(int) git_attr_foreach(
231300
git_attr_foreach_cb callback,
232301
void *payload);
233302

303+
/**
304+
* Loop over all the git attributes for a path with extended options.
305+
*
306+
* @param repo The repository containing the path.
307+
* @param opts The `git_attr_options` to use when querying these attributes.
308+
* @param path Path inside the repo to check attributes. This does not have
309+
* to exist, but if it does not, then it will be treated as a
310+
* plain file (i.e. not a directory).
311+
* @param callback Function to invoke on each attribute name and value.
312+
* See git_attr_foreach_cb.
313+
* @param payload Passed on as extra parameter to callback function.
314+
* @return 0 on success, non-zero callback return value, or error code
315+
*/
316+
GIT_EXTERN(int) git_attr_foreach_ext(
317+
git_repository *repo,
318+
git_attr_options *opts,
319+
const char *path,
320+
git_attr_foreach_cb callback,
321+
void *payload);
322+
234323
/**
235324
* Flush the gitattributes cache.
236325
*

include/git2/blame.h

+93-42
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,52 @@ GIT_BEGIN_DECL
2626
typedef enum {
2727
/** Normal blame, the default */
2828
GIT_BLAME_NORMAL = 0,
29-
/** Track lines that have moved within a file (like `git blame -M`).
30-
* NOT IMPLEMENTED. */
29+
30+
/**
31+
* Track lines that have moved within a file (like `git blame -M`).
32+
*
33+
* This is not yet implemented and reserved for future use.
34+
*/
3135
GIT_BLAME_TRACK_COPIES_SAME_FILE = (1<<0),
32-
/** Track lines that have moved across files in the same commit (like `git blame -C`).
33-
* NOT IMPLEMENTED. */
36+
37+
/**
38+
* Track lines that have moved across files in the same commit
39+
* (like `git blame -C`).
40+
*
41+
* This is not yet implemented and reserved for future use.
42+
*/
3443
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES = (1<<1),
35-
/** Track lines that have been copied from another file that exists in the
36-
* same commit (like `git blame -CC`). Implies SAME_FILE.
37-
* NOT IMPLEMENTED. */
44+
45+
/**
46+
* Track lines that have been copied from another file that exists
47+
* in the same commit (like `git blame -CC`). Implies SAME_FILE.
48+
*
49+
* This is not yet implemented and reserved for future use.
50+
*/
3851
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES = (1<<2),
39-
/** Track lines that have been copied from another file that exists in *any*
40-
* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES.
41-
* NOT IMPLEMENTED. */
52+
53+
/**
54+
* Track lines that have been copied from another file that exists in
55+
* *any* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES.
56+
*
57+
* This is not yet implemented and reserved for future use.
58+
*/
4259
GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = (1<<3),
43-
/** Restrict the search of commits to those reachable following only the
44-
* first parents. */
60+
61+
/**
62+
* Restrict the search of commits to those reachable following only
63+
* the first parents.
64+
*/
4565
GIT_BLAME_FIRST_PARENT = (1<<4),
46-
/** Use mailmap file to map author and committer names and email addresses
47-
* to canonical real names and email addresses. The mailmap will be read
48-
* from the working directory, or HEAD in a bare repository. */
66+
67+
/**
68+
* Use mailmap file to map author and committer names and email
69+
* addresses to canonical real names and email addresses. The
70+
* mailmap will be read from the working directory, or HEAD in a
71+
* bare repository.
72+
*/
4973
GIT_BLAME_USE_MAILMAP = (1<<5),
74+
5075
/** Ignore whitespace differences */
5176
GIT_BLAME_IGNORE_WHITESPACE = (1<<6),
5277
} git_blame_flag_t;
@@ -63,25 +88,33 @@ typedef struct git_blame_options {
6388

6489
/** A combination of `git_blame_flag_t` */
6590
uint32_t flags;
66-
/** The lower bound on the number of alphanumeric
67-
* characters that must be detected as moving/copying within a file for it to
68-
* associate those lines with the parent commit. The default value is 20.
69-
* This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*`
70-
* flags are specified.
91+
92+
/**
93+
* The lower bound on the number of alphanumeric characters that
94+
* must be detected as moving/copying within a file for it to
95+
* associate those lines with the parent commit. The default value
96+
* is 20.
97+
*
98+
* This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*`
99+
* flags are specified.
71100
*/
72101
uint16_t min_match_characters;
102+
73103
/** The id of the newest commit to consider. The default is HEAD. */
74104
git_oid newest_commit;
105+
75106
/**
76107
* The id of the oldest commit to consider.
77108
* The default is the first commit encountered with a NULL parent.
78109
*/
79110
git_oid oldest_commit;
111+
80112
/**
81113
* The first line in the file to blame.
82114
* The default is 1 (line numbers start with 1).
83115
*/
84116
size_t min_line;
117+
85118
/**
86119
* The last line in the file to blame.
87120
* The default is the last line of the file.
@@ -108,41 +141,59 @@ GIT_EXTERN(int) git_blame_options_init(
108141

109142
/**
110143
* Structure that represents a blame hunk.
111-
*
112-
* - `lines_in_hunk` is the number of lines in this hunk
113-
* - `final_commit_id` is the OID of the commit where this line was last
114-
* changed.
115-
* - `final_start_line_number` is the 1-based line number where this hunk
116-
* begins, in the final version of the file
117-
* - `final_signature` is the author of `final_commit_id`. If
118-
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
119-
* real name and email address.
120-
* - `orig_commit_id` is the OID of the commit where this hunk was found. This
121-
* will usually be the same as `final_commit_id`, except when
122-
* `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
123-
* - `orig_path` is the path to the file where this hunk originated, as of the
124-
* commit specified by `orig_commit_id`.
125-
* - `orig_start_line_number` is the 1-based line number where this hunk begins
126-
* in the file named by `orig_path` in the commit specified by
127-
* `orig_commit_id`.
128-
* - `orig_signature` is the author of `orig_commit_id`. If
129-
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
130-
* real name and email address.
131-
* - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the
132-
* root, or the commit specified in git_blame_options.oldest_commit)
133144
*/
134145
typedef struct git_blame_hunk {
146+
/**
147+
* The number of lines in this hunk.
148+
*/
135149
size_t lines_in_hunk;
136150

151+
/**
152+
* The OID of the commit where this line was last changed.
153+
*/
137154
git_oid final_commit_id;
155+
156+
/**
157+
* The 1-based line number where this hunk begins, in the final version
158+
* of the file.
159+
*/
138160
size_t final_start_line_number;
161+
162+
/**
163+
* The author of `final_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been
164+
* specified, it will contain the canonical real name and email address.
165+
*/
139166
git_signature *final_signature;
140167

168+
/**
169+
* The OID of the commit where this hunk was found.
170+
* This will usually be the same as `final_commit_id`, except when
171+
* `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
172+
*/
141173
git_oid orig_commit_id;
174+
175+
/**
176+
* The path to the file where this hunk originated, as of the commit
177+
* specified by `orig_commit_id`.
178+
*/
142179
const char *orig_path;
180+
181+
/**
182+
* The 1-based line number where this hunk begins in the file named by
183+
* `orig_path` in the commit specified by `orig_commit_id`.
184+
*/
143185
size_t orig_start_line_number;
186+
187+
/**
188+
* The author of `orig_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been
189+
* specified, it will contain the canonical real name and email address.
190+
*/
144191
git_signature *orig_signature;
145192

193+
/**
194+
* The 1 iff the hunk has been tracked to a boundary commit (the root,
195+
* or the commit specified in git_blame_options.oldest_commit)
196+
*/
146197
char boundary;
147198
} git_blame_hunk;
148199

include/git2/blob.h

+31-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
8484
* time.
8585
*
8686
* @param blob pointer to the blob
87-
* @return the pointer
87+
* @return the pointer, or NULL on error
8888
*/
8989
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
9090

@@ -113,22 +113,50 @@ typedef enum {
113113
* When set, filters will be loaded from a `.gitattributes` file
114114
* in the HEAD commit.
115115
*/
116-
GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD = (1 << 2),
116+
GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD = (1 << 2),
117+
118+
/**
119+
* When set, filters will be loaded from a `.gitattributes` file
120+
* in the specified commit.
121+
*/
122+
GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3),
117123
} git_blob_filter_flag_t;
118124

119125
/**
120126
* The options used when applying filter options to a file.
127+
*
128+
* Initialize with `GIT_BLOB_FILTER_OPTIONS_INIT`. Alternatively, you can
129+
* use `git_blob_filter_options_init`.
130+
*
121131
*/
122132
typedef struct {
123133
int version;
124134

125135
/** Flags to control the filtering process, see `git_blob_filter_flag_t` above */
126136
uint32_t flags;
137+
138+
/**
139+
* The commit to load attributes from, when
140+
* `GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT` is specified.
141+
*/
142+
git_oid *commit_id;
127143
} git_blob_filter_options;
128144

129145
#define GIT_BLOB_FILTER_OPTIONS_VERSION 1
130146
#define GIT_BLOB_FILTER_OPTIONS_INIT {GIT_BLOB_FILTER_OPTIONS_VERSION, GIT_BLOB_FILTER_CHECK_FOR_BINARY}
131147

148+
/**
149+
* Initialize git_blob_filter_options structure
150+
*
151+
* Initializes a `git_blob_filter_options` with default values. Equivalent
152+
* to creating an instance with `GIT_BLOB_FILTER_OPTIONS_INIT`.
153+
*
154+
* @param opts The `git_blob_filter_options` struct to initialize.
155+
* @param version The struct version; pass `GIT_BLOB_FILTER_OPTIONS_VERSION`.
156+
* @return Zero on success; -1 on failure.
157+
*/
158+
GIT_EXTERN(int) git_blob_filter_options_init(git_blob_filter_options *opts, unsigned int version);
159+
132160
/**
133161
* Get a buffer with the filtered content of a blob.
134162
*
@@ -229,7 +257,7 @@ GIT_EXTERN(int) git_blob_create_from_stream_commit(
229257
* Write an in-memory buffer to the ODB as a blob
230258
*
231259
* @param id return the id of the written blob
232-
* @param repo repository where to blob will be written
260+
* @param repo repository where the blob will be written
233261
* @param buffer data to be written into the blob
234262
* @param len length of the data
235263
* @return 0 or an error code

0 commit comments

Comments
 (0)