Skip to content

Commit 788fccc

Browse files
authored
Merge pull request libgit2#4807 from libgit2/ethomson/index_fixes
Index API updates for consistency
2 parents 0ddc609 + 168fe39 commit 788fccc

File tree

145 files changed

+1032
-974
lines changed

Some content is hidden

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

145 files changed

+1032
-974
lines changed

include/git2/common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ typedef enum {
243243
* > `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
244244
* > `GIT_CONFIG_LEVEL_PROGRAMDATA`.
245245
*
246-
* * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_otype type, size_t size)
246+
* * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_object_t type, size_t size)
247247
*
248248
* > Set the maximum data size for the given type of object to be
249249
* > considered eligible for caching in memory. Setting to value to
250250
* > zero means that that type of object will not be cached.
251-
* > Defaults to 0 for GIT_OBJ_BLOB (i.e. won't cache blobs) and 4k
252-
* > for GIT_OBJ_COMMIT, GIT_OBJ_TREE, and GIT_OBJ_TAG.
251+
* > Defaults to 0 for GIT_OBJECT_BLOB (i.e. won't cache blobs) and 4k
252+
* > for GIT_OBJECT_COMMIT, GIT_OBJECT_TREE, and GIT_OBJECT_TAG.
253253
*
254254
* * opts(GIT_OPT_SET_CACHE_MAX_SIZE, ssize_t max_storage_bytes)
255255
*

include/git2/index.h

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ typedef struct {
3737
* "Documentation/technical/index-format.txt").
3838
*
3939
* The `flags` field consists of a number of bit fields which can be
40-
* accessed via the first set of `GIT_IDXENTRY_...` bitmasks below. These
41-
* flags are all read from and persisted to disk.
40+
* accessed via the first set of `GIT_INDEX_ENTRY_...` bitmasks below.
41+
* These flags are all read from and persisted to disk.
4242
*
4343
* The `flags_extended` field also has a number of bit fields which can be
44-
* accessed via the later `GIT_IDXENTRY_...` bitmasks below. Some of
44+
* accessed via the later `GIT_INDEX_ENTRY_...` bitmasks below. Some of
4545
* these flags are read from and written to disk, but some are set aside
4646
* for in-memory only reference.
4747
*
@@ -76,32 +76,33 @@ typedef struct git_index_entry {
7676
* value both in memory and on disk. You can use them to interpret the
7777
* data in the `flags`.
7878
*/
79-
#define GIT_IDXENTRY_NAMEMASK (0x0fff)
80-
#define GIT_IDXENTRY_STAGEMASK (0x3000)
81-
#define GIT_IDXENTRY_STAGESHIFT 12
79+
80+
#define GIT_INDEX_ENTRY_NAMEMASK (0x0fff)
81+
#define GIT_INDEX_ENTRY_STAGEMASK (0x3000)
82+
#define GIT_INDEX_ENTRY_STAGESHIFT 12
8283

8384
/**
8485
* Flags for index entries
8586
*/
8687
typedef enum {
87-
GIT_IDXENTRY_EXTENDED = (0x4000),
88-
GIT_IDXENTRY_VALID = (0x8000),
89-
} git_indxentry_flag_t;
88+
GIT_INDEX_ENTRY_EXTENDED = (0x4000),
89+
GIT_INDEX_ENTRY_VALID = (0x8000),
90+
} git_index_entry_flag_t;
9091

91-
#define GIT_IDXENTRY_STAGE(E) \
92-
(((E)->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT)
92+
#define GIT_INDEX_ENTRY_STAGE(E) \
93+
(((E)->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT)
9394

94-
#define GIT_IDXENTRY_STAGE_SET(E,S) do { \
95-
(E)->flags = ((E)->flags & ~GIT_IDXENTRY_STAGEMASK) | \
96-
(((S) & 0x03) << GIT_IDXENTRY_STAGESHIFT); } while (0)
95+
#define GIT_INDEX_ENTRY_STAGE_SET(E,S) do { \
96+
(E)->flags = ((E)->flags & ~GIT_INDEX_ENTRY_STAGEMASK) | \
97+
(((S) & 0x03) << GIT_INDEX_ENTRY_STAGESHIFT); } while (0)
9798

9899
/**
99100
* Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended`
100101
*
101102
* In memory, the `flags_extended` fields are divided into two parts: the
102103
* fields that are read from and written to disk, and other fields that
103104
* in-memory only and used by libgit2. Only the flags in
104-
* `GIT_IDXENTRY_EXTENDED_FLAGS` will get saved on-disk.
105+
* `GIT_INDEX_ENTRY_EXTENDED_FLAGS` will get saved on-disk.
105106
*
106107
* Thee first three bitmasks match the three fields in the
107108
* `git_index_entry` `flags_extended` value that belong on disk. You
@@ -113,34 +114,22 @@ typedef enum {
113114
*
114115
*/
115116
typedef enum {
117+
GIT_INDEX_ENTRY_INTENT_TO_ADD = (1 << 13),
118+
GIT_INDEX_ENTRY_SKIP_WORKTREE = (1 << 14),
116119

117-
GIT_IDXENTRY_INTENT_TO_ADD = (1 << 13),
118-
GIT_IDXENTRY_SKIP_WORKTREE = (1 << 14),
119-
/** Reserved for future extension */
120-
GIT_IDXENTRY_EXTENDED2 = (1 << 15),
121-
122-
GIT_IDXENTRY_EXTENDED_FLAGS = (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE),
123-
GIT_IDXENTRY_UPDATE = (1 << 0),
124-
GIT_IDXENTRY_REMOVE = (1 << 1),
125-
GIT_IDXENTRY_UPTODATE = (1 << 2),
126-
GIT_IDXENTRY_ADDED = (1 << 3),
127-
128-
GIT_IDXENTRY_HASHED = (1 << 4),
129-
GIT_IDXENTRY_UNHASHED = (1 << 5),
130-
GIT_IDXENTRY_WT_REMOVE = (1 << 6), /**< remove in work directory */
131-
GIT_IDXENTRY_CONFLICTED = (1 << 7),
120+
GIT_INDEX_ENTRY_EXTENDED_FLAGS = (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE),
132121

133-
GIT_IDXENTRY_UNPACKED = (1 << 8),
134-
GIT_IDXENTRY_NEW_SKIP_WORKTREE = (1 << 9),
135-
} git_idxentry_extended_flag_t;
122+
GIT_INDEX_ENTRY_UPTODATE = (1 << 2),
123+
} git_index_entry_extended_flag_t;
136124

137125
/** Capabilities of system that affect index actions. */
138126
typedef enum {
139-
GIT_INDEXCAP_IGNORE_CASE = 1,
140-
GIT_INDEXCAP_NO_FILEMODE = 2,
141-
GIT_INDEXCAP_NO_SYMLINKS = 4,
142-
GIT_INDEXCAP_FROM_OWNER = -1,
143-
} git_indexcap_t;
127+
GIT_INDEX_CAPABILITY_IGNORE_CASE = 1,
128+
GIT_INDEX_CAPABILITY_NO_FILEMODE = 2,
129+
GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4,
130+
GIT_INDEX_CAPABILITY_FROM_OWNER = -1,
131+
} git_index_capability_t;
132+
144133

145134
/** Callback for APIs that add/remove/update files matching pathspec */
146135
typedef int (*git_index_matched_path_cb)(
@@ -234,19 +223,19 @@ GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
234223
* Read index capabilities flags.
235224
*
236225
* @param index An existing index object
237-
* @return A combination of GIT_INDEXCAP values
226+
* @return A combination of GIT_INDEX_CAPABILITY values
238227
*/
239228
GIT_EXTERN(int) git_index_caps(const git_index *index);
240229

241230
/**
242231
* Set index capabilities flags.
243232
*
244-
* If you pass `GIT_INDEXCAP_FROM_OWNER` for the caps, then the
233+
* If you pass `GIT_INDEX_CAPABILITY_FROM_OWNER` for the caps, then
245234
* capabilities will be read from the config of the owner object,
246235
* looking at `core.ignorecase`, `core.filemode`, `core.symlinks`.
247236
*
248237
* @param index An existing index object
249-
* @param caps A combination of GIT_INDEXCAP values
238+
* @param caps A combination of GIT_INDEX_CAPABILITY values
250239
* @return 0 on success, -1 on failure
251240
*/
252241
GIT_EXTERN(int) git_index_set_caps(git_index *index, int caps);
@@ -474,7 +463,7 @@ GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_en
474463
*
475464
* This entry is calculated from the entry's flag attribute like this:
476465
*
477-
* (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
466+
* (entry->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT
478467
*
479468
* @param entry The entry
480469
* @return the stage number
@@ -847,6 +836,49 @@ GIT_EXTERN(void) git_index_conflict_iterator_free(
847836

848837
/**@}*/
849838

839+
/** @name Deprecated Index Structures
840+
*
841+
* These macros, structures and enumerations are retained for backward
842+
* compatibility. The newer versions of these functions and structures
843+
* should be preferred in all new code.
844+
*/
845+
/**@{*/
846+
847+
#define GIT_IDXENTRY_NAMEMASK GIT_INDEX_ENTRY_NAMEMASK
848+
#define GIT_IDXENTRY_STAGEMASK GIT_INDEX_ENTRY_STAGEMASK
849+
#define GIT_IDXENTRY_STAGESHIFT GIT_INDEX_ENTRY_STAGESHIFT
850+
851+
/* The git_indxentry_flag_t enum */
852+
#define GIT_IDXENTRY_EXTENDED GIT_INDEX_ENTRY_EXTENDED
853+
#define GIT_IDXENTRY_VALID GIT_INDEX_ENTRY_VALID
854+
855+
#define GIT_IDXENTRY_STAGE(E) GIT_INDEX_ENTRY_STAGE(E)
856+
#define GIT_IDXENTRY_STAGE_SET(E,S) GIT_INDEX_ENTRY_STAGE_SET(E,S)
857+
858+
/* The git_idxentry_extended_flag_t enum */
859+
#define GIT_IDXENTRY_INTENT_TO_ADD GIT_INDEX_ENTRY_INTENT_TO_ADD
860+
#define GIT_IDXENTRY_SKIP_WORKTREE GIT_INDEX_ENTRY_SKIP_WORKTREE
861+
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE)
862+
#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
863+
#define GIT_IDXENTRY_UPDATE (1 << 0)
864+
#define GIT_IDXENTRY_REMOVE (1 << 1)
865+
#define GIT_IDXENTRY_UPTODATE (1 << 2)
866+
#define GIT_IDXENTRY_ADDED (1 << 3)
867+
#define GIT_IDXENTRY_HASHED (1 << 4)
868+
#define GIT_IDXENTRY_UNHASHED (1 << 5)
869+
#define GIT_IDXENTRY_WT_REMOVE (1 << 6)
870+
#define GIT_IDXENTRY_CONFLICTED (1 << 7)
871+
#define GIT_IDXENTRY_UNPACKED (1 << 8)
872+
#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
873+
874+
/* The git_index_capability_t enum */
875+
#define GIT_INDEXCAP_IGNORE_CASE GIT_INDEX_CAPABILITY_IGNORE_CASE
876+
#define GIT_INDEXCAP_NO_FILEMODE GIT_INDEX_CAPABILITY_NO_FILEMODE
877+
#define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS
878+
#define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER
879+
880+
/**@}*/
881+
850882
/** @} */
851883
GIT_END_DECL
852884
#endif

include/git2/object.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
3030
*
3131
* The 'type' parameter must match the type of the object
3232
* in the odb; the method will fail otherwise.
33-
* The special value 'GIT_OBJ_ANY' may be passed to let
33+
* The special value 'GIT_OBJECT_ANY' may be passed to let
3434
* the method guess the object's type.
3535
*
3636
* @param object pointer to the looked-up object
@@ -43,7 +43,7 @@ GIT_EXTERN(int) git_object_lookup(
4343
git_object **object,
4444
git_repository *repo,
4545
const git_oid *id,
46-
git_otype type);
46+
git_object_t type);
4747

4848
/**
4949
* Lookup a reference to one of the objects in a repository,
@@ -62,7 +62,7 @@ GIT_EXTERN(int) git_object_lookup(
6262
*
6363
* The 'type' parameter must match the type of the object
6464
* in the odb; the method will fail otherwise.
65-
* The special value 'GIT_OBJ_ANY' may be passed to let
65+
* The special value 'GIT_OBJECT_ANY' may be passed to let
6666
* the method guess the object's type.
6767
*
6868
* @param object_out pointer where to store the looked-up object
@@ -77,7 +77,7 @@ GIT_EXTERN(int) git_object_lookup_prefix(
7777
git_repository *repo,
7878
const git_oid *id,
7979
size_t len,
80-
git_otype type);
80+
git_object_t type);
8181

8282

8383
/**
@@ -94,7 +94,7 @@ GIT_EXTERN(int) git_object_lookup_bypath(
9494
git_object **out,
9595
const git_object *treeish,
9696
const char *path,
97-
git_otype type);
97+
git_object_t type);
9898

9999
/**
100100
* Get the id (SHA1) of a repository object
@@ -124,7 +124,7 @@ GIT_EXTERN(int) git_object_short_id(git_buf *out, const git_object *obj);
124124
* @param obj the repository object
125125
* @return the object's type
126126
*/
127-
GIT_EXTERN(git_otype) git_object_type(const git_object *obj);
127+
GIT_EXTERN(git_object_t) git_object_type(const git_object *obj);
128128

129129
/**
130130
* Get the repository that owns this object
@@ -166,24 +166,24 @@ GIT_EXTERN(void) git_object_free(git_object *object);
166166
* @param type object type to convert.
167167
* @return the corresponding string representation.
168168
*/
169-
GIT_EXTERN(const char *) git_object_type2string(git_otype type);
169+
GIT_EXTERN(const char *) git_object_type2string(git_object_t type);
170170

171171
/**
172-
* Convert a string object type representation to it's git_otype.
172+
* Convert a string object type representation to it's git_object_t.
173173
*
174174
* @param str the string to convert.
175-
* @return the corresponding git_otype.
175+
* @return the corresponding git_object_t.
176176
*/
177-
GIT_EXTERN(git_otype) git_object_string2type(const char *str);
177+
GIT_EXTERN(git_object_t) git_object_string2type(const char *str);
178178

179179
/**
180-
* Determine if the given git_otype is a valid loose object type.
180+
* Determine if the given git_object_t is a valid loose object type.
181181
*
182182
* @param type object type to test.
183183
* @return true if the type represents a valid loose object type,
184184
* false otherwise.
185185
*/
186-
GIT_EXTERN(int) git_object_typeisloose(git_otype type);
186+
GIT_EXTERN(int) git_object_typeisloose(git_object_t type);
187187

188188
/**
189189
* Get the size in bytes for the structure which
@@ -197,7 +197,7 @@ GIT_EXTERN(int) git_object_typeisloose(git_otype type);
197197
* @param type object type to get its size
198198
* @return size in bytes of the object
199199
*/
200-
GIT_EXTERN(size_t) git_object__size(git_otype type);
200+
GIT_EXTERN(size_t) git_object__size(git_object_t type);
201201

202202
/**
203203
* Recursively peel an object until an object of the specified type is met.
@@ -206,7 +206,7 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
206206
* GIT_EINVALIDSPEC will be returned (e.g. trying to peel a blob to a
207207
* tree).
208208
*
209-
* If you pass `GIT_OBJ_ANY` as the target type, then the object will
209+
* If you pass `GIT_OBJECT_ANY` as the target type, then the object will
210210
* be peeled until the type changes. A tag will be peeled until the
211211
* referenced object is no longer a tag, and a commit will be peeled
212212
* to a tree. Any other object type will return GIT_EINVALIDSPEC.
@@ -219,13 +219,13 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
219219
*
220220
* @param peeled Pointer to the peeled git_object
221221
* @param object The object to be processed
222-
* @param target_type The type of the requested object (a GIT_OBJ_ value)
222+
* @param target_type The type of the requested object (a GIT_OBJECT_ value)
223223
* @return 0 on success, GIT_EINVALIDSPEC, GIT_EPEEL, or an error code
224224
*/
225225
GIT_EXTERN(int) git_object_peel(
226226
git_object **peeled,
227227
const git_object *object,
228-
git_otype target_type);
228+
git_object_t target_type);
229229

230230
/**
231231
* Create an in-memory copy of a Git object. The copy must be

include/git2/odb.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
146146
* - 0 if the object was read;
147147
* - GIT_ENOTFOUND if the object is not in the database.
148148
*/
149-
GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
149+
GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git_odb *db, const git_oid *id);
150150

151151
/**
152152
* Determine if the given object can be found in the object database.
@@ -189,9 +189,9 @@ typedef struct git_odb_expand_id {
189189

190190
/**
191191
* The (optional) type of the object to search for; leave as `0` or set
192-
* to `GIT_OBJ_ANY` to query for any object matching the ID.
192+
* to `GIT_OBJECT_ANY` to query for any object matching the ID.
193193
*/
194-
git_otype type;
194+
git_object_t type;
195195
} git_odb_expand_id;
196196

197197
/**
@@ -270,7 +270,7 @@ GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payloa
270270
* @param type type of the data to store
271271
* @return 0 or an error code
272272
*/
273-
GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
273+
GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_object_t type);
274274

275275
/**
276276
* Open a stream to write an object into the ODB
@@ -293,7 +293,7 @@ GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size
293293
* @param type type of the object that will be written
294294
* @return 0 if the stream was created; error code otherwise
295295
*/
296-
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_otype type);
296+
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_object_t type);
297297

298298
/**
299299
* Write to an odb stream
@@ -366,7 +366,7 @@ GIT_EXTERN(void) git_odb_stream_free(git_odb_stream *stream);
366366
GIT_EXTERN(int) git_odb_open_rstream(
367367
git_odb_stream **out,
368368
size_t *len,
369-
git_otype *type,
369+
git_object_t *type,
370370
git_odb *db,
371371
const git_oid *oid);
372372

@@ -406,7 +406,7 @@ GIT_EXTERN(int) git_odb_write_pack(
406406
* @param type of the data to hash
407407
* @return 0 or an error code
408408
*/
409-
GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
409+
GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
410410

411411
/**
412412
* Read a file from disk and fill a git_oid with the object id
@@ -421,7 +421,7 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_oty
421421
* @param type the type of the object that will be hashed
422422
* @return 0 or an error code
423423
*/
424-
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
424+
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type);
425425

426426
/**
427427
* Create a copy of an odb_object
@@ -487,7 +487,7 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
487487
* @param object the object
488488
* @return the type
489489
*/
490-
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
490+
GIT_EXTERN(git_object_t) git_odb_object_type(git_odb_object *object);
491491

492492
/**
493493
* Add a custom backend to an existing Object DB

0 commit comments

Comments
 (0)