Unverified Commit 0a710091 by Edward Thomson Committed by GitHub

Merge pull request #5786 from libgit2/ethomson/revparse

revspec: rename git_revparse_mode_t to git_revspec_t
parents 41ccbc04 4732e030
...@@ -54,7 +54,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[]) ...@@ -54,7 +54,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
*/ */
if (o.commitspec) { if (o.commitspec) {
check_lg2(git_revparse(&revspec, repo, o.commitspec), "Couldn't parse commit spec", NULL); check_lg2(git_revparse(&revspec, repo, o.commitspec), "Couldn't parse commit spec", NULL);
if (revspec.flags & GIT_REVPARSE_SINGLE) { if (revspec.flags & GIT_REVSPEC_SINGLE) {
git_oid_cpy(&blameopts.newest_commit, git_object_id(revspec.from)); git_oid_cpy(&blameopts.newest_commit, git_object_id(revspec.from));
git_object_free(revspec.from); git_object_free(revspec.from);
} else { } else {
......
...@@ -245,7 +245,7 @@ static int add_revision(struct log_state *s, const char *revstr) ...@@ -245,7 +245,7 @@ static int add_revision(struct log_state *s, const char *revstr)
} }
if (*revstr == '^') { if (*revstr == '^') {
revs.flags = GIT_REVPARSE_SINGLE; revs.flags = GIT_REVSPEC_SINGLE;
hide = !hide; hide = !hide;
if (git_revparse_single(&revs.from, s->repo, revstr + 1) < 0) if (git_revparse_single(&revs.from, s->repo, revstr + 1) < 0)
...@@ -253,12 +253,12 @@ static int add_revision(struct log_state *s, const char *revstr) ...@@ -253,12 +253,12 @@ static int add_revision(struct log_state *s, const char *revstr)
} else if (git_revparse(&revs, s->repo, revstr) < 0) } else if (git_revparse(&revs, s->repo, revstr) < 0)
return -1; return -1;
if ((revs.flags & GIT_REVPARSE_SINGLE) != 0) if ((revs.flags & GIT_REVSPEC_SINGLE) != 0)
push_rev(s, revs.from, hide); push_rev(s, revs.from, hide);
else { else {
push_rev(s, revs.to, hide); push_rev(s, revs.to, hide);
if ((revs.flags & GIT_REVPARSE_MERGE_BASE) != 0) { if ((revs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
git_oid base; git_oid base;
check_lg2(git_merge_base(&base, s->repo, check_lg2(git_merge_base(&base, s->repo,
git_object_id(revs.from), git_object_id(revs.to)), git_object_id(revs.from), git_object_id(revs.to)),
......
...@@ -73,7 +73,7 @@ static int push_range(git_repository *repo, git_revwalk *walk, const char *range ...@@ -73,7 +73,7 @@ static int push_range(git_repository *repo, git_revwalk *walk, const char *range
if ((error = git_revparse(&revspec, repo, range))) if ((error = git_revparse(&revspec, repo, range)))
return error; return error;
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */ /* TODO: support "<commit>...<commit>" */
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
......
...@@ -69,17 +69,17 @@ static int parse_revision(git_repository *repo, struct parse_state *ps) ...@@ -69,17 +69,17 @@ static int parse_revision(git_repository *repo, struct parse_state *ps)
check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec); check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec);
if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) { if ((rs.flags & GIT_REVSPEC_SINGLE) != 0) {
git_oid_tostr(str, sizeof(str), git_object_id(rs.from)); git_oid_tostr(str, sizeof(str), git_object_id(rs.from));
printf("%s\n", str); printf("%s\n", str);
git_object_free(rs.from); git_object_free(rs.from);
} }
else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) { else if ((rs.flags & GIT_REVSPEC_RANGE) != 0) {
git_oid_tostr(str, sizeof(str), git_object_id(rs.to)); git_oid_tostr(str, sizeof(str), git_object_id(rs.to));
printf("%s\n", str); printf("%s\n", str);
git_object_free(rs.to); git_object_free(rs.to);
if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) { if ((rs.flags & GIT_REVSPEC_MERGE_BASE) != 0) {
git_oid base; git_oid base;
check_lg2(git_merge_base(&base, repo, check_lg2(git_merge_base(&base, repo,
git_object_id(rs.from), git_object_id(rs.to)), git_object_id(rs.from), git_object_id(rs.to)),
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "trace.h" #include "trace.h"
#include "repository.h" #include "repository.h"
#include "revert.h" #include "revert.h"
#include "revparse.h"
#include "stash.h" #include "stash.h"
#include "status.h" #include "status.h"
#include "submodule.h" #include "submodule.h"
...@@ -414,6 +415,25 @@ GIT_EXTERN(int) git_tag_create_frombuffer( ...@@ -414,6 +415,25 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
/**@}*/ /**@}*/
/** @name Deprecated Revspec Constants
*
* These enumeration values are retained for backward compatibility.
* The newer versions of these values should be preferred in all new
* code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
typedef git_revspec_t git_revparse_mode_t;
#define GIT_REVPARSE_SINGLE GIT_REVSPEC_SINGLE
#define GIT_REVPARSE_RANGE GIT_REVSPEC_RANGE
#define GIT_REVPARSE_MERGE_BASE GIT_REVSPEC_MERGE_BASE
/**@}*/
/** @name Deprecated Credential Types /** @name Deprecated Credential Types
* *
* These types are retained for backward compatibility. The newer * These types are retained for backward compatibility. The newer
...@@ -422,6 +442,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer( ...@@ -422,6 +442,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* There is no plan to remove these backward compatibility values at * There is no plan to remove these backward compatibility values at
* this time. * this time.
*/ */
/**@{*/
typedef git_credential git_cred; typedef git_credential git_cred;
typedef git_credential_userpass_plaintext git_cred_userpass_plaintext; typedef git_credential_userpass_plaintext git_cred_userpass_plaintext;
......
...@@ -70,12 +70,12 @@ GIT_EXTERN(int) git_revparse_ext( ...@@ -70,12 +70,12 @@ GIT_EXTERN(int) git_revparse_ext(
*/ */
typedef enum { typedef enum {
/** The spec targeted a single object. */ /** The spec targeted a single object. */
GIT_REVPARSE_SINGLE = 1 << 0, GIT_REVSPEC_SINGLE = 1 << 0,
/** The spec targeted a range of commits. */ /** The spec targeted a range of commits. */
GIT_REVPARSE_RANGE = 1 << 1, GIT_REVSPEC_RANGE = 1 << 1,
/** The spec used the '...' operator, which invokes special semantics. */ /** The spec used the '...' operator, which invokes special semantics. */
GIT_REVPARSE_MERGE_BASE = 1 << 2, GIT_REVSPEC_MERGE_BASE = 1 << 2,
} git_revparse_mode_t; } git_revspec_t;
/** /**
* Git Revision Spec: output of a `git_revparse` operation * Git Revision Spec: output of a `git_revparse` operation
...@@ -85,7 +85,7 @@ typedef struct { ...@@ -85,7 +85,7 @@ typedef struct {
git_object *from; git_object *from;
/** The right element of the revspec; must be freed by the user */ /** The right element of the revspec; must be freed by the user */
git_object *to; git_object *to;
/** The intent of the revspec (i.e. `git_revparse_mode_t` flags) */ /** The intent of the revspec (i.e. `git_revspec_mode_t` flags) */
unsigned int flags; unsigned int flags;
} git_revspec; } git_revspec;
......
...@@ -894,7 +894,7 @@ int git_revparse( ...@@ -894,7 +894,7 @@ int git_revparse(
if ((dotdot = strstr(spec, "..")) != NULL) { if ((dotdot = strstr(spec, "..")) != NULL) {
char *lstr; char *lstr;
const char *rstr; const char *rstr;
revspec->flags = GIT_REVPARSE_RANGE; revspec->flags = GIT_REVSPEC_RANGE;
/* /*
* Following git.git, don't allow '..' because it makes command line * Following git.git, don't allow '..' because it makes command line
...@@ -910,7 +910,7 @@ int git_revparse( ...@@ -910,7 +910,7 @@ int git_revparse(
lstr = git__substrdup(spec, dotdot - spec); lstr = git__substrdup(spec, dotdot - spec);
rstr = dotdot + 2; rstr = dotdot + 2;
if (dotdot[2] == '.') { if (dotdot[2] == '.') {
revspec->flags |= GIT_REVPARSE_MERGE_BASE; revspec->flags |= GIT_REVSPEC_MERGE_BASE;
rstr++; rstr++;
} }
...@@ -928,7 +928,7 @@ int git_revparse( ...@@ -928,7 +928,7 @@ int git_revparse(
git__free((void*)lstr); git__free((void*)lstr);
} else { } else {
revspec->flags = GIT_REVPARSE_SINGLE; revspec->flags = GIT_REVSPEC_SINGLE;
error = git_revparse_single(&revspec->from, repo, spec); error = git_revparse_single(&revspec->from, repo, spec);
} }
......
...@@ -238,7 +238,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range) ...@@ -238,7 +238,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
goto out; goto out;
} }
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { if (revspec.flags & GIT_REVSPEC_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */ /* TODO: support "<commit>...<commit>" */
git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk"); git_error_set(GIT_ERROR_INVALID, "symmetric differences not implemented in revwalk");
error = GIT_EINVALIDSPEC; error = GIT_EINVALIDSPEC;
......
...@@ -50,7 +50,7 @@ static void test_id_inrepo( ...@@ -50,7 +50,7 @@ static void test_id_inrepo(
const char *spec, const char *spec,
const char *expected_left, const char *expected_left,
const char *expected_right, const char *expected_right,
git_revparse_mode_t expected_flags, git_revspec_t expected_flags,
git_repository *repo) git_repository *repo)
{ {
git_revspec revspec; git_revspec revspec;
...@@ -90,7 +90,7 @@ static void test_object_and_ref(const char *spec, const char *expected_oid, cons ...@@ -90,7 +90,7 @@ static void test_object_and_ref(const char *spec, const char *expected_oid, cons
static void test_rangelike(const char *rangelike, static void test_rangelike(const char *rangelike,
const char *expected_left, const char *expected_left,
const char *expected_right, const char *expected_right,
git_revparse_mode_t expected_revparseflags) git_revspec_t expected_revparseflags)
{ {
char objstr[64] = {0}; char objstr[64] = {0};
git_revspec revspec; git_revspec revspec;
...@@ -117,7 +117,7 @@ static void test_id( ...@@ -117,7 +117,7 @@ static void test_id(
const char *spec, const char *spec,
const char *expected_left, const char *expected_left,
const char *expected_right, const char *expected_right,
git_revparse_mode_t expected_flags) git_revspec_t expected_flags)
{ {
test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo); test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
} }
...@@ -735,53 +735,53 @@ void test_refs_revparse__range(void) ...@@ -735,53 +735,53 @@ void test_refs_revparse__range(void)
test_rangelike("be3563a^1..be3563a", test_rangelike("be3563a^1..be3563a",
"9fd738e8f7967c078dceed8190330fc8648ee56a", "9fd738e8f7967c078dceed8190330fc8648ee56a",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
GIT_REVPARSE_RANGE); GIT_REVSPEC_RANGE);
test_rangelike("be3563a^1...be3563a", test_rangelike("be3563a^1...be3563a",
"9fd738e8f7967c078dceed8190330fc8648ee56a", "9fd738e8f7967c078dceed8190330fc8648ee56a",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_rangelike("be3563a^1.be3563a", NULL, NULL, 0); test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
} }
void test_refs_revparse__parses_range_operator(void) void test_refs_revparse__parses_range_operator(void)
{ {
test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE); test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
test_id("HEAD~3..HEAD", test_id("HEAD~3..HEAD",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
GIT_REVPARSE_RANGE); GIT_REVSPEC_RANGE);
test_id("HEAD~3...HEAD", test_id("HEAD~3...HEAD",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("HEAD~3..", test_id("HEAD~3..",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
GIT_REVPARSE_RANGE); GIT_REVSPEC_RANGE);
test_id("HEAD~3...", test_id("HEAD~3...",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("..HEAD~3", test_id("..HEAD~3",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
GIT_REVPARSE_RANGE); GIT_REVSPEC_RANGE);
test_id("...HEAD~3", test_id("...HEAD~3",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_id("...", test_id("...",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
test_invalid_revspec(".."); test_invalid_revspec("..");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment