Implemented rev-parse "^{type}" syntax.
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
diff --git a/src/revparse.c b/src/revparse.c
index da274f8..472cc75 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -116,7 +116,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
static int walk_ref_history(git_object **out, const char *refspec, const char *reflogspec)
{
- // TODO
+ /* TODO */
/* Empty refspec means current branch */
@@ -134,25 +134,25 @@ static git_object* dereference_object(git_object *obj)
{
git_otype type = git_object_type(obj);
git_object *newobj = NULL;
+ git_tree *tree = NULL;
switch (type) {
case GIT_OBJ_COMMIT:
- break;
- case GIT_OBJ_TREE:
- break;
- case GIT_OBJ_BLOB:
+ if (0 == git_commit_tree(&tree, (git_commit*)obj)) {
+ return (git_object*)tree;
+ }
break;
case GIT_OBJ_TAG:
if (0 == git_tag_target(&newobj, (git_tag*)obj)) {
return newobj;
}
break;
- case GIT_OBJ_OFS_DELTA:
- break;
- case GIT_OBJ_REF_DELTA:
- break;
default:
+ case GIT_OBJ_TREE:
+ case GIT_OBJ_BLOB:
+ case GIT_OBJ_OFS_DELTA:
+ case GIT_OBJ_REF_DELTA:
break;
}
@@ -168,14 +168,14 @@ static int dereference_to_type(git_object **out, git_object *obj, git_otype targ
git_otype this_type = git_object_type(obj1);
if (this_type == target_type) {
- *out = obj;
+ *out = obj1;
return 0;
}
/* Dereference once, if possible. */
obj2 = dereference_object(obj1);
- if (obj2 != obj) {
- git_object_free(obj2);
+ if (obj1 != obj) {
+ git_object_free(obj1);
}
obj1 = obj2;
}
@@ -212,7 +212,7 @@ static int handle_caret_syntax(git_object **out, git_object *obj, const char *mo
giterr_set(GITERR_REFERENCE, "Couldn't find object of target type.");
return GIT_ERROR;
}
- newobj = newobj;
+ newobj = newobj2;
}
*out = newobj2;
return 0;
@@ -220,7 +220,7 @@ static int handle_caret_syntax(git_object **out, git_object *obj, const char *mo
/* {/...} -> Walk all commits until we see a commit msg that matches the phrase. */
if (movement[1] == '/') {
- // TODO
+ /* TODO */
return GIT_ERROR;
}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 64aca4a..c1be32f 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -7,7 +7,7 @@ static git_object *g_obj;
-// Hepers
+/* Helpers */
static void oid_str_cmp(const git_object *obj, const char *expected)
{
char objstr[64] = {0};
@@ -35,7 +35,6 @@ void test_refs_revparse__nonexistant_object(void)
void test_refs_revparse__shas(void)
{
- // Full SHA should return a valid object
cl_git_pass(git_revparse_single(&g_obj, g_repo, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
oid_str_cmp(g_obj, "c47800c7266a2be04c571c04d5a6614691ea99bd");
cl_git_pass(git_revparse_single(&g_obj, g_repo, "c47800c"));
@@ -44,14 +43,12 @@ void test_refs_revparse__shas(void)
void test_refs_revparse__head(void)
{
- // Named head should return a valid object
cl_git_pass(git_revparse_single(&g_obj, g_repo, "HEAD"));
oid_str_cmp(g_obj, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
}
void test_refs_revparse__full_refs(void)
{
- // Fully-qualified refs should return valid objects
cl_git_pass(git_revparse_single(&g_obj, g_repo, "refs/heads/master"));
oid_str_cmp(g_obj, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_pass(git_revparse_single(&g_obj, g_repo, "refs/heads/test"));
@@ -62,7 +59,6 @@ void test_refs_revparse__full_refs(void)
void test_refs_revparse__partial_refs(void)
{
- // Partially-qualified refs should return valid objects
cl_git_pass(git_revparse_single(&g_obj, g_repo, "point_to_blob"));
oid_str_cmp(g_obj, "1385f264afb75a56a5bec74243be9b367ba4ca08");
cl_git_pass(git_revparse_single(&g_obj, g_repo, "packed-test"));
@@ -103,9 +99,15 @@ void test_refs_revparse__not_tag(void)
void test_refs_revparse__to_type(void)
{
+ cl_git_pass(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{commit}"));
+ oid_str_cmp(g_obj, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ cl_git_pass(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{tree}"));
+ oid_str_cmp(g_obj, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ cl_git_pass(git_revparse_single(&g_obj, g_repo, "point_to_blob^{blob}"));
+ oid_str_cmp(g_obj, "1385f264afb75a56a5bec74243be9b367ba4ca08");
}
void test_refs_revparse__reflog(void)
{
- // TODO: how to create a fixture for this? git_reflog_write?
+ /* TODO: how to create a fixture for this? git_reflog_write? */
}