[gnome-builder/wip/libide: 143/153] libide: add ide_vcs_get_working_directory()



commit 5f53a50b3d2672436f407cb3b112e3ac1e3a8ce6
Author: Christian Hergert <christian hergert me>
Date:   Thu Feb 12 17:28:03 2015 -0800

    libide: add ide_vcs_get_working_directory()
    
    This is the directory where all of the project files exist.

 libide/directory/ide-directory-vcs.c |   39 +++++++++++++++++++++++++++++++++-
 libide/git/ide-git-vcs.c             |   17 ++++++++++++++
 libide/ide-vcs.c                     |   20 +++++++++++++++++
 libide/ide-vcs.h                     |   17 ++++++++------
 4 files changed, 85 insertions(+), 8 deletions(-)
---
diff --git a/libide/directory/ide-directory-vcs.c b/libide/directory/ide-directory-vcs.c
index 9796d59..c98aacc 100644
--- a/libide/directory/ide-directory-vcs.c
+++ b/libide/directory/ide-directory-vcs.c
@@ -6,7 +6,7 @@
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
- * 
+ *
  * This file is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
@@ -30,17 +30,51 @@
  *       are done async, and that can fail.
  */
 
+typedef struct
+{
+  GFile *working_directory;
+} IdeDirectoryVcsPrivate;
+
 #define LOAD_MAX_FILES 2000
 
 static void async_initable_iface_init (GAsyncInitableIface *iface);
 
 G_DEFINE_TYPE_EXTENDED (IdeDirectoryVcs, ide_directory_vcs, IDE_TYPE_VCS, 0,
+                        G_ADD_PRIVATE (IdeDirectoryVcs)
                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
                                                async_initable_iface_init))
 
+static GFile *
+ide_directory_vcs_get_working_directory (IdeVcs *vcs)
+{
+  IdeDirectoryVcs *self = (IdeDirectoryVcs *)vcs;
+  IdeDirectoryVcsPrivate *priv = ide_directory_vcs_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_DIRECTORY_VCS (vcs), NULL);
+
+  return priv->working_directory;
+}
+
+static void
+ide_directory_vcs_dispose (GObject *object)
+{
+  IdeDirectoryVcs *self = (IdeDirectoryVcs *)object;
+  IdeDirectoryVcsPrivate *priv = ide_directory_vcs_get_instance_private (self);
+
+  g_clear_object (&priv->working_directory);
+
+  G_OBJECT_CLASS (ide_directory_vcs_parent_class)->dispose (object);
+}
+
 static void
 ide_directory_vcs_class_init (IdeDirectoryVcsClass *klass)
 {
+  IdeVcsClass *vcs_class = IDE_VCS_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  vcs_class->get_working_directory = ide_directory_vcs_get_working_directory;
+
+  object_class->dispose = ide_directory_vcs_dispose;
 }
 
 static void
@@ -56,6 +90,7 @@ ide_directory_vcs_init_async (GAsyncInitable      *initable,
                               gpointer             user_data)
 {
   IdeDirectoryVcs *self = (IdeDirectoryVcs *)initable;
+  IdeDirectoryVcsPrivate *priv = ide_directory_vcs_get_instance_private (self);
   IdeProjectItem *root;
   IdeProjectItem *files;
   IdeProject *project;
@@ -71,6 +106,8 @@ ide_directory_vcs_init_async (GAsyncInitable      *initable,
   project = ide_context_get_project (context);
   root = ide_project_get_root (project);
 
+  priv->working_directory = g_object_ref (directory);
+
   files = g_object_new (IDE_TYPE_PROJECT_FILES,
                         "context", context,
                         "parent", root,
diff --git a/libide/git/ide-git-vcs.c b/libide/git/ide-git-vcs.c
index b9515ca..4788dde 100644
--- a/libide/git/ide-git-vcs.c
+++ b/libide/git/ide-git-vcs.c
@@ -28,6 +28,7 @@
 typedef struct
 {
   GgitRepository *repository;
+  GFile          *working_directory;
 } IdeGitVcsPrivate;
 
 static void g_async_initable_init_interface (GAsyncInitableIface *iface);
@@ -62,6 +63,17 @@ ide_git_vcs_get_repository (IdeGitVcs *vcs)
   return priv->repository;
 }
 
+static GFile *
+ide_git_vcs_get_working_directory (IdeVcs *vcs)
+{
+  IdeGitVcs *self = (IdeGitVcs *)vcs;
+  IdeGitVcsPrivate *priv = ide_git_vcs_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_GIT_VCS (self), NULL);
+
+  return priv->working_directory;
+}
+
 static void
 ide_git_vcs_finalize (GObject *object)
 {
@@ -69,6 +81,7 @@ ide_git_vcs_finalize (GObject *object)
   IdeGitVcsPrivate *priv = ide_git_vcs_get_instance_private (self);
 
   g_clear_object (&priv->repository);
+  g_clear_object (&priv->working_directory);
 
   G_OBJECT_CLASS (ide_git_vcs_parent_class)->finalize (object);
 }
@@ -96,10 +109,13 @@ static void
 ide_git_vcs_class_init (IdeGitVcsClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  IdeVcsClass *vcs_class = IDE_VCS_CLASS (klass);
 
   object_class->finalize = ide_git_vcs_finalize;
   object_class->get_property = ide_git_vcs_get_property;
 
+  vcs_class->get_working_directory = ide_git_vcs_get_working_directory;
+
   gParamSpecs [PROP_REPOSITORY] =
     g_param_spec_object ("repository",
                          _("Repository"),
@@ -286,6 +302,7 @@ ide_git_vcs_init_worker (GTask        *task,
     }
 
   priv->repository = g_object_ref (repository);
+  priv->working_directory = ggit_repository_get_workdir (priv->repository);
 
   if (!ide_git_vcs_reload_index (self, &error))
     {
diff --git a/libide/ide-vcs.c b/libide/ide-vcs.c
index 8eb64a0..c1ab027 100644
--- a/libide/ide-vcs.c
+++ b/libide/ide-vcs.c
@@ -30,6 +30,26 @@ ide_vcs_init (IdeVcs *self)
 {
 }
 
+/**
+ * ide_vcs_get_working_directory:
+ * @vcs: An #IdeVcs.
+ *
+ * Retrieves the working directory for the context. This is the root of where
+ * the project files exist.
+ *
+ * Returns: (transfer none): A #GFile.
+ */
+GFile *
+ide_vcs_get_working_directory (IdeVcs *vcs)
+{
+  g_return_val_if_fail (IDE_IS_VCS (vcs), NULL);
+
+  if (IDE_VCS_GET_CLASS (vcs)->get_working_directory)
+   return IDE_VCS_GET_CLASS (vcs)->get_working_directory (vcs);
+
+  return NULL;
+}
+
 void
 ide_vcs_new_async (IdeContext           *context,
                    int                   io_priority,
diff --git a/libide/ide-vcs.h b/libide/ide-vcs.h
index e5e0c9d..b214439 100644
--- a/libide/ide-vcs.h
+++ b/libide/ide-vcs.h
@@ -33,15 +33,18 @@ G_DECLARE_DERIVABLE_TYPE (IdeVcs, ide_vcs, IDE, VCS, IdeObject)
 struct _IdeVcsClass
 {
   IdeObjectClass parent;
+
+  GFile *(*get_working_directory) (IdeVcs *vcs);
 };
 
-void    ide_vcs_new_async  (IdeContext           *context,
-                            int                   io_priority,
-                            GCancellable         *cancellable,
-                            GAsyncReadyCallback   callback,
-                            gpointer              user_data);
-IdeVcs *ide_vcs_new_finish (GAsyncResult         *result,
-                            GError              **error);
+GFile  *ide_vcs_get_working_directory (IdeVcs *vcs);
+void    ide_vcs_new_async             (IdeContext           *context,
+                                       int                   io_priority,
+                                       GCancellable         *cancellable,
+                                       GAsyncReadyCallback   callback,
+                                       gpointer              user_data);
+IdeVcs *ide_vcs_new_finish            (GAsyncResult         *result,
+                                       GError              **error);
 
 G_END_DECLS
 


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