[libgit2-glib] Use git_reference_is_branch instead of manual check



commit 0a5d440d21197157e029c4f8523786b435a451b4
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Dec 21 21:41:50 2014 +0100

    Use git_reference_is_branch instead of manual check

 libgit2-glib/ggit-branch.c     |   15 +--------------
 libgit2-glib/ggit-ref.c        |   14 +++++++++++---
 libgit2-glib/ggit-repository.c |    9 +--------
 3 files changed, 13 insertions(+), 25 deletions(-)
---
diff --git a/libgit2-glib/ggit-branch.c b/libgit2-glib/ggit-branch.c
index a13f150..9cee659 100644
--- a/libgit2-glib/ggit-branch.c
+++ b/libgit2-glib/ggit-branch.c
@@ -165,8 +165,6 @@ ggit_branch_get_upstream (GgitBranch  *branch,
 {
        gint ret;
        git_reference *upstream;
-       const gchar *name;
-       GgitRef *ref;
 
        g_return_val_if_fail (GGIT_IS_BRANCH (branch), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -180,18 +178,7 @@ ggit_branch_get_upstream (GgitBranch  *branch,
                return NULL;
        }
 
-       name = git_reference_name (upstream);
-
-       if (g_str_has_prefix (name, "refs/heads/"))
-       {
-               ref = GGIT_REF (_ggit_branch_wrap (upstream));
-       }
-       else
-       {
-               ref = _ggit_ref_wrap (upstream);
-       }
-
-       return ref;
+       return _ggit_ref_wrap (upstream);
 }
 
 /**
diff --git a/libgit2-glib/ggit-ref.c b/libgit2-glib/ggit-ref.c
index 0b20eb4..8044d9e 100644
--- a/libgit2-glib/ggit-ref.c
+++ b/libgit2-glib/ggit-ref.c
@@ -25,6 +25,7 @@
 #include "ggit-repository.h"
 #include "ggit-signature.h"
 #include "ggit-utils.h"
+#include "ggit-branch.h"
 
 #include <git2.h>
 
@@ -45,9 +46,16 @@ ggit_ref_init (GgitRef *self)
 GgitRef *
 _ggit_ref_wrap (git_reference *ref)
 {
-       return g_object_new (GGIT_TYPE_REF,
-                            "native", ref,
-                            NULL);
+       if (git_reference_is_branch (ref))
+       {
+               return GGIT_REF (_ggit_branch_wrap (ref));
+       }
+       else
+       {
+               return g_object_new (GGIT_TYPE_REF,
+                                    "native", ref,
+                                    NULL);
+       }
 }
 
 /**
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 8eac80c..b51141a 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -624,14 +624,7 @@ ggit_repository_lookup_reference (GgitRepository  *repository,
 
        if (ret == GIT_OK)
        {
-               if (g_str_has_prefix (name, "refs/heads/"))
-               {
-                       ref = GGIT_REF (_ggit_branch_wrap (reference));
-               }
-               else
-               {
-                       ref = _ggit_ref_wrap (reference);
-               }
+               ref = _ggit_ref_wrap (reference);
        }
        else
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]