Skip to content

Commit 4732e03

Browse files
committed
revspec: rename git_revparse_mode_t to git_revspec_t
The information about the type of a revision spec is not information about the parser. Name it accordingly, so that `git_revparse_mode_t` is now `git_revspec_t`. Deprecate the old name.
1 parent 50f5362 commit 4732e03

File tree

9 files changed

+51
-30
lines changed

9 files changed

+51
-30
lines changed

examples/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
5454
*/
5555
if (o.commitspec) {
5656
check_lg2(git_revparse(&revspec, repo, o.commitspec), "Couldn't parse commit spec", NULL);
57-
if (revspec.flags & GIT_REVPARSE_SINGLE) {
57+
if (revspec.flags & GIT_REVSPEC_SINGLE) {
5858
git_oid_cpy(&blameopts.newest_commit, git_object_id(revspec.from));
5959
git_object_free(revspec.from);
6060
} else {

examples/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,20 @@ static int add_revision(struct log_state *s, const char *revstr)
245245
}
246246

247247
if (*revstr == '^') {
248-
revs.flags = GIT_REVPARSE_SINGLE;
248+
revs.flags = GIT_REVSPEC_SINGLE;
249249
hide = !hide;
250250

251251
if (git_revparse_single(&revs.from, s->repo, revstr + 1) < 0)
252252
return -1;
253253
} else if (git_revparse(&revs, s->repo, revstr) < 0)
254254
return -1;
255255

256-
if ((revs.flags & GIT_REVPARSE_SINGLE) != 0)
256+
if ((revs.flags & GIT_REVSPEC_SINGLE) != 0)
257257
push_rev(s, revs.from, hide);
258258
else {
259259
push_rev(s, revs.to, hide);
260260

261-
if ((revs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
261+
if ((revs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
262262
git_oid base;
263263
check_lg2(git_merge_base(&base, s->repo,
264264
git_object_id(revs.from), git_object_id(revs.to)),

examples/rev-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int push_range(git_repository *repo, git_revwalk *walk, const char *range
7373
if ((error = git_revparse(&revspec, repo, range)))
7474
return error;
7575

76-
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
76+
if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
7777
/* TODO: support "<commit>...<commit>" */
7878
return GIT_EINVALIDSPEC;
7979
}

examples/rev-parse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ static int parse_revision(git_repository *repo, struct parse_state *ps)
6969

7070
check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec);
7171

72-
if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) {
72+
if ((rs.flags & GIT_REVSPEC_SINGLE) != 0) {
7373
git_oid_tostr(str, sizeof(str), git_object_id(rs.from));
7474
printf("%s\n", str);
7575
git_object_free(rs.from);
7676
}
77-
else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) {
77+
else if ((rs.flags & GIT_REVSPEC_RANGE) != 0) {
7878
git_oid_tostr(str, sizeof(str), git_object_id(rs.to));
7979
printf("%s\n", str);
8080
git_object_free(rs.to);
8181

82-
if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
82+
if ((rs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
8383
git_oid base;
8484
check_lg2(git_merge_base(&base, repo,
8585
git_object_id(rs.from), git_object_id(rs.to)),

include/git2/deprecated.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "trace.h"
3030
#include "repository.h"
3131
#include "revert.h"
32+
#include "revparse.h"
3233
#include "stash.h"
3334
#include "status.h"
3435
#include "submodule.h"
@@ -414,6 +415,25 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
414415

415416
/**@}*/
416417

418+
/** @name Deprecated Revspec Constants
419+
*
420+
* These enumeration values are retained for backward compatibility.
421+
* The newer versions of these values should be preferred in all new
422+
* code.
423+
*
424+
* There is no plan to remove these backward compatibility values at
425+
* this time.
426+
*/
427+
/**@{*/
428+
429+
typedef git_revspec_t git_revparse_mode_t;
430+
431+
#define GIT_REVPARSE_SINGLE GIT_REVSPEC_SINGLE
432+
#define GIT_REVPARSE_RANGE GIT_REVSPEC_RANGE
433+
#define GIT_REVPARSE_MERGE_BASE GIT_REVSPEC_MERGE_BASE
434+
435+
/**@}*/
436+
417437
/** @name Deprecated Credential Types
418438
*
419439
* These types are retained for backward compatibility. The newer
@@ -422,6 +442,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
422442
* There is no plan to remove these backward compatibility values at
423443
* this time.
424444
*/
445+
/**@{*/
425446

426447
typedef git_credential git_cred;
427448
typedef git_credential_userpass_plaintext git_cred_userpass_plaintext;

include/git2/revparse.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ GIT_EXTERN(int) git_revparse_ext(
7070
*/
7171
typedef enum {
7272
/** The spec targeted a single object. */
73-
GIT_REVPARSE_SINGLE = 1 << 0,
73+
GIT_REVSPEC_SINGLE = 1 << 0,
7474
/** The spec targeted a range of commits. */
75-
GIT_REVPARSE_RANGE = 1 << 1,
75+
GIT_REVSPEC_RANGE = 1 << 1,
7676
/** The spec used the '...' operator, which invokes special semantics. */
77-
GIT_REVPARSE_MERGE_BASE = 1 << 2,
78-
} git_revparse_mode_t;
77+
GIT_REVSPEC_MERGE_BASE = 1 << 2,
78+
} git_revspec_t;
7979

8080
/**
8181
* Git Revision Spec: output of a `git_revparse` operation
@@ -85,7 +85,7 @@ typedef struct {
8585
git_object *from;
8686
/** The right element of the revspec; must be freed by the user */
8787
git_object *to;
88-
/** The intent of the revspec (i.e. `git_revparse_mode_t` flags) */
88+
/** The intent of the revspec (i.e. `git_revspec_mode_t` flags) */
8989
unsigned int flags;
9090
} git_revspec;
9191

src/revparse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ int git_revparse(
894894
if ((dotdot = strstr(spec, "..")) != NULL) {
895895
char *lstr;
896896
const char *rstr;
897-
revspec->flags = GIT_REVPARSE_RANGE;
897+
revspec->flags = GIT_REVSPEC_RANGE;
898898

899899
/*
900900
* Following git.git, don't allow '..' because it makes command line
@@ -910,7 +910,7 @@ int git_revparse(
910910
lstr = git__substrdup(spec, dotdot - spec);
911911
rstr = dotdot + 2;
912912
if (dotdot[2] == '.') {
913-
revspec->flags |= GIT_REVPARSE_MERGE_BASE;
913+
revspec->flags |= GIT_REVSPEC_MERGE_BASE;
914914
rstr++;
915915
}
916916

@@ -928,7 +928,7 @@ int git_revparse(
928928

929929
git__free((void*)lstr);
930930
} else {
931-
revspec->flags = GIT_REVPARSE_SINGLE;
931+
revspec->flags = GIT_REVSPEC_SINGLE;
932932
error = git_revparse_single(&revspec->from, repo, spec);
933933
}
934934

src/revwalk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
238238
goto out;
239239
}
240240

241-
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
241+
if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
242242
/* TODO: support "<commit>...<commit>" */
243243
git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk");
244244
error = GIT_EINVALIDSPEC;

tests/refs/revparse.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void test_id_inrepo(
5050
const char *spec,
5151
const char *expected_left,
5252
const char *expected_right,
53-
git_revparse_mode_t expected_flags,
53+
git_revspec_t expected_flags,
5454
git_repository *repo)
5555
{
5656
git_revspec revspec;
@@ -90,7 +90,7 @@ static void test_object_and_ref(const char *spec, const char *expected_oid, cons
9090
static void test_rangelike(const char *rangelike,
9191
const char *expected_left,
9292
const char *expected_right,
93-
git_revparse_mode_t expected_revparseflags)
93+
git_revspec_t expected_revparseflags)
9494
{
9595
char objstr[64] = {0};
9696
git_revspec revspec;
@@ -117,7 +117,7 @@ static void test_id(
117117
const char *spec,
118118
const char *expected_left,
119119
const char *expected_right,
120-
git_revparse_mode_t expected_flags)
120+
git_revspec_t expected_flags)
121121
{
122122
test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
123123
}
@@ -735,53 +735,53 @@ void test_refs_revparse__range(void)
735735
test_rangelike("be3563a^1..be3563a",
736736
"9fd738e8f7967c078dceed8190330fc8648ee56a",
737737
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
738-
GIT_REVPARSE_RANGE);
738+
GIT_REVSPEC_RANGE);
739739

740740
test_rangelike("be3563a^1...be3563a",
741741
"9fd738e8f7967c078dceed8190330fc8648ee56a",
742742
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
743-
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
743+
GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
744744

745745
test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
746746
}
747747

748748
void test_refs_revparse__parses_range_operator(void)
749749
{
750-
test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE);
750+
test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
751751
test_id("HEAD~3..HEAD",
752752
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
753753
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
754-
GIT_REVPARSE_RANGE);
754+
GIT_REVSPEC_RANGE);
755755

756756
test_id("HEAD~3...HEAD",
757757
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
758758
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
759-
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
759+
GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
760760

761761
test_id("HEAD~3..",
762762
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
763763
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
764-
GIT_REVPARSE_RANGE);
764+
GIT_REVSPEC_RANGE);
765765

766766
test_id("HEAD~3...",
767767
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
768768
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
769-
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
769+
GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
770770

771771
test_id("..HEAD~3",
772772
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
773773
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
774-
GIT_REVPARSE_RANGE);
774+
GIT_REVSPEC_RANGE);
775775

776776
test_id("...HEAD~3",
777777
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
778778
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
779-
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
779+
GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
780780

781781
test_id("...",
782782
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
783783
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
784-
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
784+
GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
785785

786786
test_invalid_revspec("..");
787787
}

0 commit comments

Comments
 (0)