Updated Spanish translation
[anjuta-git-plugin.git] / plugins / subversion / svn-log-command.c
blobef05e62e0ce9cdb5af46b11d7146fd5a27a47f19
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-log-command.h"
27 struct _SvnLogCommandPriv
29 gchar *path;
30 GQueue *log_entry_queue;
33 G_DEFINE_TYPE (SvnLogCommand, svn_log_command, SVN_TYPE_COMMAND);
35 static void
36 svn_log_command_init (SvnLogCommand *self)
38 self->priv = g_new0 (SvnLogCommandPriv, 1);
39 self->priv->log_entry_queue = g_queue_new ();
42 static void
43 svn_log_command_finalize (GObject *object)
45 SvnLogCommand *self;
46 GList *current_log_entry;
48 self = SVN_LOG_COMMAND (object);
50 g_free (self->priv->path);
52 current_log_entry = self->priv->log_entry_queue->head;
54 while (current_log_entry)
56 svn_log_entry_destroy (current_log_entry->data);
57 current_log_entry = g_list_next (current_log_entry);
60 g_queue_free (self->priv->log_entry_queue);
61 g_free (self->priv);
63 G_OBJECT_CLASS (svn_log_command_parent_class)->finalize (object);
66 static svn_error_t *
67 log_callback (void *baton,
68 apr_hash_t *changed_paths,
69 svn_revnum_t revision,
70 const char *author,
71 const char *date,
72 const char *message,
73 apr_pool_t *pool)
75 SvnLogCommand *self;
76 SvnLogEntry *log_entry;
77 gchar *entry_author;
78 const gchar *human_date;
79 gchar *entry_date;
80 apr_time_t entry_time;
81 gchar *entry_message;
83 self = SVN_LOG_COMMAND (baton);
85 /* Libsvn docs say author, date, and message might be NULL. */
86 if (author)
87 entry_author = g_strdup (author);
88 else
89 entry_author = g_strdup ("(none)");
91 if (date && date[0])
93 svn_time_from_cstring (&entry_time, date,
94 svn_command_get_pool (SVN_COMMAND (self)));
95 human_date = svn_time_to_human_cstring (entry_time,
96 svn_command_get_pool (SVN_COMMAND (self)));
97 entry_date = g_strdup (human_date);
99 else
100 entry_date = g_strdup ("(none)");
102 if (message)
103 entry_message = g_strdup (message);
104 else
105 entry_message = g_strdup ("empty log message"); /* Emulate ViewCVS */
107 log_entry = svn_log_entry_new (entry_author, entry_date, revision,
108 entry_message);
110 anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (self));
111 g_queue_push_head (self->priv->log_entry_queue, log_entry);
112 anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (self));
114 anjuta_command_notify_data_arrived (ANJUTA_COMMAND (self));
116 return SVN_NO_ERROR;
119 static guint
120 svn_log_command_run (AnjutaCommand *command)
122 SvnLogCommand *self;
123 SvnCommand *svn_command;
124 apr_array_header_t *log_path;
125 svn_opt_revision_t peg_revision;
126 svn_opt_revision_t start_revision;
127 svn_opt_revision_t end_revision;
128 svn_error_t *error;
130 self = SVN_LOG_COMMAND (command);
131 svn_command = SVN_COMMAND (command);
132 log_path = apr_array_make (svn_command_get_pool (SVN_COMMAND (command)),
133 1, sizeof (char *));
134 /* I just copied this so don't blame me... */
135 (*((const char **) apr_array_push (log_path))) = self->priv->path;
136 peg_revision.kind = svn_opt_revision_unspecified;
137 start_revision.kind = svn_opt_revision_number;
138 start_revision.value.number = 1; /* Initial revision */
139 end_revision.kind = svn_opt_revision_head;
141 error = svn_client_log3 (log_path,
142 &peg_revision,
143 &start_revision,
144 &end_revision,
146 FALSE,
147 FALSE,
148 log_callback,
149 self,
150 svn_command_get_client_context (svn_command),
151 svn_command_get_pool (svn_command));
153 if (error)
155 svn_command_set_error (svn_command, error);
156 return 1;
159 return 0;
162 static void
163 svn_log_command_class_init (SvnLogCommandClass *klass)
165 GObjectClass *object_class = G_OBJECT_CLASS (klass);
166 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
168 object_class->finalize = svn_log_command_finalize;
169 command_class->run = svn_log_command_run;
172 SvnLogCommand *
173 svn_log_command_new (gchar *path)
175 SvnLogCommand *self;
177 self = g_object_new (SVN_TYPE_LOG_COMMAND, NULL);
178 self->priv->path = g_strdup (path);
180 return self;
183 void
184 svn_log_command_destroy (SvnLogCommand *self)
186 g_object_unref (self);
189 GQueue *
190 svn_log_command_get_entry_queue (SvnLogCommand *self)
192 return self->priv->log_entry_queue;