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-log-command.h"
27 struct _GitLogCommandPriv
29 GitLogDataCommand
*data_command
;
44 G_DEFINE_TYPE (GitLogCommand
, git_log_command
, GIT_TYPE_COMMAND
);
47 on_data_command_data_arrived (AnjutaCommand
*command
, GitLogCommand
*self
)
49 anjuta_command_notify_data_arrived (command
);
53 on_data_command_finished (AnjutaCommand
*command
, guint return_code
,
56 ANJUTA_COMMAND_CLASS (git_log_command_parent_class
)->notify_complete (ANJUTA_COMMAND (self
),
57 self
->priv
->return_code
);
61 git_log_command_init (GitLogCommand
*self
)
63 self
->priv
= g_new0 (GitLogCommandPriv
, 1);
65 self
->priv
->data_command
= git_log_data_command_new ();
67 g_signal_connect (G_OBJECT (self
->priv
->data_command
), "data-arrived",
68 G_CALLBACK (on_data_command_data_arrived
),
71 g_signal_connect (G_OBJECT (self
->priv
->data_command
), "command-finished",
72 G_CALLBACK (on_data_command_finished
),
77 git_log_command_finalize (GObject
*object
)
81 self
= GIT_LOG_COMMAND (object
);
83 g_object_unref (self
->priv
->data_command
);
84 g_free (self
->priv
->author
);
85 g_free (self
->priv
->grep
);
86 g_free (self
->priv
->since_date
);
87 g_free (self
->priv
->until_date
);
88 g_free (self
->priv
->since_commit
);
89 g_free (self
->priv
->until_commit
);
92 G_OBJECT_CLASS (git_log_command_parent_class
)->finalize (object
);
96 git_log_command_run (AnjutaCommand
*command
)
100 GString
*commit_range
;
102 self
= GIT_LOG_COMMAND (command
);
104 git_command_add_arg (GIT_COMMAND (command
), "rev-list");
105 git_command_add_arg (GIT_COMMAND (command
), "--topo-order");
106 git_command_add_arg (GIT_COMMAND (command
), "--pretty=format:parents %P%n"
112 if (self
->priv
->author
)
114 filter_arg
= g_strdup_printf ("--author=%s", self
->priv
->author
);
115 git_command_add_arg (GIT_COMMAND (command
), filter_arg
);
119 if (self
->priv
->grep
)
121 filter_arg
= g_strdup_printf ("--grep=%s", self
->priv
->grep
);
122 git_command_add_arg (GIT_COMMAND (command
), filter_arg
);
126 if (self
->priv
->since_date
)
128 filter_arg
= g_strdup_printf ("--since=%s", self
->priv
->since_date
);
129 git_command_add_arg (GIT_COMMAND (command
), filter_arg
);
133 if (self
->priv
->until_date
)
135 filter_arg
= g_strdup_printf ("--until=%s", self
->priv
->until_date
);
136 git_command_add_arg (GIT_COMMAND (command
), filter_arg
);
140 if (self
->priv
->since_commit
|| self
->priv
->until_commit
)
142 commit_range
= g_string_new ("");
144 /* Not the most elegant way of doing it... */
145 if (self
->priv
->since_commit
)
146 g_string_append (commit_range
, self
->priv
->since_commit
);
148 g_string_append (commit_range
, "..");
150 if (self
->priv
->until_commit
)
151 g_string_append (commit_range
, self
->priv
->until_commit
);
153 git_command_add_arg (GIT_COMMAND (command
), commit_range
->str
);
155 g_string_free (commit_range
, TRUE
);
158 if (self
->priv
->branch
)
159 git_command_add_arg (GIT_COMMAND (command
), self
->priv
->branch
);
161 git_command_add_arg (GIT_COMMAND (command
), "HEAD");
163 if (self
->priv
->path
)
165 git_command_add_arg (GIT_COMMAND (command
), "--");
166 git_command_add_arg (GIT_COMMAND (command
), self
->priv
->path
);
169 /* Start the data processing task */
170 anjuta_command_start (ANJUTA_COMMAND (self
->priv
->data_command
));
176 git_log_command_notify_complete (AnjutaCommand
*command
, guint return_code
)
180 self
= GIT_LOG_COMMAND (command
);
182 /* Send an empty string to the data processing command so that it knows
183 * to stop when it's done processing data. The command will finish when
184 * the processing thread finishes, and not when git stops executing */
185 git_log_data_command_push_line (self
->priv
->data_command
, "");
187 /* Use the git return code */
188 self
->priv
->return_code
= return_code
;
192 git_log_command_handle_output (GitCommand
*git_command
, const gchar
*output
)
196 self
= GIT_LOG_COMMAND (git_command
);
198 git_log_data_command_push_line (self
->priv
->data_command
, output
);
202 git_log_command_class_init (GitLogCommandClass
*klass
)
204 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
205 GitCommandClass
* parent_class
= GIT_COMMAND_CLASS (klass
);
206 AnjutaCommandClass
*command_class
= ANJUTA_COMMAND_CLASS (klass
);
208 object_class
->finalize
= git_log_command_finalize
;
209 parent_class
->output_handler
= git_log_command_handle_output
;
210 command_class
->run
= git_log_command_run
;
211 command_class
->notify_complete
= git_log_command_notify_complete
;
216 git_log_command_new (const gchar
*working_directory
,
217 const gchar
*branch
, const gchar
*path
,
218 const gchar
*author
, const gchar
*grep
,
219 const gchar
*since_date
, const gchar
*until_date
,
220 const gchar
*since_commit
,
221 const gchar
*until_commit
)
225 self
= g_object_new (GIT_TYPE_LOG_COMMAND
,
226 "working-directory", working_directory
,
227 "single-line-output", TRUE
,
230 self
->priv
->author
= g_strdup (author
);
231 self
->priv
->path
= g_strdup (path
);
232 self
->priv
->branch
= g_strdup (branch
);
233 self
->priv
->grep
= g_strdup (grep
);
234 self
->priv
->since_date
= g_strdup (since_date
);
235 self
->priv
->until_date
= g_strdup (until_date
);
236 self
->priv
->since_commit
= g_strdup (since_commit
);
237 self
->priv
->until_commit
= g_strdup (until_commit
);
243 git_log_command_get_output_queue (GitLogCommand
*self
)
245 return git_log_data_command_get_output (self
->priv
->data_command
);