glade: Fix make file some files were not installed
[anjuta.git] / plugins / subversion / svn-log-command.c
blob80dc2e0f539419f01b2b61f18f34fb9597bd906b
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 g_free (entry_author);
111 g_free (entry_date);
112 g_free (entry_message);
114 anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (self));
115 g_queue_push_head (self->priv->log_entry_queue, log_entry);
116 anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (self));
118 anjuta_command_notify_data_arrived (ANJUTA_COMMAND (self));
120 return SVN_NO_ERROR;
123 static guint
124 svn_log_command_run (AnjutaCommand *command)
126 SvnLogCommand *self;
127 SvnCommand *svn_command;
128 apr_array_header_t *log_path;
129 svn_opt_revision_t peg_revision;
130 svn_opt_revision_t start_revision;
131 svn_opt_revision_t end_revision;
132 svn_error_t *error;
134 self = SVN_LOG_COMMAND (command);
135 svn_command = SVN_COMMAND (command);
136 log_path = apr_array_make (svn_command_get_pool (SVN_COMMAND (command)),
137 1, sizeof (char *));
138 /* I just copied this so don't blame me... */
139 (*((const char **) apr_array_push (log_path))) = self->priv->path;
140 peg_revision.kind = svn_opt_revision_unspecified;
141 start_revision.kind = svn_opt_revision_number;
142 start_revision.value.number = 1; /* Initial revision */
143 end_revision.kind = svn_opt_revision_head;
145 error = svn_client_log3 (log_path,
146 &peg_revision,
147 &start_revision,
148 &end_revision,
150 FALSE,
151 FALSE,
152 log_callback,
153 self,
154 svn_command_get_client_context (svn_command),
155 svn_command_get_pool (svn_command));
157 if (error)
159 svn_command_set_error (svn_command, error);
160 return 1;
163 return 0;
166 static void
167 svn_log_command_class_init (SvnLogCommandClass *klass)
169 GObjectClass *object_class = G_OBJECT_CLASS (klass);
170 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
172 object_class->finalize = svn_log_command_finalize;
173 command_class->run = svn_log_command_run;
176 SvnLogCommand *
177 svn_log_command_new (const gchar *path)
179 SvnLogCommand *self;
181 self = g_object_new (SVN_TYPE_LOG_COMMAND, NULL);
182 self->priv->path = svn_command_make_canonical_path (SVN_COMMAND (self),
183 path);
184 return self;
187 void
188 svn_log_command_destroy (SvnLogCommand *self)
190 g_object_unref (self);
193 GQueue *
194 svn_log_command_get_entry_queue (SvnLogCommand *self)
196 return self->priv->log_entry_queue;