[gnome-builder] greeter: add gnome/gitlab/github URI prefixes



commit 94b2f9d5b7d5c5cae00c3285f07691f81e1b0529
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 20 11:19:07 2019 -0800

    greeter: add gnome/gitlab/github URI prefixes
    
    This allows cloning a URL using an expansion such as:
    
      gnome-builder --clone gnome:chergert/foobar.git
    
    and have it expand to the https URL.

 src/libide/greeter/ide-clone-surface.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/src/libide/greeter/ide-clone-surface.c b/src/libide/greeter/ide-clone-surface.c
index 7c792feac..40cffaa64 100644
--- a/src/libide/greeter/ide-clone-surface.c
+++ b/src/libide/greeter/ide-clone-surface.c
@@ -446,8 +446,29 @@ void
 ide_clone_surface_set_uri (IdeCloneSurface *self,
                            const gchar     *uri)
 {
+  static const struct {
+    const gchar *prefix;
+    const gchar *expanded;
+  } mappings[] = {
+    { "gnome:", "https://gitlab.gnome.org/"; },
+    { "gitlab:", "https://gitlab.com/"; },
+    { "github:", "https://github.com/"; },
+  };
+  g_autofree gchar *expanded = NULL;
+
   g_return_if_fail (IDE_IS_CLONE_SURFACE (self));
 
+  if (uri != NULL)
+    {
+      for (guint i = 0; i < G_N_ELEMENTS (mappings); i++)
+        {
+          const gchar *prefix = mappings[i].prefix;
+
+          if (g_str_has_prefix (uri, prefix))
+            uri = expanded = g_strdup_printf ("%s%s", mappings[i].expanded, uri + strlen (prefix));
+        }
+    }
+
   gtk_entry_set_text (self->uri_entry, uri);
 }
 


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