[gnome-builder] project: remove IdeProjectFile and IdeProjectFiles



commit f05a109ae05ddc920cfc7be40595a1a281173de0
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jan 13 03:23:15 2018 -0800

    project: remove IdeProjectFile and IdeProjectFiles
    
    This wasn't really being used and certainly wont be long-term. Lets drop
    it now. This ports the few places that used that code to using the
    ide_file_new_for_path() which can do caching and proper relative path
    resolution without the IdeProjectFiles unpurgeable cache.

 src/libide/buildsystem/ide-build-pipeline.c       |   1 +
 src/libide/directory/ide-directory-build-system.c |   1 -
 src/libide/files/ide-file.c                       |  10 +-
 src/libide/ide-context.c                          |  10 +-
 src/libide/ide-types.h                            |   4 -
 src/libide/ide.h                                  |   2 -
 src/libide/projects/ide-project-file.c            | 287 ----------------------
 src/libide/projects/ide-project-file.h            |  50 ----
 src/libide/projects/ide-project-files.c           | 276 ---------------------
 src/libide/projects/ide-project-files.h           |  48 ----
 src/libide/projects/ide-project.c                 | 149 -----------
 src/libide/projects/ide-project.h                 |  12 -
 src/libide/projects/meson.build                   |   4 -
 src/tests/test-ide-buffer-manager.c               |  13 +-
 src/tests/test-ide-buffer.c                       |   6 +-
 src/tests/test-ide-indenter.c                     |  17 +-
 src/tests/test-vim.c                              |   8 +-
 17 files changed, 28 insertions(+), 870 deletions(-)
---
diff --git a/src/libide/buildsystem/ide-build-pipeline.c b/src/libide/buildsystem/ide-build-pipeline.c
index 103aa3bcf..054c4b9b1 100644
--- a/src/libide/buildsystem/ide-build-pipeline.c
+++ b/src/libide/buildsystem/ide-build-pipeline.c
@@ -42,6 +42,7 @@
 #include "diagnostics/ide-diagnostic.h"
 #include "diagnostics/ide-source-location.h"
 #include "diagnostics/ide-source-range.h"
+#include "files/ide-file.h"
 #include "plugins/ide-extension-util.h"
 #include "projects/ide-project.h"
 #include "runtimes/ide-runtime.h"
diff --git a/src/libide/directory/ide-directory-build-system.c 
b/src/libide/directory/ide-directory-build-system.c
index 2148890b5..6c67c8502 100644
--- a/src/libide/directory/ide-directory-build-system.c
+++ b/src/libide/directory/ide-directory-build-system.c
@@ -23,7 +23,6 @@
 #include "ide-context.h"
 
 #include "directory/ide-directory-build-system.h"
-#include "projects/ide-project-file.h"
 #include "projects/ide-project-item.h"
 #include "projects/ide-project.h"
 
diff --git a/src/libide/files/ide-file.c b/src/libide/files/ide-file.c
index 1f7eb0457..3a31b5a18 100644
--- a/src/libide/files/ide-file.c
+++ b/src/libide/files/ide-file.c
@@ -733,7 +733,15 @@ ide_file_new_for_path (IdeContext  *context,
   g_return_val_if_fail (!context || IDE_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (path != NULL, NULL);
 
-  file = g_file_new_for_path (path);
+  if (context != NULL && !g_path_is_absolute (path))
+    {
+      IdeVcs *vcs = ide_context_get_vcs (context);
+      GFile *workdir = ide_vcs_get_working_directory (vcs);
+
+      file = g_file_get_child (workdir, path);
+    }
+  else
+    file = g_file_new_for_path (path);
 
   return ide_file_new (context, file);
 }
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index 983bf1353..2667ccef4 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -44,7 +44,6 @@
 #include "doap/ide-doap.h"
 #include "documentation/ide-documentation.h"
 #include "plugins/ide-extension-util.h"
-#include "projects/ide-project-files.h"
 #include "projects/ide-project-item.h"
 #include "projects/ide-project.h"
 #include "projects/ide-recent-projects.h"
@@ -2129,11 +2128,12 @@ restore_in_idle (gpointer user_data)
   IdeContext *self;
   GPtrArray *ar;
   GFile *file;
-  IdeWorkbenchOpenFlags flags;
 
   g_assert (G_IS_TASK (task));
 
   self = g_task_get_source_object (task);
+  g_assert (IDE_IS_CONTEXT (self));
+
   ar = g_task_get_task_data (task);
 
   if (ar == NULL || ar->len == 0)
@@ -2148,15 +2148,13 @@ restore_in_idle (gpointer user_data)
 
   uf = g_ptr_array_index (ar, ar->len - 1);
   file = ide_unsaved_file_get_file (uf);
-  ifile = ide_project_get_project_file (self->project, file);
+  ifile = ide_file_new (self, file);
   g_ptr_array_remove_index (ar, ar->len - 1);
 
-  flags = IDE_WORKBENCH_OPEN_FLAGS_BACKGROUND;
-
   ide_buffer_manager_load_file_async (self->buffer_manager,
                                       ifile,
                                       FALSE,
-                                      flags,
+                                      IDE_WORKBENCH_OPEN_FLAGS_BACKGROUND,
                                       NULL,
                                       g_task_get_cancellable (task),
                                       ide_context_restore__load_file_cb,
diff --git a/src/libide/ide-types.h b/src/libide/ide-types.h
index 5eca8a3b9..541f4aa28 100644
--- a/src/libide/ide-types.h
+++ b/src/libide/ide-types.h
@@ -91,10 +91,6 @@ typedef struct _IdeProjectItem                 IdeProjectItem;
 
 typedef struct _IdeProjectEdit                 IdeProjectEdit;
 
-typedef struct _IdeProjectFile                 IdeProjectFile;
-
-typedef struct _IdeProjectFiles                IdeProjectFiles;
-
 typedef struct _IdeRenameProvider              IdeRenameProvider;
 
 typedef struct _IdeRunner                      IdeRunner;
diff --git a/src/libide/ide.h b/src/libide/ide.h
index 37a320a5d..1b25742d2 100644
--- a/src/libide/ide.h
+++ b/src/libide/ide.h
@@ -127,8 +127,6 @@ G_BEGIN_DECLS
 #include "preferences/ide-preferences-perspective.h"
 #include "preferences/ide-preferences-window.h"
 #include "projects/ide-project-edit.h"
-#include "projects/ide-project-file.h"
-#include "projects/ide-project-files.h"
 #include "projects/ide-project-info.h"
 #include "projects/ide-project-item.h"
 #include "projects/ide-project.h"
diff --git a/src/libide/projects/ide-project.c b/src/libide/projects/ide-project.c
index 4cf934c7b..b57d4c2f2 100644
--- a/src/libide/projects/ide-project.c
+++ b/src/libide/projects/ide-project.c
@@ -24,7 +24,6 @@
 #include "ide-debug.h"
 
 #include "files/ide-file.h"
-#include "projects/ide-project-files.h"
 #include "projects/ide-project-item.h"
 #include "projects/ide-project.h"
 #include "subprocess/ide-subprocess.h"
@@ -198,154 +197,6 @@ ide_project_set_root (IdeProject     *self,
     g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ROOT]);
 }
 
-/**
- * ide_project_get_files:
- * @self: an #IdeProject.
- *
- * Gets the #IdeProjectFiles instance within the project tree.
- * If it has not yet been loaded, %NULL is returned.
- *
- * Returns: (transfer none) (nullable): An #IdeProjectFiles or %NULL.
- */
-IdeProjectFiles *
-ide_project_get_files (IdeProject *self)
-{
-  GSequenceIter *iter;
-  GSequence *children;
-  IdeProjectItem *root;
-
-  g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
-
-  root = ide_project_get_root (self);
-  children = ide_project_item_get_children (root);
-
-  if (children == NULL)
-    return NULL;
-
-  for (iter = g_sequence_get_begin_iter (children);
-       !g_sequence_iter_is_end (iter);
-       iter = g_sequence_iter_next (iter))
-    {
-      IdeProjectItem *item = g_sequence_get (iter);
-
-      if (IDE_IS_PROJECT_FILES (item))
-        return IDE_PROJECT_FILES (item);
-    }
-
-  return NULL;
-}
-
-/**
- * ide_project_get_file_for_path:
- * @path: A relative path from the project root.
- *
- * Retrieves an #IdeFile for the path specified. #IdeFile provides access to
- * language specific features via ide_file_get_language().
- *
- * You must hold the reader lock while calling this function. See
- * ide_project_reader_lock() and ide_project_reader_unlock() for more
- * information.
- *
- * Returns: (transfer full) (nullable): An #IdeFile or %NULL if no matching
- *   file could be found.
- */
-IdeFile *
-ide_project_get_file_for_path (IdeProject  *self,
-                               const gchar *path)
-{
-  IdeProjectFiles *files;
-  IdeFile *file = NULL;
-
-  g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
-  g_return_val_if_fail (path, NULL);
-
-  ide_project_reader_lock (self);
-
-  files = ide_project_get_files (self);
-  if (files != NULL)
-    file = ide_project_files_get_file_for_path (files, path);
-
-  ide_project_reader_unlock (self);
-
-  if (!file)
-    {
-      IdeContext *context;
-      IdeVcs *vcs;
-      GFile *workdir;
-      g_autoptr(GFile) gfile = NULL;
-
-      /*
-       * Okay, we couldn't find an existing item that matches this path, so let's
-       * synthesize one (but not add it to the tree). This could be hit in common
-       * cases like new files that are not yet added to the project.
-       */
-      context = ide_object_get_context (IDE_OBJECT (self));
-      g_assert (IDE_IS_CONTEXT (context));
-      vcs = ide_context_get_vcs (context);
-      workdir = ide_vcs_get_working_directory (vcs);
-      gfile = g_file_get_child (workdir, path);
-      file = g_object_new (IDE_TYPE_FILE,
-                           "context", context,
-                           "path", path,
-                           "file", gfile,
-                           NULL);
-    }
-
-  return file;
-}
-
-/**
- * ide_project_get_project_file:
- * @self: an #IdeProject.
- * @gfile: a #GFile.
- *
- * Gets a new #IdeFile representing @gfile.
- *
- * Returns: (transfer full): An #IdeFile.
- */
-IdeFile *
-ide_project_get_project_file (IdeProject *self,
-                              GFile      *gfile)
-{
-  g_autofree gchar *relpath = NULL;
-  IdeContext *context;
-  IdeVcs *vcs;
-  GFile *workdir;
-
-  g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
-  g_return_val_if_fail (G_IS_FILE (gfile), NULL);
-
-  context = ide_object_get_context (IDE_OBJECT (self));
-  vcs = ide_context_get_vcs (context);
-  workdir = ide_vcs_get_working_directory (vcs);
-
-  relpath = g_file_get_relative_path (workdir, gfile);
-  if (relpath)
-    return ide_project_get_file_for_path (self, relpath);
-
-  return g_object_new (IDE_TYPE_FILE,
-                       "context", context,
-                       "path", g_file_get_path (gfile),
-                       "file", gfile,
-                       NULL);
-}
-
-void
-ide_project_add_file (IdeProject     *self,
-                      IdeProjectFile *file)
-{
-  IdeProjectFiles *files;
-
-  g_return_if_fail (IDE_IS_PROJECT (self));
-  g_return_if_fail (IDE_IS_PROJECT_FILE (file));
-
-
-  ide_project_writer_lock (self);
-  files = ide_project_get_files (self);
-  ide_project_files_add_file (files, file);
-  ide_project_writer_unlock (self);
-}
-
 static void
 ide_project_finalize (GObject *object)
 {
diff --git a/src/libide/projects/ide-project.h b/src/libide/projects/ide-project.h
index 3c05a2351..737aa4f31 100644
--- a/src/libide/projects/ide-project.h
+++ b/src/libide/projects/ide-project.h
@@ -21,7 +21,6 @@
 #include "ide-version-macros.h"
 
 #include "ide-object.h"
-#include "projects/ide-project-files.h"
 
 G_BEGIN_DECLS
 
@@ -38,12 +37,6 @@ const gchar     *ide_project_get_name           (IdeProject           *self);
 IDE_AVAILABLE_IN_ALL
 const gchar     *ide_project_get_id             (IdeProject           *self);
 IDE_AVAILABLE_IN_ALL
-IdeFile         *ide_project_get_file_for_path  (IdeProject           *self,
-                                                 const gchar          *path);
-IDE_AVAILABLE_IN_ALL
-IdeFile         *ide_project_get_project_file   (IdeProject           *self,
-                                                 GFile                *gfile);
-IDE_AVAILABLE_IN_ALL
 void             ide_project_reader_lock        (IdeProject           *self);
 IDE_AVAILABLE_IN_ALL
 void             ide_project_reader_unlock      (IdeProject           *self);
@@ -52,11 +45,6 @@ void             ide_project_writer_lock        (IdeProject           *self);
 IDE_AVAILABLE_IN_ALL
 void             ide_project_writer_unlock      (IdeProject           *self);
 IDE_AVAILABLE_IN_ALL
-void             ide_project_add_file           (IdeProject           *self,
-                                                 IdeProjectFile       *file);
-IDE_AVAILABLE_IN_ALL
-IdeProjectFiles *ide_project_get_files          (IdeProject           *self);
-IDE_AVAILABLE_IN_ALL
 void             ide_project_rename_file_async  (IdeProject           *self,
                                                  GFile                *orig_file,
                                                  GFile                *new_file,
diff --git a/src/libide/projects/meson.build b/src/libide/projects/meson.build
index d5fc351c8..aa68a2029 100644
--- a/src/libide/projects/meson.build
+++ b/src/libide/projects/meson.build
@@ -1,7 +1,5 @@
 projects_headers = [
   'ide-project-edit.h',
-  'ide-project-file.h',
-  'ide-project-files.h',
   'ide-project-info.h',
   'ide-project-item.h',
   'ide-project.h',
@@ -10,8 +8,6 @@ projects_headers = [
 
 projects_sources = [
   'ide-project-edit.c',
-  'ide-project-file.c',
-  'ide-project-files.c',
   'ide-project-info.c',
   'ide-project-item.c',
   'ide-project.c',
diff --git a/src/tests/test-ide-buffer-manager.c b/src/tests/test-ide-buffer-manager.c
index 52d590337..8a1f13750 100644
--- a/src/tests/test-ide-buffer-manager.c
+++ b/src/tests/test-ide-buffer-manager.c
@@ -73,10 +73,10 @@ test_buffer_manager_basic_cb2 (GObject      *object,
   IdeBufferManager *buffer_manager = (IdeBufferManager *)object;
   g_autoptr(IdeProgress) progress = NULL;
   g_autoptr(GTask) task = user_data;
+  g_autoptr(GFile) gfile = NULL;
+  g_autoptr(IdeFile) file = NULL;
   IdeContext *context;
-  IdeProject *project;
   GtkTextIter begin, end;
-  IdeFile *file;
   g_autofree gchar *text = NULL;
   GError *error = NULL;
   int tmpfd;
@@ -96,8 +96,8 @@ test_buffer_manager_basic_cb2 (GObject      *object,
   g_assert_cmpint (-1, !=, tmpfd);
   close (tmpfd); /* not secure, but okay for tests */
 
-  project = ide_context_get_project (context);
-  file = ide_project_get_file_for_path (project, tmpfilename);
+  gfile = g_file_new_for_path (tmpfilename);
+  file = ide_file_new (context, gfile);
 
   ide_buffer_manager_save_file_async (buffer_manager,
                                       buffer,
@@ -120,7 +120,6 @@ test_buffer_manager_basic_cb1 (GObject      *object,
   g_autoptr(IdeProgress) progress = NULL;
   g_autoptr(IdeContext) context = NULL;
   IdeBufferManager *buffer_manager;
-  IdeProject *project;
   g_autofree gchar *path = NULL;
   GError *error = NULL;
 
@@ -132,10 +131,8 @@ test_buffer_manager_basic_cb1 (GObject      *object,
   g_signal_connect (buffer_manager, "save-buffer", G_CALLBACK (save_buffer_cb), task);
   g_signal_connect (buffer_manager, "buffer-loaded", G_CALLBACK (buffer_loaded_cb), task);
 
-  project = ide_context_get_project (context);
-
   path = g_build_filename (TEST_DATA_DIR, "project1", "configure.ac", NULL);
-  file = ide_project_get_file_for_path (project, path);
+  file = ide_file_new_for_path (context, path);
 
   ide_buffer_manager_load_file_async (buffer_manager,
                                       file,
diff --git a/src/tests/test-ide-buffer.c b/src/tests/test-ide-buffer.c
index a515b3422..2b1823cd1 100644
--- a/src/tests/test-ide-buffer.c
+++ b/src/tests/test-ide-buffer.c
@@ -55,9 +55,8 @@ test_buffer_basic_cb1 (GObject      *object,
   g_autoptr(GTask) task = user_data;
   g_autoptr(IdeFile) file = NULL;
   g_autoptr(IdeContext) context = NULL;
+  g_autoptr(GError) error = NULL;
   IdeBufferManager *manager;
-  IdeProject *project;
-  GError *error = NULL;
 
   IDE_ENTRY;
 
@@ -67,8 +66,7 @@ test_buffer_basic_cb1 (GObject      *object,
   g_assert (IDE_IS_CONTEXT (context));
 
   manager = ide_context_get_buffer_manager (context);
-  project = ide_context_get_project (context);
-  file = ide_project_get_file_for_path (project, "test-ide-buffer.tmp");
+  file = ide_file_new_for_path (context, "test-ide-buffer.tmp");
 
   ide_buffer_manager_load_file_async (manager,
                                       file,
diff --git a/src/tests/test-ide-indenter.c b/src/tests/test-ide-indenter.c
index 2f6e8af4c..8c013d240 100644
--- a/src/tests/test-ide-indenter.c
+++ b/src/tests/test-ide-indenter.c
@@ -44,24 +44,20 @@ new_context_cb (GObject      *object,
 {
   g_autoptr(GTask) task = user_data;
   g_autoptr(IdeContext) context = NULL;
+  g_autoptr(GError) error = NULL;
+  GtkSourceCompletion *completion;
   GtkWidget *window;
   GtkWidget *widget;
-  IdeBuffer *buffer;
-  GtkSourceCompletion *completion;
-  IdeProject *project;
-  IdeFile *file;
-  GError *error = NULL;
 
   context = ide_context_new_finish (result, &error);
   g_assert_no_error (error);
   g_assert (context != NULL);
   g_assert (IDE_IS_CONTEXT (context));
 
-  project = ide_context_get_project (context);
-
-  for (gint i = 0; indent_tests [i].path; i++)
+  for (guint i = 0; indent_tests [i].path; i++)
     {
-      file = ide_project_get_file_for_path (project, indent_tests [i].path);
+      g_autoptr(IdeFile) file = ide_file_new_for_path (context, indent_tests [i].path);
+      g_autoptr(IdeBuffer) buffer = NULL;
 
       buffer = g_object_new (IDE_TYPE_BUFFER,
                              "context", context,
@@ -85,9 +81,6 @@ new_context_cb (GObject      *object,
         gtk_main_iteration ();
 
       indent_tests [i].func (context, widget);
-
-      g_object_unref (buffer);
-      g_object_unref (file);
     }
 
   g_task_return_boolean (task, TRUE);
diff --git a/src/tests/test-vim.c b/src/tests/test-vim.c
index 9f100e565..64c5d0ecb 100644
--- a/src/tests/test-vim.c
+++ b/src/tests/test-vim.c
@@ -43,25 +43,21 @@ new_context_cb (GObject      *object,
                 gpointer      user_data)
 {
   g_autoptr(GTask) task = user_data;
+  g_autoptr(GError) error = NULL;
   GtkWidget *window;
   GtkWidget *widget;
   IdeBuffer *buffer;
   GtkSourceCompletion *completion;
   IdeContext *context;
-  IdeProject *project;
-  IdeFile *file;
-  GError *error = NULL;
 
   context = ide_context_new_finish (result, &error);
   g_assert_no_error (error);
   g_assert (context != NULL);
   g_assert (IDE_IS_CONTEXT (context));
 
-  project = ide_context_get_project (context);
-
   for (gint i = 0; vim_tests [i].path; i++)
     {
-      file = ide_project_get_file_for_path (project, vim_tests [i].path);
+      g_autoptr(IdeFile) file = ide_file_new_for_path (context, vim_tests [i].path);
 
       buffer = g_object_new (IDE_TYPE_BUFFER,
                              "context", context,


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