[gnome-builder] vcs: add ide_vcs_path_is_ignored()



commit 257db6accc5856ea24e9ecd51985f4a3f5eefb31
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 13 16:04:19 2017 -0700

    vcs: add ide_vcs_path_is_ignored()
    
    This function allows for checking if a file should be ignored
    similar to ide_vcs_is_ignored(). It's purpose is to save the
    caller from dealing with the burden of checking if a GFile
    creation needs to be relative to the project or absolute.
    
    It also is slightly faster in checking against known regexes
    for ignored globs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774977

 src/libide/vcs/ide-vcs.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++
 src/libide/vcs/ide-vcs.h |    3 ++
 2 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/vcs/ide-vcs.c b/src/libide/vcs/ide-vcs.c
index 3eed24b..7e4ffb7 100644
--- a/src/libide/vcs/ide-vcs.c
+++ b/src/libide/vcs/ide-vcs.c
@@ -82,6 +82,22 @@ ide_vcs_default_init (IdeVcsInterface *iface)
                   NULL, NULL, NULL, G_TYPE_NONE, 0);
 }
 
+/**
+ * ide_vcs_is_ignored:
+ * @self: An #IdeVcs
+ * @file: A #GFile
+ * @error: A location for a #GError, or %NULL
+ *
+ * This function will check if @file is considered an "ignored file" by
+ * the underlying Version Control System.
+ *
+ * This function is not thread-safe, it must only be called from the
+ * main thread.
+ *
+ * Returns: %TRUE if the path should be ignored.
+ *
+ * Since: 3.18
+ */
 gboolean
 ide_vcs_is_ignored (IdeVcs  *self,
                     GFile   *file,
@@ -110,6 +126,63 @@ ide_vcs_is_ignored (IdeVcs  *self,
   return FALSE;
 }
 
+/**
+ * ide_vcs_path_is_ignored:
+ * @self: An #IdeVcs
+ * @path: The path to check
+ * @error: A location for a #GError, or %NULL
+ *
+ * This function acts like ide_vcs_is_ignored() except that it
+ * allows for using a regular file-system path.
+ *
+ * It will check if the path is absolute or relative to the project
+ * directory and adjust as necessary.
+ *
+ * This function is not thread-safe, it must only be called from the
+ * main thread.
+ *
+ * Returns: %TRUE if the path should be ignored.
+ *
+ * Since: 3.28
+ */
+gboolean
+ide_vcs_path_is_ignored (IdeVcs       *self,
+                         const gchar  *path,
+                         GError      **error)
+{
+  g_return_val_if_fail (IDE_IS_VCS (self), FALSE);
+  g_return_val_if_fail (path != NULL, FALSE);
+
+  if G_LIKELY (ignored != NULL)
+    {
+      g_autofree gchar *name = g_path_get_basename (path);
+      guint len = strlen (name);
+      g_autofree gchar *reversed = g_utf8_strreverse (name, len);
+
+      for (guint i = 0; i < ignored->len; i++)
+        {
+          GPatternSpec *pattern_spec = g_ptr_array_index (ignored, i);
+
+          if (g_pattern_match (pattern_spec, len, name, reversed))
+            return TRUE;
+        }
+    }
+
+  if (IDE_VCS_GET_IFACE (self)->is_ignored)
+    {
+      g_autoptr(GFile) file = NULL;
+
+      if (g_path_is_absolute (path))
+        file = g_file_new_for_path (path);
+      else
+        file = g_file_get_child (ide_vcs_get_working_directory (self), path);
+
+      return IDE_VCS_GET_IFACE (self)->is_ignored (self, file, error);
+    }
+
+  return FALSE;
+}
+
 gint
 ide_vcs_get_priority (IdeVcs *self)
 {
diff --git a/src/libide/vcs/ide-vcs.h b/src/libide/vcs/ide-vcs.h
index 059741a..b8d61d9 100644
--- a/src/libide/vcs/ide-vcs.h
+++ b/src/libide/vcs/ide-vcs.h
@@ -59,6 +59,9 @@ IdeVcs                 *ide_vcs_new_finish                (GAsyncResult
 gboolean                ide_vcs_is_ignored                (IdeVcs               *self,
                                                            GFile                *file,
                                                            GError              **error);
+gboolean                ide_vcs_path_is_ignored           (IdeVcs               *self,
+                                                           const gchar          *path,
+                                                           GError              **error);
 gint                    ide_vcs_get_priority              (IdeVcs               *self);
 void                    ide_vcs_emit_changed              (IdeVcs               *self);
 IdeVcsConfig           *ide_vcs_get_config                (IdeVcs               *self);


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