1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
5 *
6 * Portions based on the original Subversion plugin
7 * Copyright (C) Johannes Schmid 2005
8 *
9 * anjuta is free software.
10 *
11 * You may redistribute it and/or modify it under the terms of the
12 * GNU General Public License, as published by the Free Software
13 * Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 * anjuta is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with anjuta. If not, write to:
23 * The Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor
25 * Boston, MA 02110-1301, USA.
26 */
27
28 #include "svn-add-command.h"
29
30 struct _SvnAddCommandPriv
31 {
32 GList *paths;
33 gboolean force;
34 gboolean recursive;
35 };
36
37 G_DEFINE_TYPE (SvnAddCommand, svn_add_command, SVN_TYPE_COMMAND);
38
39 static void
svn_add_command_init(SvnAddCommand * self)40 svn_add_command_init (SvnAddCommand *self)
41 {
42 self->priv = g_new0 (SvnAddCommandPriv, 1);
43 }
44
45 static void
svn_add_command_finalize(GObject * object)46 svn_add_command_finalize (GObject *object)
47 {
48 SvnAddCommand *self;
49
50 self = SVN_ADD_COMMAND (object);
51
52 svn_command_free_path_list (self->priv->paths);
53 g_free (self->priv);
54
55 G_OBJECT_CLASS (svn_add_command_parent_class)->finalize (object);
56 }
57
58 static guint
svn_add_command_run(AnjutaCommand * command)59 svn_add_command_run (AnjutaCommand *command)
60 {
61 SvnAddCommand *self;
62 SvnCommand *svn_command;
63 GList *current_path;
64 svn_error_t *error;
65
66 self = SVN_ADD_COMMAND (command);
67 svn_command = SVN_COMMAND (command);
68 current_path = self->priv->paths;
69
70 while (current_path)
71 {
72 error = svn_client_add2 (current_path->data,
73 self->priv->force,
74 self->priv->recursive,
75 svn_command_get_client_context (svn_command),
76 svn_command_get_pool (svn_command));
77
78 if (error)
79 {
80 svn_command_set_error (svn_command, error);
81 return 1;
82 }
83
84 current_path = g_list_next (current_path);
85 }
86
87 return 0;
88 }
89
90 static void
svn_add_command_class_init(SvnAddCommandClass * klass)91 svn_add_command_class_init (SvnAddCommandClass *klass)
92 {
93 GObjectClass *object_class = G_OBJECT_CLASS (klass);
94 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
95
96 object_class->finalize = svn_add_command_finalize;
97 command_class->run = svn_add_command_run;
98 }
99
100
101 SvnAddCommand *
svn_add_command_new_path(const gchar * path,gboolean force,gboolean recursive)102 svn_add_command_new_path (const gchar *path, gboolean force, gboolean recursive)
103 {
104 SvnAddCommand *self;
105
106 self = g_object_new (SVN_TYPE_ADD_COMMAND, NULL);
107 self->priv->paths = g_list_append (self->priv->paths,
108 svn_command_make_canonical_path (SVN_COMMAND (self),
109 path));
110 self->priv->force = force;
111 self->priv->recursive = recursive;
112
113 return self;
114 }
115
116 SvnAddCommand *
svn_add_command_new_list(GList * paths,gboolean force,gboolean recursive)117 svn_add_command_new_list (GList *paths, gboolean force, gboolean recursive)
118 {
119 SvnAddCommand *self;
120 GList *current_path;
121
122 self = g_object_new (SVN_TYPE_ADD_COMMAND, NULL);
123 current_path = paths;
124
125 while (current_path)
126 {
127 self->priv->paths = g_list_append (self->priv->paths,
128 svn_command_make_canonical_path (SVN_COMMAND (self),
129 current_path->data));
130 current_path = g_list_next (current_path);
131 }
132
133 self->priv->force = force;
134 self->priv->recursive = recursive;
135
136 return self;
137 }
138
139 void
svn_add_command_destroy(SvnAddCommand * self)140 svn_add_command_destroy (SvnAddCommand *self)
141 {
142 g_object_unref (self);
143 }
144