2008-02-11 Johannes Schmid <jhs@gnome.org>
[anjuta-git-plugin.git] / plugins / subversion / svn-commit-command.c
blob99b10805c11e97d300765901e72868524500eab4
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>
6 * Portions based on the original Subversion plugin
7 * Copyright (C) Johannes Schmid 2005
8 *
9 * anjuta is free software.
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.
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.
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.
28 #include "svn-commit-command.h"
30 struct _SvnCommitCommandPriv
32 GList *paths;
33 gchar *log_message;
34 gboolean recursive;
37 G_DEFINE_TYPE (SvnCommitCommand, svn_commit_command, SVN_TYPE_COMMAND);
39 static svn_error_t*
40 on_log_callback (const char **log_msg,
41 const char **tmp_file,
42 apr_array_header_t *commit_items,
43 void *baton,
44 apr_pool_t *pool)
47 SvnCommitCommand *self;
49 self = SVN_COMMIT_COMMAND (baton);
51 *log_msg = self->priv->log_message;
52 *tmp_file = NULL;
54 return SVN_NO_ERROR;
57 static void
58 svn_commit_command_init (SvnCommitCommand *self)
60 svn_client_ctx_t *client_context;
62 self->priv = g_new0 (SvnCommitCommandPriv, 1);
63 client_context = svn_command_get_client_context (SVN_COMMAND (self));
65 client_context->log_msg_func = on_log_callback;
66 client_context->log_msg_baton = self;
70 static void
71 svn_commit_command_finalize (GObject *object)
73 SvnCommitCommand *self;
75 self = SVN_COMMIT_COMMAND (object);
77 svn_command_free_path_list (self->priv->paths);
78 g_free (self->priv->log_message);
79 g_free (self->priv);
81 G_OBJECT_CLASS (svn_commit_command_parent_class)->finalize (object);
84 static guint
85 svn_commit_command_run (AnjutaCommand *command)
87 SvnCommitCommand *self;
88 SvnCommand *svn_command;
89 GList *current_path;
90 apr_array_header_t *commit_paths;
91 gchar *revision_message;
92 svn_error_t *error;
93 svn_commit_info_t *commit_info;
95 self = SVN_COMMIT_COMMAND (command);
96 svn_command = SVN_COMMAND (command);
97 current_path = self->priv->paths;
98 commit_paths = apr_array_make (svn_command_get_pool (svn_command),
99 g_list_length (self->priv->paths),
100 sizeof (char *));
102 while (current_path)
104 /* I just copied this so don't blame me... */
105 (*((const char **) apr_array_push (commit_paths))) = current_path->data;
106 current_path = g_list_next (current_path);
109 error = svn_client_commit3 (&commit_info,
110 commit_paths,
111 self->priv->recursive,
112 TRUE,
113 svn_command_get_client_context (svn_command),
114 svn_command_get_pool (svn_command));
116 if (error)
118 svn_command_set_error (svn_command, error);
119 return 1;
122 if (commit_info)
124 revision_message = g_strdup_printf ("Committed revision %ld.",
125 commit_info->revision);
126 svn_command_push_info (SVN_COMMAND (command), revision_message);
127 g_free (revision_message);
130 return 0;
133 static void
134 svn_commit_command_class_init (SvnCommitCommandClass *klass)
136 GObjectClass *object_class = G_OBJECT_CLASS (klass);
137 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
139 object_class->finalize = svn_commit_command_finalize;
140 command_class->run = svn_commit_command_run;
143 SvnCommitCommand *
144 svn_commit_command_new (GList *paths, gchar *log_message,
145 gboolean recursive)
147 SvnCommitCommand *self;
149 self = g_object_new (SVN_TYPE_COMMIT_COMMAND, NULL);
150 self->priv->paths = svn_command_copy_path_list (paths);
151 self->priv->log_message = g_strdup (log_message);
152 self->priv->recursive = recursive;
154 return self;
157 void
158 svn_commit_command_destroy (SvnCommitCommand *self)
160 g_object_unref (self);