Implement bisecting
[anjuta-git-plugin.git] / plugins / subversion / svn-status-command.c
blobf195014768e6edcb559c47cd67968febd1bff334
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-status-command.h"
27 struct _SvnStatusCommandPriv
29 gchar *path;
30 gboolean recursive;
31 gboolean get_all_items;
32 GQueue *status_queue;
35 G_DEFINE_TYPE (SvnStatusCommand, svn_status_command, SVN_TYPE_COMMAND);
37 static void
38 svn_status_command_init (SvnStatusCommand *self)
40 self->priv = g_new0 (SvnStatusCommandPriv, 1);
41 self->priv->status_queue = g_queue_new ();
44 static void
45 svn_status_command_finalize (GObject *object)
47 SvnStatusCommand *self;
48 GList *current_status;
50 self = SVN_STATUS_COMMAND (object);
51 current_status = self->priv->status_queue->head;
53 g_free (self->priv->path);
55 while (current_status)
57 svn_status_destroy (current_status->data);
58 current_status = g_list_next (current_status);
61 g_queue_free (self->priv->status_queue);
62 g_free (self->priv);
64 G_OBJECT_CLASS (svn_status_command_parent_class)->finalize (object);
67 static void
68 on_svn_status_notify (void *baton, const char *path, svn_wc_status2_t *status)
70 SvnStatusCommand *self;
71 SvnStatus *status_object;
73 self = SVN_STATUS_COMMAND (baton);
75 /* Right now we only support text status (no properties.) */
77 switch (status->text_status)
79 case svn_wc_status_modified:
80 case svn_wc_status_added:
81 case svn_wc_status_deleted:
82 case svn_wc_status_conflicted:
83 case svn_wc_status_missing:
84 status_object = svn_status_new ((gchar *) path,
85 status->text_status);
87 anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (self));
88 g_queue_push_tail (self->priv->status_queue, status_object);
89 anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (self));
91 anjuta_command_notify_data_arrived (ANJUTA_COMMAND (self));
93 break;
94 default:
95 break;
99 static guint
100 svn_status_command_run (AnjutaCommand *command)
102 SvnStatusCommand *self;
103 SvnCommand *svn_command;
104 svn_opt_revision_t revision;
105 svn_error_t *error;
107 self = SVN_STATUS_COMMAND (command);
108 svn_command = SVN_COMMAND (command);
109 revision.kind = svn_opt_revision_working;
111 error = svn_client_status2 (NULL,
112 self->priv->path,
113 &revision,
114 on_svn_status_notify,
115 self,
116 self->priv->recursive,
117 self->priv->get_all_items,
118 FALSE,
119 FALSE,
120 TRUE,
121 svn_command_get_client_context (svn_command),
122 svn_command_get_pool (svn_command));
124 if (error)
126 svn_command_set_error (svn_command, error);
127 return 1;
130 return 0;
133 static void
134 svn_status_command_class_init (SvnStatusCommandClass *klass)
136 GObjectClass *object_class = G_OBJECT_CLASS (klass);
137 AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass);
139 command_class->run = svn_status_command_run;
140 object_class->finalize = svn_status_command_finalize;
143 SvnStatusCommand *
144 svn_status_command_new (gchar *path, gboolean recursive, gboolean get_all_items)
146 SvnStatusCommand *self;
148 self = g_object_new (SVN_TYPE_STATUS_COMMAND, NULL);
149 self->priv->path = svn_command_make_canonical_path (SVN_COMMAND (self),
150 path);
151 self->priv->recursive = recursive;
152 self->priv->get_all_items = get_all_items;
154 return self;
157 void
158 svn_status_command_destroy (SvnStatusCommand *self)
160 g_object_unref (self);
163 GQueue *
164 svn_status_command_get_status_queue (SvnStatusCommand *self)
166 return self->priv->status_queue;