Updated Spanish translation
[anjuta-git-plugin.git] / plugins / subversion / svn-copy-command.c
blob6cd0225bbe444952e1a6f9349375ebaec1c7cfea
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-copy-command.h"
27 struct _SvnCopyCommandPriv
29 gchar *source_path;
30 glong source_revision;
31 gchar *dest_path;
32 gchar *log_message;
35 G_DEFINE_TYPE (SvnCopyCommand, svn_copy_command, SVN_TYPE_COMMAND);
37 static svn_error_t*
38 on_log_callback (const char **log_msg,
39 const char **tmp_file,
40 apr_array_header_t *commit_items,
41 void *baton,
42 apr_pool_t *pool)
45 SvnCopyCommand *self;
47 self = SVN_COPY_COMMAND (baton);
49 *log_msg = self->priv->log_message;
50 *tmp_file = NULL;
52 return SVN_NO_ERROR;
55 static void
56 svn_copy_command_init (SvnCopyCommand *self)
58 svn_client_ctx_t *client_context;
60 self->priv = g_new0 (SvnCopyCommandPriv, 1);
61 client_context = svn_command_get_client_context (SVN_COMMAND (self));
63 client_context->log_msg_func = on_log_callback;
64 client_context->log_msg_baton = self;
67 static void
68 svn_copy_command_finalize (GObject *object)
70 SvnCopyCommand *self;
72 self = SVN_COPY_COMMAND (object);
74 g_free (self->priv->source_path);
75 g_free (self->priv->dest_path);
76 g_free (self->priv->log_message);
77 g_free (self->priv);
79 G_OBJECT_CLASS (svn_copy_command_parent_class)->finalize (object);
82 static guint
83 svn_copy_command_run (AnjutaCommand *command)
85 SvnCopyCommand *self;
86 SvnCommand *svn_command;
87 svn_opt_revision_t revision;
88 svn_commit_info_t *commit_info;
89 gchar *revision_message;
90 svn_error_t *error;
92 self = SVN_COPY_COMMAND (command);
93 svn_command = SVN_COMMAND (command);
95 switch (self->priv->source_revision)
97 case SVN_COPY_REVISION_WORKING:
98 revision.kind = svn_opt_revision_working;
99 break;
100 case SVN_COPY_REVISION_HEAD:
101 revision.kind = svn_opt_revision_head;
102 break;
103 default:
104 revision.kind = svn_opt_revision_number;
105 revision.value.number = self->priv->source_revision;
106 break;
109 error = svn_client_copy3 (&commit_info,
110 self->priv->source_path,
111 &revision,
112 self->priv->dest_path,
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 &&
123 svn_path_is_url (self->priv->dest_path))
125 revision_message = g_strdup_printf ("Committed revision %ld.",
126 commit_info->revision);
127 svn_command_push_info (SVN_COMMAND (command), revision_message);
128 g_free (revision_message);
131 return 0;
134 static void
135 svn_copy_command_class_init (SvnCopyCommandClass *klass)
137 GObjectClass* object_class = G_OBJECT_CLASS (klass);
138 AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
140 object_class->finalize = svn_copy_command_finalize;
141 command_class->run = svn_copy_command_run;
144 SvnCopyCommand *
145 svn_copy_command_new (gchar *source_path, glong source_revision,
146 gchar *dest_path, gchar *log_message)
148 SvnCopyCommand *self;
150 self = g_object_new (SVN_TYPE_COPY_COMMAND, NULL);
152 self->priv->source_path = g_strdup (source_path);
153 self->priv->source_revision = source_revision;
154 self->priv->dest_path = g_strdup (dest_path);
155 self->priv->log_message = g_strdup (log_message);
157 return self;
160 void
161 svn_copy_command_destroy (SvnCopyCommand *self)
163 g_object_unref (self);