1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
6 * anjuta is free software.
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)
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 "git-vcs-interface.h"
28 git_ivcs_iface_init (IAnjutaVcsIface
*iface
)
30 iface
->add
= git_ivcs_add
;
31 iface
->checkout
= git_ivcs_checkout
;
32 iface
->diff
= git_ivcs_diff
;
33 iface
->query_status
= git_ivcs_query_status
;
34 iface
->remove
= git_ivcs_remove
;
38 git_ivcs_add (IAnjutaVcs
*obj
, GList
*files
, AnjutaAsyncNotify
*notify
,
41 gchar
*project_root_directory
;
43 GitAddCommand
*add_command
;
45 project_root_directory
= ANJUTA_PLUGIN_GIT (obj
)->project_root_directory
;
47 if (project_root_directory
)
49 path_list
= anjuta_util_convert_gfile_list_to_relative_path_list (files
,
50 project_root_directory
);
51 add_command
= git_add_command_new_list (project_root_directory
,
54 anjuta_util_glist_strings_free (path_list
);
56 g_signal_connect (G_OBJECT (add_command
), "command-finished",
57 G_CALLBACK (g_object_unref
),
62 g_signal_connect_swapped (G_OBJECT (add_command
), "command-finished",
63 G_CALLBACK (anjuta_async_notify_notify_finished
),
67 anjuta_command_start (ANJUTA_COMMAND (add_command
));
73 git_ivcs_checkout (IAnjutaVcs
*obj
,
74 const gchar
*repository_location
, GFile
*dest
,
76 AnjutaAsyncNotify
*notify
, GError
**err
)
79 gchar
*path
, *dir_name
;
80 GitCloneCommand
*clone_command
;
83 parent
= g_file_get_parent (dest
);
84 path
= g_file_get_path (parent
);
85 dir_name
= g_file_get_basename (dest
);
87 clone_command
= git_clone_command_new (path
, repository_location
, dir_name
);
88 plugin
= ANJUTA_PLUGIN_GIT (obj
);
90 g_object_unref (parent
);
94 git_pane_create_message_view (plugin
);
96 g_signal_connect (G_OBJECT (clone_command
), "data-arrived",
97 G_CALLBACK (git_pane_on_command_info_arrived
),
100 g_signal_connect (G_OBJECT (clone_command
), "command-finished",
101 G_CALLBACK (g_object_unref
),
106 g_signal_connect_swapped (G_OBJECT (cancel
), "cancelled",
107 G_CALLBACK (anjuta_command_cancel
),
113 g_signal_connect_swapped (G_OBJECT (clone_command
),
115 G_CALLBACK (anjuta_async_notify_notify_finished
),
119 anjuta_command_start (ANJUTA_COMMAND (clone_command
));
123 on_diff_command_data_arrived (AnjutaCommand
*command
,
124 IAnjutaVcsDiffCallback callback
)
129 output
= git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command
));
131 while (g_queue_peek_head (output
))
133 line
= g_queue_pop_head (output
);
134 callback (g_object_get_data (G_OBJECT (command
), "file"), line
,
135 g_object_get_data (G_OBJECT (command
), "user-data"));
141 git_ivcs_diff (IAnjutaVcs
*obj
, GFile
* file
,
142 IAnjutaVcsDiffCallback callback
, gpointer user_data
,
143 GCancellable
* cancel
, AnjutaAsyncNotify
*notify
,
146 gchar
*project_root_directory
;
147 GitDiffCommand
*diff_command
;
149 project_root_directory
= ANJUTA_PLUGIN_GIT (obj
)->project_root_directory
;
151 if (project_root_directory
)
153 diff_command
= git_diff_command_new (project_root_directory
);
155 g_object_set_data_full (G_OBJECT (diff_command
), "file",
157 (GDestroyNotify
) g_object_unref
);
158 g_object_set_data (G_OBJECT (diff_command
), "user-data", user_data
);
160 g_signal_connect (G_OBJECT (diff_command
), "command-finished",
161 G_CALLBACK (g_object_unref
),
164 g_signal_connect (G_OBJECT (diff_command
), "data-arrived",
165 G_CALLBACK (on_diff_command_data_arrived
),
168 /* FIXME: Reenable when canceling is implemented. */
172 g_signal_connect_swapped (G_OBJECT (cancel
), "cancelled",
173 G_CALLBACK (anjuta_command_cancel
),
180 g_signal_connect_swapped (G_OBJECT (diff_command
), "command-finished",
181 G_CALLBACK (anjuta_async_notify_notify_finished
),
185 anjuta_command_start (ANJUTA_COMMAND (diff_command
));
190 on_status_command_data_arrived (AnjutaCommand
*command
,
191 IAnjutaVcsStatusCallback callback
)
193 GQueue
*status_queue
;
195 const gchar
*working_directory
;
200 status_queue
= git_status_command_get_status_queue (GIT_STATUS_COMMAND (command
));
202 while (g_queue_peek_head (status_queue
))
204 status
= g_queue_pop_head (status_queue
);
205 working_directory
= g_object_get_data (G_OBJECT (command
),
206 "working-directory");
207 path
= git_status_get_path (status
);
208 full_path
= g_strconcat (working_directory
, G_DIR_SEPARATOR_S
, path
,
210 file
= g_file_new_for_path (full_path
);
212 DEBUG_PRINT ("Working directory: %s\n", working_directory
);
213 DEBUG_PRINT ("File %s Status %i\n", full_path
, git_status_get_vcs_status (status
));
218 git_status_get_vcs_status (status
),
219 g_object_get_data (G_OBJECT (command
), "user-data"));
221 g_object_unref (file
);
227 g_object_unref (status
);
232 git_ivcs_query_status (IAnjutaVcs
*obj
, GFile
*file
,
233 IAnjutaVcsStatusCallback callback
,
234 gpointer user_data
, GCancellable
*cancel
,
235 AnjutaAsyncNotify
*notify
, GError
**err
)
238 GitStatusCommand
*status_command
;
240 path
= g_file_get_path (file
);
241 status_command
= git_status_command_new (path
, ~0);
245 g_object_set_data (G_OBJECT (status_command
), "user-data", user_data
);
246 g_object_set_data (G_OBJECT (status_command
), "working-directory",
247 ANJUTA_PLUGIN_GIT (obj
)->project_root_directory
);
249 g_signal_connect (G_OBJECT (status_command
), "data-arrived",
250 G_CALLBACK (on_status_command_data_arrived
),
253 g_signal_connect (G_OBJECT (status_command
), "command-finished",
254 G_CALLBACK (g_object_unref
),
260 g_signal_connect_swapped (G_OBJECT (cancel
), "cancelled",
261 G_CALLBACK (anjuta_command_cancel
),
268 g_signal_connect_swapped (G_OBJECT (status_command
), "command-finished",
269 G_CALLBACK (anjuta_async_notify_notify_finished
),
273 anjuta_command_queue_push (ANJUTA_PLUGIN_GIT (obj
)->command_queue
,
274 ANJUTA_COMMAND (status_command
));
278 git_ivcs_remove (IAnjutaVcs
*obj
, GList
*files
,
279 AnjutaAsyncNotify
*notify
, GError
**err
)
281 gchar
*project_root_directory
;
283 GitRemoveCommand
*remove_command
;
285 project_root_directory
= ANJUTA_PLUGIN_GIT (obj
)->project_root_directory
;
287 if (project_root_directory
)
289 path_list
= anjuta_util_convert_gfile_list_to_relative_path_list (files
,
290 project_root_directory
);
291 remove_command
= git_remove_command_new_list (project_root_directory
,
294 anjuta_util_glist_strings_free (path_list
);
296 g_signal_connect (G_OBJECT (remove_command
), "command-finished",
297 G_CALLBACK (g_object_unref
),
302 g_signal_connect_swapped (G_OBJECT (remove_command
), "command-finished",
303 G_CALLBACK (anjuta_async_notify_notify_finished
),
307 anjuta_command_start (ANJUTA_COMMAND (remove_command
));