[gnome-builder] vcs: allow fetching the current branch name
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vcs: allow fetching the current branch name
- Date: Tue, 28 Jun 2016 00:04:12 +0000 (UTC)
commit dedcab41e4b1be971c2586ac183e179a2b95e93e
Author: Christian Hergert <chergert redhat com>
Date: Tue Jun 21 18:08:19 2016 -0700
vcs: allow fetching the current branch name
If you want to watch for changes, connect to ::changed and then call this
function again.
libide/vcs/ide-vcs.c | 18 ++++++++++++++++++
libide/vcs/ide-vcs.h | 2 ++
plugins/git/ide-git-vcs.c | 21 +++++++++++++++++++++
3 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/libide/vcs/ide-vcs.c b/libide/vcs/ide-vcs.c
index 115b6cb..f2033a1 100644
--- a/libide/vcs/ide-vcs.c
+++ b/libide/vcs/ide-vcs.c
@@ -208,3 +208,21 @@ ide_vcs_get_config (IdeVcs *self)
return ret;
}
+
+/**
+ * ide_vcs_get_branch_name:
+ *
+ * Retrieves the name of the branch in the current working directory.
+ *
+ * Returns: (transfer full): A string containing the branch name.
+ */
+gchar *
+ide_vcs_get_branch_name (IdeVcs *self)
+{
+ g_return_val_if_fail (IDE_IS_VCS (self), NULL);
+
+ if (IDE_VCS_GET_IFACE (self)->get_branch_name)
+ return IDE_VCS_GET_IFACE (self)->get_branch_name (self);
+
+ return g_strdup ("primary");
+}
diff --git a/libide/vcs/ide-vcs.h b/libide/vcs/ide-vcs.h
index 3b76850..dd3654b 100644
--- a/libide/vcs/ide-vcs.h
+++ b/libide/vcs/ide-vcs.h
@@ -43,6 +43,7 @@ struct _IdeVcsInterface
gint (*get_priority) (IdeVcs *self);
void (*changed) (IdeVcs *self);
IdeVcsConfig *(*get_config) (IdeVcs *self);
+ gchar *(*get_branch_name) (IdeVcs *self);
};
IdeBufferChangeMonitor *ide_vcs_get_buffer_change_monitor (IdeVcs *self,
@@ -61,6 +62,7 @@ gboolean ide_vcs_is_ignored (IdeVcs
gint ide_vcs_get_priority (IdeVcs *self);
void ide_vcs_emit_changed (IdeVcs *self);
IdeVcsConfig *ide_vcs_get_config (IdeVcs *self);
+gchar *ide_vcs_get_branch_name (IdeVcs *self);
G_END_DECLS
diff --git a/plugins/git/ide-git-vcs.c b/plugins/git/ide-git-vcs.c
index 0b2d4bb..1548c0f 100644
--- a/plugins/git/ide-git-vcs.c
+++ b/plugins/git/ide-git-vcs.c
@@ -346,6 +346,26 @@ ide_git_vcs_is_ignored (IdeVcs *vcs,
return ret;
}
+static gchar *
+ide_git_vcs_get_branch_name (IdeVcs *vcs)
+{
+ IdeGitVcs *self = (IdeGitVcs *)vcs;
+ GgitRef *ref;
+ gchar *ret = NULL;
+
+ g_assert (IDE_IS_GIT_VCS (self));
+
+ ref = ggit_repository_get_head (self->repository, NULL);
+
+ if (ref != NULL)
+ {
+ ret = g_strdup (ggit_ref_get_shorthand (ref));
+ g_object_unref (ref);
+ }
+
+ return ret;
+}
+
static void
ide_git_vcs_dispose (GObject *object)
{
@@ -401,6 +421,7 @@ ide_git_vcs_init_iface (IdeVcsInterface *iface)
iface->get_buffer_change_monitor = ide_git_vcs_get_buffer_change_monitor;
iface->is_ignored = ide_git_vcs_is_ignored;
iface->get_config = ide_git_vcs_get_config;
+ iface->get_branch_name = ide_git_vcs_get_branch_name;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]