Integrate removing files with the file manager
[anjuta-git-plugin.git] / plugins / subversion / svn-update-command.c
blobec6d5de712fb6d58e9485cfecdd94119fb12bb87
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-update-command.h"
30 struct _SvnUpdateCommandPriv
32 gchar *path;
33 gchar *revision;
34 gboolean recursive;
37 G_DEFINE_TYPE (SvnUpdateCommand, svn_update_command, SVN_TYPE_COMMAND);
39 static void
40 svn_update_command_init (SvnUpdateCommand *self)
42 self->priv = g_new0 (SvnUpdateCommandPriv, 1);
45 static void
46 svn_update_command_finalize (GObject *object)
48 SvnUpdateCommand *self;
50 self = SVN_UPDATE_COMMAND (object);
52 g_free (self->priv->path);
53 g_free (self->priv->revision);
54 g_free (self->priv);
56 G_OBJECT_CLASS (svn_update_command_parent_class)->finalize (object);
59 static guint
60 svn_update_command_run (AnjutaCommand *command)
62 SvnUpdateCommand *self;
63 SvnCommand *svn_command;
64 svn_opt_revision_t *revision;
65 apr_array_header_t *update_paths;
66 apr_array_header_t *update_revisions;
67 svn_error_t *error;
68 svn_revnum_t revision_number;
69 gchar *revision_message;
71 self = SVN_UPDATE_COMMAND (command);
72 svn_command = SVN_COMMAND (command);
73 revision = svn_command_get_revision (self->priv->revision);
75 /* I just copied this so don't blame me... */
76 update_paths = apr_array_make (svn_command_get_pool (svn_command), 1,
77 sizeof (char *));
78 (*((const char **) apr_array_push (update_paths))) = self->priv->path;
80 error = svn_client_update2 (&update_revisions,
81 update_paths,
82 revision,
83 self->priv->recursive,
84 FALSE,
85 svn_command_get_client_context (svn_command),
86 svn_command_get_pool (svn_command));
88 if (error)
90 svn_command_set_error (svn_command, error);
91 return 1;
94 revision_number = (*(svn_revnum_t *) apr_array_pop (update_revisions));
96 revision_message = g_strdup_printf ("Updated to revision %ld.",
97 (glong) revision_number);
98 svn_command_push_info (SVN_COMMAND (command), revision_message);
99 g_free (revision_message);
101 return 0;
104 static void
105 svn_update_command_class_init (SvnUpdateCommandClass *klass)
107 GObjectClass *object_class = G_OBJECT_CLASS (klass);
108 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
110 object_class->finalize = svn_update_command_finalize;
111 command_class->run = svn_update_command_run;
115 SvnUpdateCommand *
116 svn_update_command_new (gchar *path, gchar *revision, gboolean recursive)
118 SvnUpdateCommand *self;
120 self = g_object_new (SVN_TYPE_UPDATE_COMMAND, NULL);
122 self->priv->path = svn_command_make_canonical_path (SVN_COMMAND (self),
123 path);
124 self->priv->revision = g_strdup (revision);
125 self->priv->recursive = recursive;
127 return self;
130 void
131 svn_update_command_destroy (SvnUpdateCommand *self)
133 g_object_unref (self);