[gnome-builder/wip/gtk4-port: 1250/1774] plugins/git: implement get_directory_name vfunc




commit de798e85277aebc87a3d05a29981fdbc8abdfeb7
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 31 21:59:33 2022 -0700

    plugins/git: implement get_directory_name vfunc

 src/plugins/git/gbp-git-vcs-cloner.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/src/plugins/git/gbp-git-vcs-cloner.c b/src/plugins/git/gbp-git-vcs-cloner.c
index 6ce1ffb63..60f25d721 100644
--- a/src/plugins/git/gbp-git-vcs-cloner.c
+++ b/src/plugins/git/gbp-git-vcs-cloner.c
@@ -517,6 +517,30 @@ gbp_git_vcs_cloner_list_branches_finish (IdeVcsCloner  *cloner,
   IDE_RETURN (ret);
 }
 
+static char *
+gbp_git_vcs_cloner_get_directory_name (IdeVcsCloner *cloner,
+                                       IdeVcsUri    *uri)
+{
+  g_autofree char *name = NULL;
+  const char *path;
+  char *dot;
+
+  g_assert (GBP_IS_GIT_VCS_CLONER (cloner));
+  g_assert (uri != NULL);
+
+  /* Make sure we have a path to use as a name */
+  path = ide_vcs_uri_get_path (uri);
+  if (ide_str_empty0 (path))
+    return NULL;
+
+  /* Remove trailing .git if necessary */
+  name = g_path_get_basename (path);
+  if ((dot = strrchr (name, '.')) && ide_str_equal0 (dot, ".git"))
+    *dot = 0;
+
+  return g_steal_pointer (&name);
+}
+
 static void
 vcs_cloner_iface_init (IdeVcsClonerInterface *iface)
 {
@@ -526,4 +550,5 @@ vcs_cloner_iface_init (IdeVcsClonerInterface *iface)
   iface->clone_finish = gbp_git_vcs_cloner_clone_finish;
   iface->list_branches_async = gbp_git_vcs_cloner_list_branches_async;
   iface->list_branches_finish = gbp_git_vcs_cloner_list_branches_finish;
+  iface->get_directory_name = gbp_git_vcs_cloner_get_directory_name;
 }


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