1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * anjuta
4  * Copyright (C) Carl-Anton Ingmarsson 2009 <carlantoni@gnome.org>
5  *
6  * anjuta is free software.
7  *
8  * You may redistribute it and/or modify it under the terms of the
9  * GNU General Public License, as published by the Free Software
10  * Foundation; either version 2 of the License, or (at your option)
11  * any later version.
12  *
13  * anjuta is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with anjuta.  If not, write to:
20  * 	The Free Software Foundation, Inc.,
21  * 	51 Franklin Street, Fifth Floor
22  * 	Boston, MA  02110-1301, USA.
23  */
24 
25 #include "git-clone-command.h"
26 
27 struct _GitCloneCommandPriv
28 {
29 	gchar *url;
30 	gchar *repository_name;
31 };
32 
33 G_DEFINE_TYPE (GitCloneCommand, git_clone_command, GIT_TYPE_COMMAND);
34 
35 static guint
git_clone_command_run(AnjutaCommand * command)36 git_clone_command_run (AnjutaCommand *command)
37 {
38 	GitCloneCommand *self;
39 
40 	self = GIT_CLONE_COMMAND (command);
41 
42 	git_command_add_arg (GIT_COMMAND (self), "clone");
43 	git_command_add_arg (GIT_COMMAND (self), self->priv->url);
44 	git_command_add_arg (GIT_COMMAND (self), self->priv->repository_name);
45 
46 	return 0;
47 }
48 
49 static void
git_clone_command_init(GitCloneCommand * self)50 git_clone_command_init (GitCloneCommand *self)
51 {
52 	self->priv = g_new0 (GitCloneCommandPriv, 1);
53 }
54 
55 static void
git_clone_command_finalize(GObject * object)56 git_clone_command_finalize (GObject *object)
57 {
58 	GitCloneCommand *self;
59 
60 	self = GIT_CLONE_COMMAND (object);
61 
62 	g_free (self->priv->url);
63 	g_free (self->priv->repository_name);
64 	g_free (self->priv);
65 
66 	G_OBJECT_CLASS (git_clone_command_parent_class)->finalize (object);
67 }
68 
69 static void
git_clone_command_class_init(GitCloneCommandClass * klass)70 git_clone_command_class_init (GitCloneCommandClass *klass)
71 {
72 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 	GitCommandClass *parent_class = GIT_COMMAND_CLASS (klass);
74 	AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
75 
76 	object_class->finalize = git_clone_command_finalize;
77 	parent_class->output_handler = git_command_send_output_to_info;
78 	command_class->run = git_clone_command_run;
79 }
80 
81 GitCloneCommand *
git_clone_command_new(const gchar * working_directory,const gchar * url,const gchar * repository_name)82 git_clone_command_new (const gchar *working_directory, const gchar *url,
83                        const gchar *repository_name)
84 {
85 	GitCloneCommand *self;
86 
87 	self = g_object_new (GIT_TYPE_CLONE_COMMAND,
88 	                     "working-directory", working_directory,
89 	                     "single-line-output", TRUE,
90 	                     NULL);
91 
92 	self->priv->url = g_strdup (url);
93 	self->priv->repository_name = g_strdup (repository_name);
94 
95 	return self;
96 }