Skip to content

Commit 4e892ae

Browse files
committed
index: update enum and structure names
We have various macro, enumeration and structure names that were introduced (very) early in the project and do not match our current naming conventions. For instance: `GIT_IDXENTRY...` flags that correspond to a structure named `git_index_entry`. Update these to match the current guidance. The old macros and enumeration names are reflected as new macros in order to support backward compatibility (and do so without warnings for consumers).
1 parent 0ddc609 commit 4e892ae

File tree

1 file changed

+74
-42
lines changed

1 file changed

+74
-42
lines changed

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

0 commit comments

Comments
 (0)