diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-05-21 10:01:44 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-05-21 12:12:32 +0200 |
commit | 04865aa05e9d16ad56920103678ee4c34578da78 (patch) | |
tree | 1ea4aeaeb540fe6cee3d378a31369caab2aaa7ae | |
parent | 306475eb0173d7943a27afee6054af8d0f76bedd (diff) | |
download | libgit2-04865aa05e9d16ad56920103678ee4c34578da78.tar.gz |
local transport: expose the symref data
When using the local transport, we always have the symbolic information
available, so fill it.
-rw-r--r-- | src/transports/local.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/transports/local.c b/src/transports/local.c index 2c17e6271..8d3619388 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, |