Updated Spanish translation
[anjuta-git-plugin.git] / plugins / subversion / svn-switch-command.c
blobf4c4432612edf01b84495c9f1e130503edaacfee
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 * 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.
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.
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.
25 #include "svn-switch-command.h"
27 struct _SvnSwitchCommandPriv
29 gchar *working_copy_path;
30 gchar *branch_url;
31 glong revision;
32 gboolean recursive;
35 G_DEFINE_TYPE (SvnSwitchCommand, svn_switch_command, SVN_TYPE_COMMAND);
37 static void
38 svn_switch_command_init (SvnSwitchCommand *self)
40 self->priv = g_new0 (SvnSwitchCommandPriv, 1);
43 static void
44 svn_switch_command_finalize (GObject *object)
46 SvnSwitchCommand *self;
48 self = SVN_SWITCH_COMMAND (object);
50 g_free (self->priv->working_copy_path);
51 g_free (self->priv->branch_url);
52 g_free (self->priv);
54 G_OBJECT_CLASS (svn_switch_command_parent_class)->finalize (object);
57 static guint
58 svn_switch_command_run (AnjutaCommand *command)
60 SvnSwitchCommand *self;
61 SvnCommand *svn_command;
62 svn_opt_revision_t revision;
63 svn_revnum_t switched_revision;
64 gchar *revision_message;
65 svn_error_t *error;
67 self = SVN_SWITCH_COMMAND (command);
68 svn_command = SVN_COMMAND (command);
70 if (self->priv->revision == SVN_SWITCH_REVISION_HEAD)
71 revision.kind = svn_opt_revision_head;
72 else
74 revision.kind = svn_opt_revision_number;
75 revision.value.number = self->priv->revision;
78 error = svn_client_switch (&switched_revision,
79 self->priv->working_copy_path,
80 self->priv->branch_url,
81 &revision,
82 self->priv->recursive,
83 svn_command_get_client_context (svn_command),
84 svn_command_get_pool (svn_command));
86 if (error)
88 svn_command_set_error (svn_command, error);
89 return 1;
92 revision_message = g_strdup_printf ("Switched to revision %ld.",
93 switched_revision);
95 svn_command_push_info (svn_command, revision_message);
96 g_free (revision_message);
98 return 0;
101 static void
102 svn_switch_command_class_init (SvnSwitchCommandClass *klass)
104 GObjectClass* object_class = G_OBJECT_CLASS (klass);
105 AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
107 object_class->finalize = svn_switch_command_finalize;
108 command_class->run = svn_switch_command_run;
111 SvnSwitchCommand *
112 svn_switch_command_new (gchar *working_copy_path, gchar *branch_url,
113 glong revision, gboolean recursive)
115 SvnSwitchCommand *self;
117 self = g_object_new (SVN_TYPE_SWITCH_COMMAND, NULL);
118 self->priv->working_copy_path = g_strdup (working_copy_path);
119 self->priv->branch_url = g_strdup (branch_url);
120 self->priv->revision = revision;
121 self->priv->recursive = recursive;
123 return self;
126 void
127 svn_switch_command_destroy (SvnSwitchCommand *self)
129 g_object_unref (self);