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

Commit ef2695e

Browse files
committed
libgit2 1.0.0
1 parent bca9d5c commit ef2695e

Some content is hidden

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

84 files changed

+3749
-1783
lines changed

include/git2.h

+5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
#define INCLUDE_git_git_h__
1010

1111
#include "git2/annotated_commit.h"
12+
#include "git2/apply.h"
1213
#include "git2/attr.h"
1314
#include "git2/blob.h"
1415
#include "git2/blame.h"
1516
#include "git2/branch.h"
1617
#include "git2/buffer.h"
18+
#include "git2/cert.h"
1719
#include "git2/checkout.h"
1820
#include "git2/cherrypick.h"
1921
#include "git2/clone.h"
2022
#include "git2/commit.h"
2123
#include "git2/common.h"
2224
#include "git2/config.h"
25+
#include "git2/credential.h"
26+
#include "git2/deprecated.h"
2327
#include "git2/describe.h"
2428
#include "git2/diff.h"
2529
#include "git2/errors.h"
@@ -29,6 +33,7 @@
2933
#include "git2/ignore.h"
3034
#include "git2/index.h"
3135
#include "git2/indexer.h"
36+
#include "git2/mailmap.h"
3237
#include "git2/merge.h"
3338
#include "git2/message.h"
3439
#include "git2/net.h"

include/git2/annotated_commit.h

+9
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ GIT_EXTERN(int) git_annotated_commit_from_revspec(
103103
GIT_EXTERN(const git_oid *) git_annotated_commit_id(
104104
const git_annotated_commit *commit);
105105

106+
/**
107+
* Get the refname that the given `git_annotated_commit` refers to.
108+
*
109+
* @param commit the given annotated commit
110+
* @return ref name.
111+
*/
112+
GIT_EXTERN(const char *) git_annotated_commit_ref(
113+
const git_annotated_commit *commit);
114+
106115
/**
107116
* Frees a `git_annotated_commit`.
108117
*

include/git2/apply.h

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
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+
*/
7+
#ifndef INCLUDE_git_apply_h__
8+
#define INCLUDE_git_apply_h__
9+
10+
#include "common.h"
11+
#include "types.h"
12+
#include "oid.h"
13+
#include "diff.h"
14+
15+
/**
16+
* @file git2/apply.h
17+
* @brief Git patch application routines
18+
* @defgroup git_apply Git patch application routines
19+
* @ingroup Git
20+
* @{
21+
*/
22+
GIT_BEGIN_DECL
23+
24+
/**
25+
* When applying a patch, callback that will be made per delta (file).
26+
*
27+
* When the callback:
28+
* - returns < 0, the apply process will be aborted.
29+
* - returns > 0, the delta will not be applied, but the apply process
30+
* continues
31+
* - returns 0, the delta is applied, and the apply process continues.
32+
*
33+
* @param delta The delta to be applied
34+
* @param payload User-specified payload
35+
*/
36+
typedef int GIT_CALLBACK(git_apply_delta_cb)(
37+
const git_diff_delta *delta,
38+
void *payload);
39+
40+
/**
41+
* When applying a patch, callback that will be made per hunk.
42+
*
43+
* When the callback:
44+
* - returns < 0, the apply process will be aborted.
45+
* - returns > 0, the hunk will not be applied, but the apply process
46+
* continues
47+
* - returns 0, the hunk is applied, and the apply process continues.
48+
*
49+
* @param hunk The hunk to be applied
50+
* @param payload User-specified payload
51+
*/
52+
typedef int GIT_CALLBACK(git_apply_hunk_cb)(
53+
const git_diff_hunk *hunk,
54+
void *payload);
55+
56+
/** Flags controlling the behavior of git_apply */
57+
typedef enum {
58+
/**
59+
* Don't actually make changes, just test that the patch applies.
60+
* This is the equivalent of `git apply --check`.
61+
*/
62+
GIT_APPLY_CHECK = (1 << 0),
63+
} git_apply_flags_t;
64+
65+
/**
66+
* Apply options structure
67+
*
68+
* Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
69+
* use `git_apply_options_init`.
70+
*
71+
* @see git_apply_to_tree, git_apply
72+
*/
73+
typedef struct {
74+
unsigned int version; /**< The version */
75+
76+
/** When applying a patch, callback that will be made per delta (file). */
77+
git_apply_delta_cb delta_cb;
78+
79+
/** When applying a patch, callback that will be made per hunk. */
80+
git_apply_hunk_cb hunk_cb;
81+
82+
/** Payload passed to both delta_cb & hunk_cb. */
83+
void *payload;
84+
85+
/** Bitmask of git_apply_flags_t */
86+
unsigned int flags;
87+
} git_apply_options;
88+
89+
#define GIT_APPLY_OPTIONS_VERSION 1
90+
#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
91+
92+
GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int version);
93+
94+
/**
95+
* Apply a `git_diff` to a `git_tree`, and return the resulting image
96+
* as an index.
97+
*
98+
* @param out the postimage of the application
99+
* @param repo the repository to apply
100+
* @param preimage the tree to apply the diff to
101+
* @param diff the diff to apply
102+
* @param options the options for the apply (or null for defaults)
103+
*/
104+
GIT_EXTERN(int) git_apply_to_tree(
105+
git_index **out,
106+
git_repository *repo,
107+
git_tree *preimage,
108+
git_diff *diff,
109+
const git_apply_options *options);
110+
111+
/** Possible application locations for git_apply */
112+
typedef enum {
113+
/**
114+
* Apply the patch to the workdir, leaving the index untouched.
115+
* This is the equivalent of `git apply` with no location argument.
116+
*/
117+
GIT_APPLY_LOCATION_WORKDIR = 0,
118+
119+
/**
120+
* Apply the patch to the index, leaving the working directory
121+
* untouched. This is the equivalent of `git apply --cached`.
122+
*/
123+
GIT_APPLY_LOCATION_INDEX = 1,
124+
125+
/**
126+
* Apply the patch to both the working directory and the index.
127+
* This is the equivalent of `git apply --index`.
128+
*/
129+
GIT_APPLY_LOCATION_BOTH = 2,
130+
} git_apply_location_t;
131+
132+
/**
133+
* Apply a `git_diff` to the given repository, making changes directly
134+
* in the working directory, the index, or both.
135+
*
136+
* @param repo the repository to apply to
137+
* @param diff the diff to apply
138+
* @param location the location to apply (workdir, index or both)
139+
* @param options the options for the apply (or null for defaults)
140+
*/
141+
GIT_EXTERN(int) git_apply(
142+
git_repository *repo,
143+
git_diff *diff,
144+
git_apply_location_t location,
145+
const git_apply_options *options);
146+
147+
/** @} */
148+
GIT_END_DECL
149+
#endif

include/git2/attr.h

+42-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
3030
* Then for file `xyz.c` looking up attribute "foo" gives a value for
3131
* which `GIT_ATTR_TRUE(value)` is true.
3232
*/
33-
#define GIT_ATTR_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_TRUE_T)
33+
#define GIT_ATTR_IS_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_TRUE)
3434

3535
/**
3636
* GIT_ATTR_FALSE checks if an attribute is set off. In core git
@@ -44,7 +44,7 @@ GIT_BEGIN_DECL
4444
* Then for file `zyx.h` looking up attribute "foo" gives a value for
4545
* which `GIT_ATTR_FALSE(value)` is true.
4646
*/
47-
#define GIT_ATTR_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_FALSE_T)
47+
#define GIT_ATTR_IS_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_FALSE)
4848

4949
/**
5050
* GIT_ATTR_UNSPECIFIED checks if an attribute is unspecified. This
@@ -62,7 +62,7 @@ GIT_BEGIN_DECL
6262
* file `onefile.rb` or looking up "bar" on any file will all give
6363
* `GIT_ATTR_UNSPECIFIED(value)` of true.
6464
*/
65-
#define GIT_ATTR_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_UNSPECIFIED_T)
65+
#define GIT_ATTR_IS_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_UNSPECIFIED)
6666

6767
/**
6868
* GIT_ATTR_HAS_VALUE checks if an attribute is set to a value (as
@@ -74,17 +74,17 @@ GIT_BEGIN_DECL
7474
* Given this, looking up "eol" for `onefile.txt` will give back the
7575
* string "lf" and `GIT_ATTR_SET_TO_VALUE(attr)` will return true.
7676
*/
77-
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_T)
77+
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_STRING)
7878

7979
/**
8080
* Possible states for an attribute
8181
*/
8282
typedef enum {
83-
GIT_ATTR_UNSPECIFIED_T = 0, /**< The attribute has been left unspecified */
84-
GIT_ATTR_TRUE_T, /**< The attribute has been set */
85-
GIT_ATTR_FALSE_T, /**< The attribute has been unset */
86-
GIT_ATTR_VALUE_T, /**< This attribute has a value */
87-
} git_attr_t;
83+
GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */
84+
GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */
85+
GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */
86+
GIT_ATTR_VALUE_STRING, /**< This attribute has a value */
87+
} git_attr_value_t;
8888

8989
/**
9090
* Return the value type for a given attribute.
@@ -99,7 +99,7 @@ typedef enum {
9999
* @param attr The attribute
100100
* @return the value type for the attribute
101101
*/
102-
GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);
102+
GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr);
103103

104104
/**
105105
* Check attribute flags: Reading values from index and working directory.
@@ -119,13 +119,20 @@ GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);
119119
#define GIT_ATTR_CHECK_INDEX_ONLY 2
120120

121121
/**
122-
* Check attribute flags: Using the system attributes file.
122+
* Check attribute flags: controlling extended attribute behavior.
123123
*
124124
* Normally, attribute checks include looking in the /etc (or system
125125
* equivalent) directory for a `gitattributes` file. Passing this
126126
* flag will cause attribute checks to ignore that file.
127+
* equivalent) directory for a `gitattributes` file. Passing the
128+
* `GIT_ATTR_CHECK_NO_SYSTEM` flag will cause attribute checks to
129+
* ignore that file.
130+
*
131+
* Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes
132+
* from a `.gitattributes` file in the repository at the HEAD revision.
127133
*/
128-
#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
134+
#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
135+
#define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3)
129136

130137
/**
131138
* Look up the value of one git attribute for path.
@@ -186,7 +193,23 @@ GIT_EXTERN(int) git_attr_get_many(
186193
size_t num_attr,
187194
const char **names);
188195

189-
typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload);
196+
/**
197+
* The callback used with git_attr_foreach.
198+
*
199+
* This callback will be invoked only once per attribute name, even if there
200+
* are multiple rules for a given file. The highest priority rule will be
201+
* used.
202+
*
203+
* @see git_attr_foreach.
204+
*
205+
* @param name The attribute name.
206+
* @param value The attribute value. May be NULL if the attribute is explicitly
207+
* set to UNSPECIFIED using the '!' sign.
208+
* @param payload A user-specified pointer.
209+
* @return 0 to continue looping, non-zero to stop. This value will be returned
210+
* from git_attr_foreach.
211+
*/
212+
typedef int GIT_CALLBACK(git_attr_foreach_cb)(const char *name, const char *value, void *payload);
190213

191214
/**
192215
* Loop over all the git attributes for a path.
@@ -196,13 +219,8 @@ typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *pa
196219
* @param path Path inside the repo to check attributes. This does not have
197220
* to exist, but if it does not, then it will be treated as a
198221
* plain file (i.e. not a directory).
199-
* @param callback Function to invoke on each attribute name and value. The
200-
* value may be NULL is the attribute is explicitly set to
201-
* UNSPECIFIED using the '!' sign. Callback will be invoked
202-
* only once per attribute name, even if there are multiple
203-
* rules for a given file. The highest priority rule will be
204-
* used. Return a non-zero value from this to stop looping.
205-
* The value will be returned from `git_attr_foreach`.
222+
* @param callback Function to invoke on each attribute name and value.
223+
* See git_attr_foreach_cb.
206224
* @param payload Passed on as extra parameter to callback function.
207225
* @return 0 on success, non-zero callback return value, or error code
208226
*/
@@ -220,8 +238,11 @@ GIT_EXTERN(int) git_attr_foreach(
220238
* disk no longer match the cached contents of memory. This will cause
221239
* the attributes files to be reloaded the next time that an attribute
222240
* access function is called.
241+
*
242+
* @param repo The repository containing the gitattributes cache
243+
* @return 0 on success, or an error code
223244
*/
224-
GIT_EXTERN(void) git_attr_cache_flush(
245+
GIT_EXTERN(int) git_attr_cache_flush(
225246
git_repository *repo);
226247

227248
/**

0 commit comments

Comments
 (0)