Commit 04865aa05e9d16ad56920103678ee4c34578da78

Carlos Martín Nieto 2014-05-21T10:01:44

local transport: expose the symref data When using the local transport, we always have the symbolic information available, so fill it.

diff --git a/src/transports/local.c b/src/transports/local.c
index 2c17e62..8d36193 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -43,14 +43,19 @@ typedef struct {
 static int add_ref(transport_local *t, const char *name)
 {
 	const char peeled[] = "^{}";
-	git_oid head_oid;
+	git_reference *ref, *resolved;
 	git_remote_head *head;
+	git_oid obj_id;
 	git_object *obj = NULL, *target = NULL;
 	git_buf buf = GIT_BUF_INIT;
 	int error;
 
-	error = git_reference_name_to_id(&head_oid, t->repo, name);
+	if ((error = git_reference_lookup(&ref, t->repo, name)) < 0)
+		return error;
+
+	error = git_reference_resolve(&resolved, ref);
 	if (error < 0) {
+		git_reference_free(ref);
 		if (!strcmp(name, GIT_HEAD_FILE) && error == GIT_ENOTFOUND) {
 			/* This is actually okay.  Empty repos often have a HEAD that
 			 * points to a nonexistent "refs/heads/master". */
@@ -60,13 +65,22 @@ static int add_ref(transport_local *t, const char *name)
 		return error;
 	}
 
+	git_oid_cpy(&obj_id, git_reference_target(resolved));
+	git_reference_free(resolved);
+
 	head = git__calloc(1, sizeof(git_remote_head));
 	GITERR_CHECK_ALLOC(head);
 
 	head->name = git__strdup(name);
 	GITERR_CHECK_ALLOC(head->name);
 
-	git_oid_cpy(&head->oid, &head_oid);
+	git_oid_cpy(&head->oid, &obj_id);
+
+	if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
+		head->symref_target = git__strdup(git_reference_symbolic_target(ref));
+		GITERR_CHECK_ALLOC(head->symref_target);
+	}
+	git_reference_free(ref);
 
 	if ((error = git_vector_insert(&t->refs, head)) < 0) {
 		git__free(head->name);
@@ -176,7 +190,7 @@ static int path_from_url_or_path(git_buf *local_path_out, const char *url_or_pat
 
 /*
  * Try to open the url as a git directory. The direction doesn't
- * matter in this case because we're calulating the heads ourselves.
+ * matter in this case because we're calculating the heads ourselves.
  */
 static int local_connect(
 	git_transport *transport,