Skip to content

Commit 1758636

Browse files
authored
Merge pull request libgit2#4939 from libgit2/ethomson/git_ref
Move `git_ref_t` to `git_reference_t`
2 parents b2c2dc6 + ed8cfbf commit 1758636

File tree

28 files changed

+291
-256
lines changed

28 files changed

+291
-256
lines changed

examples/for-each-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static int show_ref(git_reference *ref, void *data)
1010
const git_oid *oid;
1111
git_object *obj;
1212

13-
if (git_reference_type(ref) == GIT_REF_SYMBOLIC)
13+
if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC)
1414
check_lg2(git_reference_resolve(&resolved, ref),
1515
"Unable to resolve symbolic reference",
1616
git_reference_name(ref));

examples/general.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ static void reference_listing(git_repository *repo)
692692
git_reference_lookup(&ref, repo, refname);
693693

694694
switch (git_reference_type(ref)) {
695-
case GIT_REF_OID:
695+
case GIT_REFERENCE_DIRECT:
696696
git_oid_fmt(oid_hex, git_reference_target(ref));
697697
printf("%s [%s]\n", refname, oid_hex);
698698
break;
699699

700-
case GIT_REF_SYMBOLIC:
700+
case GIT_REFERENCE_SYMBOLIC:
701701
printf("%s => %s\n", refname, git_reference_symbolic_target(ref));
702702
break;
703703
default:

include/git2/refs.h

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
*/
2222
GIT_BEGIN_DECL
2323

24+
/** @name Reference Functions
25+
*
26+
* These functions read, write and analyze references.
27+
*/
28+
/**@{*/
29+
2430
/**
2531
* Lookup a reference by name in a repository.
2632
*
@@ -263,12 +269,12 @@ GIT_EXTERN(const char *) git_reference_symbolic_target(const git_reference *ref)
263269
/**
264270
* Get the type of a reference.
265271
*
266-
* Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC)
272+
* Either direct (GIT_REFERENCE_DIRECT) or symbolic (GIT_REFERENCE_SYMBOLIC)
267273
*
268274
* @param ref The reference
269275
* @return the type
270276
*/
271-
GIT_EXTERN(git_ref_t) git_reference_type(const git_reference *ref);
277+
GIT_EXTERN(git_reference_t) git_reference_type(const git_reference *ref);
272278

273279
/**
274280
* Get the full name of a reference.
@@ -640,15 +646,15 @@ typedef enum {
640646
/**
641647
* No particular normalization.
642648
*/
643-
GIT_REF_FORMAT_NORMAL = 0u,
649+
GIT_REFERENCE_FORMAT_NORMAL = 0u,
644650

645651
/**
646652
* Control whether one-level refnames are accepted
647653
* (i.e., refnames that do not contain multiple /-separated
648654
* components). Those are expected to be written only using
649655
* uppercase letters and underscore (FETCH_HEAD, ...)
650656
*/
651-
GIT_REF_FORMAT_ALLOW_ONELEVEL = (1u << 0),
657+
GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = (1u << 0),
652658

653659
/**
654660
* Interpret the provided name as a reference pattern for a
@@ -657,15 +663,15 @@ typedef enum {
657663
* in place of a one full pathname component
658664
* (e.g., foo/<star>/bar but not foo/bar<star>).
659665
*/
660-
GIT_REF_FORMAT_REFSPEC_PATTERN = (1u << 1),
666+
GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = (1u << 1),
661667

662668
/**
663669
* Interpret the name as part of a refspec in shorthand form
664670
* so the `ONELEVEL` naming rules aren't enforced and 'master'
665671
* becomes a valid name.
666672
*/
667-
GIT_REF_FORMAT_REFSPEC_SHORTHAND = (1u << 2),
668-
} git_reference_normalize_t;
673+
GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2),
674+
} git_reference_format_t;
669675

670676
/**
671677
* Normalize reference name and check validity.
@@ -683,7 +689,7 @@ typedef enum {
683689
* @param buffer_size Size of buffer_out
684690
* @param name Reference name to be checked.
685691
* @param flags Flags to constrain name validation rules - see the
686-
* GIT_REF_FORMAT constants above.
692+
* GIT_REFERENCE_FORMAT constants above.
687693
* @return 0 on success, GIT_EBUFS if buffer is too small, GIT_EINVALIDSPEC
688694
* or an error code.
689695
*/
@@ -743,6 +749,34 @@ GIT_EXTERN(int) git_reference_is_valid_name(const char *refname);
743749
*/
744750
GIT_EXTERN(const char *) git_reference_shorthand(const git_reference *ref);
745751

752+
/**@}*/
753+
754+
/** @name Deprecated Reference Constants
755+
*
756+
* These enumeration values are retained for backward compatibility. The
757+
* newer versions of these functions should be preferred in all new code.
758+
*/
759+
/**@{*/
760+
761+
/** Basic type of any Git reference. */
762+
#define git_ref_t git_reference_t
763+
#define git_reference_normalize_t git_reference_format_t
764+
765+
GIT_DEPRECATED(static const unsigned int) GIT_REF_INVALID = GIT_REFERENCE_INVALID;
766+
GIT_DEPRECATED(static const unsigned int) GIT_REF_OID = GIT_REFERENCE_DIRECT;
767+
GIT_DEPRECATED(static const unsigned int) GIT_REF_SYMBOLIC = GIT_REFERENCE_SYMBOLIC;
768+
GIT_DEPRECATED(static const unsigned int) GIT_REF_LISTALL = GIT_REFERENCE_ALL;
769+
770+
GIT_DEPRECATED(static const unsigned int) GIT_REF_FORMAT_NORMAL =
771+
GIT_REFERENCE_FORMAT_NORMAL;
772+
GIT_DEPRECATED(static const unsigned int) GIT_REF_FORMAT_ALLOW_ONELEVEL =
773+
GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL;
774+
GIT_DEPRECATED(static const unsigned int) GIT_REF_FORMAT_REFSPEC_PATTERN =
775+
GIT_REFERENCE_FORMAT_REFSPEC_PATTERN;
776+
GIT_DEPRECATED(static const unsigned int) GIT_REF_FORMAT_REFSPEC_SHORTHAND =
777+
GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND;
778+
779+
/**@}*/
746780

747781
/** @} */
748782
GIT_END_DECL

include/git2/types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ typedef struct git_rebase git_rebase;
193193

194194
/** Basic type of any Git reference. */
195195
typedef enum {
196-
GIT_REF_INVALID = 0, /**< Invalid reference */
197-
GIT_REF_OID = 1, /**< A reference which points at an object id */
198-
GIT_REF_SYMBOLIC = 2, /**< A reference which points at another reference */
199-
GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC,
200-
} git_ref_t;
196+
GIT_REFERENCE_INVALID = 0, /**< Invalid reference */
197+
GIT_REFERENCE_DIRECT = 1, /**< A reference that points at an object id */
198+
GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */
199+
GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC,
200+
} git_reference_t;
201201

202202
/** Basic type of any Git branch. */
203203
typedef enum {

src/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int branch_equals(git_repository *repo, const char *path, void *payload)
141141
int equal = 0;
142142

143143
if (git_reference__read_head(&head, repo, path) < 0 ||
144-
git_reference_type(head) != GIT_REF_SYMBOLIC)
144+
git_reference_type(head) != GIT_REFERENCE_SYMBOLIC)
145145
goto done;
146146

147147
equal = !git__strcmp(head->target.symbolic, branch->name);

src/refdb_fs.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,12 @@ static int loose_commit(git_filebuf *file, const git_reference *ref)
811811
{
812812
assert(file && ref);
813813

814-
if (ref->type == GIT_REF_OID) {
814+
if (ref->type == GIT_REFERENCE_DIRECT) {
815815
char oid[GIT_OID_HEXSZ + 1];
816816
git_oid_nfmt(oid, sizeof(oid), &ref->target.oid);
817817

818818
git_filebuf_printf(file, "%s\n", oid);
819-
} else if (ref->type == GIT_REF_SYMBOLIC) {
819+
} else if (ref->type == GIT_REFERENCE_SYMBOLIC) {
820820
git_filebuf_printf(file, GIT_SYMREF "%s\n", ref->target.symbolic);
821821
} else {
822822
assert(0); /* don't let this happen */
@@ -1142,19 +1142,19 @@ static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name,
11421142
goto out;
11431143

11441144
/* If the types don't match, there's no way the values do */
1145-
if (old_id && old_ref->type != GIT_REF_OID) {
1145+
if (old_id && old_ref->type != GIT_REFERENCE_DIRECT) {
11461146
*cmp = -1;
11471147
goto out;
11481148
}
1149-
if (old_target && old_ref->type != GIT_REF_SYMBOLIC) {
1149+
if (old_target && old_ref->type != GIT_REFERENCE_SYMBOLIC) {
11501150
*cmp = 1;
11511151
goto out;
11521152
}
11531153

1154-
if (old_id && old_ref->type == GIT_REF_OID)
1154+
if (old_id && old_ref->type == GIT_REFERENCE_DIRECT)
11551155
*cmp = git_oid_cmp(old_id, &old_ref->target.oid);
11561156

1157-
if (old_target && old_ref->type == GIT_REF_SYMBOLIC)
1157+
if (old_target && old_ref->type == GIT_REFERENCE_SYMBOLIC)
11581158
*cmp = git__strcmp(old_target, old_ref->target.symbolic);
11591159

11601160
out:
@@ -1184,7 +1184,7 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref
11841184
git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
11851185
const char *name;
11861186

1187-
if (ref->type == GIT_REF_SYMBOLIC)
1187+
if (ref->type == GIT_REFERENCE_SYMBOLIC)
11881188
return 0;
11891189

11901190
/* if we can't resolve, we use {0}*40 as old id */
@@ -1194,14 +1194,14 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref
11941194
if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0)
11951195
return error;
11961196

1197-
if (git_reference_type(head) == GIT_REF_OID)
1197+
if (git_reference_type(head) == GIT_REFERENCE_DIRECT)
11981198
goto cleanup;
11991199

12001200
if ((error = git_reference_lookup(&tmp, backend->repo, GIT_HEAD_FILE)) < 0)
12011201
goto cleanup;
12021202

12031203
/* Go down the symref chain until we find the branch */
1204-
while (git_reference_type(tmp) == GIT_REF_SYMBOLIC) {
1204+
while (git_reference_type(tmp) == GIT_REFERENCE_SYMBOLIC) {
12051205
error = git_reference_lookup(&peeled, backend->repo, git_reference_symbolic_target(tmp));
12061206
if (error < 0)
12071207
break;
@@ -1279,7 +1279,7 @@ static int refdb_fs_backend__write_tail(
12791279
goto on_error;
12801280
}
12811281

1282-
if (ref->type == GIT_REF_SYMBOLIC)
1282+
if (ref->type == GIT_REFERENCE_SYMBOLIC)
12831283
new_target = ref->target.symbolic;
12841284
else
12851285
new_id = &ref->target.oid;
@@ -1886,7 +1886,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
18861886
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
18871887
git_repository *repo = backend->repo;
18881888

1889-
is_symbolic = ref->type == GIT_REF_SYMBOLIC;
1889+
is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
18901890

18911891
/* "normal" symbolic updates do not write */
18921892
if (is_symbolic &&
@@ -1979,7 +1979,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
19791979
repo = backend->repo;
19801980

19811981
if ((error = git_reference__normalize_name(
1982-
&normalized, new_name, GIT_REF_FORMAT_ALLOW_ONELEVEL)) < 0)
1982+
&normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
19831983
return error;
19841984

19851985
if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)

0 commit comments

Comments
 (0)