[giggle] Implement clone command



commit 31627c2a8b8c09e5978e2f798faaafe729205a1d
Author: Florian Müllner <fmuellner src gnome org>
Date:   Fri Jan 22 20:50:08 2010 +0100

    Implement clone command
    
    While this implementation does work, it is somehow limited by the
    current GitJob implementation - e.g. being a potentially time intensive
    operation, it would be nice to be able to pop up a good progress
    indicator in the interface.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=608267

 libgiggle-git/Makefile.am        |    2 +
 libgiggle-git/giggle-git-clone.c |  190 ++++++++++++++++++++++++++++++++++++++
 libgiggle-git/giggle-git-clone.h |   60 ++++++++++++
 3 files changed, 252 insertions(+), 0 deletions(-)
---
diff --git a/libgiggle-git/Makefile.am b/libgiggle-git/Makefile.am
index 12aa684..4014359 100644
--- a/libgiggle-git/Makefile.am
+++ b/libgiggle-git/Makefile.am
@@ -15,6 +15,7 @@ libgiggle_git_h_files =  \
 	giggle-git-authors.h \
 	giggle-git-blame.h \
 	giggle-git-cat-file.h \
+	giggle-git-clone.h \
 	giggle-git-commit.h \
 	giggle-git-config.h \
 	giggle-git-config-read.h \
@@ -39,6 +40,7 @@ libgiggle_git_la_SOURCES = \
 	giggle-git-authors.c \
 	giggle-git-blame.c \
 	giggle-git-cat-file.c \
+	giggle-git-clone.c \
 	giggle-git-commit.c \
 	giggle-git-config.c \
 	giggle-git-config-read.c \
diff --git a/libgiggle-git/giggle-git-clone.c b/libgiggle-git/giggle-git-clone.c
new file mode 100644
index 0000000..3f4924a
--- /dev/null
+++ b/libgiggle-git/giggle-git-clone.c
@@ -0,0 +1,190 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2010 Florian Müllner
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "giggle-git-clone.h"
+
+struct GiggleGitClonePrivate {
+	gchar *repo;
+	gchar *directory;
+};
+
+static void     git_clone_finalize            (GObject         *object);
+static void     git_clone_get_property        (GObject         *object,
+                                               guint            param_id,
+                                               GValue          *value,
+                                               GParamSpec      *pspec);
+static void     git_clone_set_property        (GObject         *object,
+                                               guint            param_id,
+                                               const GValue    *value,
+                                               GParamSpec      *pspec);
+
+static gboolean git_clone_get_command_line    (GiggleJob       *job,
+                                               gchar          **command_line);
+
+
+G_DEFINE_TYPE (GiggleGitClone, giggle_git_clone, GIGGLE_TYPE_JOB)
+
+
+enum {
+	PROP_0,
+	PROP_REPO,
+	PROP_DIR
+};
+
+static void
+giggle_git_clone_class_init (GiggleGitCloneClass *class)
+{
+	GObjectClass   *object_class = G_OBJECT_CLASS (class);
+	GiggleJobClass *job_class    = GIGGLE_JOB_CLASS (class);
+
+	object_class->finalize     = git_clone_finalize;
+	object_class->get_property = git_clone_get_property;
+	object_class->set_property = git_clone_set_property;
+
+	job_class->get_command_line = git_clone_get_command_line;
+
+	g_object_class_install_property (object_class,
+	                                 PROP_REPO,
+	                                 g_param_spec_string ("repo",
+	                                                      "Repo",
+	                                                      "Cloned repository",
+	                                                      NULL,
+	                                                      G_PARAM_READWRITE));
+
+	g_object_class_install_property (object_class,
+	                                 PROP_DIR,
+	                                 g_param_spec_string ("directory",
+	                                                      "Directory",
+	                                                      "Directory for clone",
+	                                                      NULL,
+	                                                      G_PARAM_READWRITE));
+
+	g_type_class_add_private (object_class, sizeof (GiggleGitClonePrivate));
+}
+
+static void
+giggle_git_clone_init (GiggleGitClone *clone)
+{
+	clone->priv = G_TYPE_INSTANCE_GET_PRIVATE (clone,
+						   GIGGLE_TYPE_GIT_CLONE,
+						   GiggleGitClonePrivate);
+}
+
+static void
+git_clone_finalize (GObject *object)
+{
+	GiggleGitClonePrivate *priv;
+
+	priv = GIGGLE_GIT_CLONE (object)->priv;
+
+	g_free (priv->repo);
+
+	G_OBJECT_CLASS (giggle_git_clone_parent_class)->finalize (object);
+}
+
+static void
+git_clone_get_property (GObject    *object,
+                        guint       param_id,
+                        GValue     *value,
+                        GParamSpec *pspec)
+{
+	GiggleGitClonePrivate *priv;
+
+	priv = GIGGLE_GIT_CLONE (object)->priv;
+
+	switch (param_id) {
+	case PROP_REPO:
+		g_value_set_string (value, priv->repo);
+		break;
+	case PROP_DIR:
+		g_value_set_string (value, priv->directory);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	}
+}
+
+static void
+git_clone_set_property (GObject      *object,
+                        guint         param_id,
+                        const GValue *value,
+                        GParamSpec   *pspec)
+{
+	GiggleGitClonePrivate *priv;
+
+	priv = GIGGLE_GIT_CLONE (object)->priv;
+
+	switch (param_id) {
+	case PROP_REPO:
+		priv->repo = g_value_dup_string (value);
+		break;
+	case PROP_DIR:
+		priv->directory = g_value_dup_string (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	}
+}
+
+static gboolean
+git_clone_get_command_line (GiggleJob *job, gchar **command_line)
+{
+	GiggleGitClonePrivate *priv;
+	GString             *str;
+
+	priv = GIGGLE_GIT_CLONE (job)->priv;
+
+	g_return_val_if_fail (priv->repo != NULL, FALSE);
+	str = g_string_new (GIT_COMMAND " clone  ");
+
+	g_string_append_printf (str, "\"%s\" \"%s\"",
+	                        priv->repo, priv->directory);
+
+	*command_line = g_string_free (str, FALSE);
+	return TRUE;
+}
+
+GiggleJob *
+giggle_git_clone_new (const gchar *repo, const gchar *directory)
+{
+	return g_object_new (GIGGLE_TYPE_GIT_CLONE,
+			     "repo", repo,
+	                     "directory", directory,
+			     NULL);
+}
+
+const gchar *
+giggle_git_clone_get_directory (GiggleGitClone *clone)
+{
+	g_return_val_if_fail (GIGGLE_IS_GIT_CLONE (clone), NULL);
+
+	return clone->priv->directory;
+}
+
+const gchar *
+giggle_git_clone_get_repo (GiggleGitClone *clone)
+{
+	g_return_val_if_fail (GIGGLE_IS_GIT_CLONE (clone), NULL);
+
+	return clone->priv->repo;
+}
diff --git a/libgiggle-git/giggle-git-clone.h b/libgiggle-git/giggle-git-clone.h
new file mode 100644
index 0000000..29dce10
--- /dev/null
+++ b/libgiggle-git/giggle-git-clone.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2010 Florian Müllner
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GIGGLE_GIT_CLONE_H__
+#define __GIGGLE_GIT_CLONE_H__
+
+#include <libgiggle/giggle-job.h>
+
+G_BEGIN_DECLS
+
+#define GIGGLE_TYPE_GIT_CLONE            (giggle_git_clone_get_type ())
+#define GIGGLE_GIT_CLONE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIGGLE_TYPE_GIT_CLONE, GiggleGitClone))
+#define GIGGLE_GIT_CLONE_CLASS(klass)	  (G_TYPE_CHECK_CLASS_CAST ((klass), GIGGLE_TYPE_GIT_CLONE, GiggleGitCloneClass))
+#define GIGGLE_IS_GIT_CLONE(obj)	  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIGGLE_TYPE_GIT_CLONE))
+#define GIGGLE_IS_GIT_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIGGLE_TYPE_GIT_CLONE))
+#define GIGGLE_GIT_CLONE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIGGLE_TYPE_GIT_CLONE, GiggleGitCloneClass))
+
+typedef struct GiggleGitClone        GiggleGitClone;
+typedef struct GiggleGitCloneClass   GiggleGitCloneClass;
+typedef struct GiggleGitClonePrivate GiggleGitClonePrivate;
+
+
+struct GiggleGitClone {
+	GiggleJob parent;
+
+	/* <private> */
+	GiggleGitClonePrivate *priv;
+};
+
+struct GiggleGitCloneClass {
+	GiggleJobClass parent_class;
+};
+
+GType        giggle_git_clone_get_type      (void);
+
+GiggleJob   *giggle_git_clone_new           (const gchar *repo,
+                                             const gchar *directory);
+const gchar *giggle_git_clone_get_directory (GiggleGitClone *clone);
+const gchar *giggle_git_clone_get_repo      (GiggleGitClone *clone);
+
+G_END_DECLS
+
+#endif /* __GIGGLE_GIT_CLONE_H__ */



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