Is this crazy?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
diff --git a/include/git2/revparse.h b/include/git2/revparse.h
index a992d2c..3e334b4 100644
--- a/include/git2/revparse.h
+++ b/include/git2/revparse.h
@@ -44,8 +44,16 @@ typedef enum {
GIT_REVPARSE_RANGE = 1 << 1,
/** The spec used the '...' operator, which invokes special semantics. */
GIT_REVPARSE_MERGE_BASE = 1 << 2,
-} git_revparse_flag_t;
+} git_revparse_mode_t;
+/**
+ * Git Revision: output of a `git_revparse` operation
+ */
+typedef struct {
+ git_object *from;
+ git_object *to;
+ unsigned int flags;
+} git_revision;
/**
* Parse a revision string for left, right, and intent. See `man gitrevisions` or
@@ -64,9 +72,7 @@ typedef enum {
* @return 0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code
*/
GIT_EXTERN(int) git_revparse(
- git_object **left,
- git_object **right,
- unsigned int *flags,
+ git_revision *revision,
git_repository *repo,
const char *spec);
diff --git a/src/revparse.c b/src/revparse.c
index d2c14cc..a4fedd2 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -870,47 +870,43 @@ cleanup:
int git_revparse(
- git_object **left,
- git_object **right,
- unsigned int *flags,
- git_repository *repo,
- const char *spec)
+ git_revision *revision,
+ git_repository *repo,
+ const char *spec)
{
- unsigned int lflags = 0;
const char *dotdot;
int error = 0;
- assert(left && repo && spec);
+ assert(revision && repo && spec);
+
+ memset(revision, 0x0, sizeof(*revision));
if ((dotdot = strstr(spec, "..")) != NULL) {
char *lstr;
const char *rstr;
- lflags = GIT_REVPARSE_RANGE;
+ revision->flags = GIT_REVPARSE_RANGE;
- lstr = git__substrdup(spec, dotdot-spec);
+ lstr = git__substrdup(spec, dotdot - spec);
rstr = dotdot + 2;
if (dotdot[2] == '.') {
- lflags |= GIT_REVPARSE_MERGE_BASE;
+ revision->flags |= GIT_REVPARSE_MERGE_BASE;
rstr++;
}
- if ((error = git_revparse_single(left, repo, lstr)) < 0) {
+ if ((error = git_revparse_single(&revision->from, repo, lstr)) < 0) {
return error;
}
- if (right &&
- (error = git_revparse_single(right, repo, rstr)) < 0) {
+
+ if ((error = git_revparse_single(&revision->to, repo, rstr)) < 0) {
return error;
}
git__free((void*)lstr);
} else {
- lflags = GIT_REVPARSE_SINGLE;
- error = git_revparse_single(left, repo, spec);
+ revision->flags = GIT_REVPARSE_SINGLE;
+ error = git_revparse_single(&revision->from, repo, spec);
}
- if (flags)
- *flags = lflags;
-
return error;
}
diff --git a/src/revwalk.c b/src/revwalk.c
index 05e99c0..9e32198 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -231,25 +231,26 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
int git_revwalk_push_range(git_revwalk *walk, const char *range)
{
- git_object *left, *right;
- git_revparse_flag_t revparseflags;
+ git_revision revision;
int error = 0;
- if ((error = git_revparse(&left, &right, &revparseflags, walk->repo, range)))
+ if ((error = git_revparse(&revision, walk->repo, range)))
return error;
- if (revparseflags & GIT_REVPARSE_MERGE_BASE) {
+
+ if (revision.flags & GIT_REVPARSE_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */
giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk");
return GIT_EINVALIDSPEC;
}
- if ((error = push_commit(walk, git_object_id(left), 1)))
+ if ((error = push_commit(walk, git_object_id(revision.from), 1)))
goto out;
- error = push_commit(walk, git_object_id(right), 0);
- out:
- git_object_free(left);
- git_object_free(right);
+ error = push_commit(walk, git_object_id(revision.to), 0);
+
+out:
+ git_object_free(revision.from);
+ git_object_free(revision.to);
return error;
}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index c1cfc58..ad52006 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -31,33 +31,31 @@ static void test_id_inrepo(
const char *spec,
const char *expected_left,
const char *expected_right,
- git_revparse_flag_t expected_flags,
+ git_revparse_mode_t expected_flags,
git_repository *repo)
{
- git_object *l, *r;
- git_revparse_flag_t flags = 0;
-
- int error = git_revparse(&l, &r, &flags, repo, spec);
+ git_revision revision;
+ int error = git_revparse(&revision, repo, spec);
if (expected_left) {
char str[64] = {0};
cl_assert_equal_i(0, error);
- git_oid_fmt(str, git_object_id(l));
+ git_oid_fmt(str, git_object_id(revision.from));
cl_assert_equal_s(str, expected_left);
- git_object_free(l);
+ git_object_free(revision.from);
} else {
cl_assert_equal_i(GIT_ENOTFOUND, error);
}
if (expected_right) {
char str[64] = {0};
- git_oid_fmt(str, git_object_id(r));
+ git_oid_fmt(str, git_object_id(revision.to));
cl_assert_equal_s(str, expected_right);
- git_object_free(r);
+ git_object_free(revision.to);
}
if (expected_flags)
- cl_assert_equal_i(expected_flags, flags);
+ cl_assert_equal_i(expected_flags, revision.flags);
}
static void test_object(const char *spec, const char *expected_oid)
@@ -68,27 +66,26 @@ static void test_object(const char *spec, const char *expected_oid)
static void test_rangelike(const char *rangelike,
const char *expected_left,
const char *expected_right,
- git_revparse_flag_t expected_revparseflags)
+ git_revparse_mode_t expected_revparseflags)
{
char objstr[64] = {0};
- git_object *left = NULL, *right = NULL;
- git_revparse_flag_t revparseflags;
+ git_revision revision;
int error;
- error = git_revparse(&left, &right, &revparseflags, g_repo, rangelike);
+ error = git_revparse(&revision, g_repo, rangelike);
if (expected_left != NULL) {
cl_assert_equal_i(0, error);
- cl_assert_equal_i(revparseflags, expected_revparseflags);
- git_oid_fmt(objstr, git_object_id(left));
+ cl_assert_equal_i(revision.flags, expected_revparseflags);
+ git_oid_fmt(objstr, git_object_id(revision.from));
cl_assert_equal_s(objstr, expected_left);
- git_oid_fmt(objstr, git_object_id(right));
+ git_oid_fmt(objstr, git_object_id(revision.to));
cl_assert_equal_s(objstr, expected_right);
} else
cl_assert(error != 0);
- git_object_free(left);
- git_object_free(right);
+ git_object_free(revision.from);
+ git_object_free(revision.to);
}
@@ -96,7 +93,7 @@ static void test_id(
const char *spec,
const char *expected_left,
const char *expected_right,
- git_revparse_flag_t expected_flags)
+ git_revparse_mode_t expected_flags)
{
test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
}
@@ -684,21 +681,17 @@ void test_refs_revparse__range(void)
test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
}
-void test_refs_revparse__validates_args(void)
-{
- git_object *l, *r;
- git_revparse_flag_t flags = 0;
-
- cl_git_pass(git_revparse(&l,&r,NULL, g_repo, "HEAD"));
- cl_git_pass(git_revparse(&l,NULL,&flags, g_repo, "HEAD"));
- cl_assert_equal_i(GIT_EINVALIDSPEC, git_revparse(&l,&r,&flags, g_repo, "^&*("));
-}
-
void test_refs_revparse__parses_range_operator(void)
{
test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE);
- test_id("HEAD~3..HEAD", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_REVPARSE_RANGE);
- test_id("HEAD~3...HEAD", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
- GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+ test_id("HEAD~3..HEAD",
+ "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ GIT_REVPARSE_RANGE);
+
+ test_id("HEAD~3...HEAD",
+ "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+ GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
}