1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2007 Imendio AB
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
24
#include "giggle-git-log.h"
25
#include "giggle-revision.h"
27
typedef struct GiggleGitLogPriv GiggleGitLogPriv;
29
struct GiggleGitLogPriv {
30
GiggleRevision *revision;
34
static void git_log_finalize (GObject *object);
35
static void git_log_get_property (GObject *object,
39
static void git_log_set_property (GObject *object,
44
static gboolean git_log_get_command_line (GiggleJob *job,
45
gchar **command_line);
46
static void git_log_handle_output (GiggleJob *job,
47
const gchar *output_str,
55
G_DEFINE_TYPE (GiggleGitLog, giggle_git_log, GIGGLE_TYPE_JOB)
57
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_LOG, GiggleGitLogPriv))
60
giggle_git_log_class_init (GiggleGitLogClass *class)
62
GObjectClass *object_class = G_OBJECT_CLASS (class);
63
GiggleJobClass *job_class = GIGGLE_JOB_CLASS (class);
65
object_class->finalize = git_log_finalize;
66
object_class->get_property = git_log_get_property;
67
object_class->set_property = git_log_set_property;
69
job_class->get_command_line = git_log_get_command_line;
70
job_class->handle_output = git_log_handle_output;
72
g_object_class_install_property (object_class,
74
g_param_spec_object ("revision",
78
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
80
g_type_class_add_private (object_class, sizeof (GiggleGitLogPriv));
84
giggle_git_log_init (GiggleGitLog *log)
89
git_log_finalize (GObject *object)
91
GiggleGitLogPriv *priv;
93
priv = GET_PRIV (object);
94
g_object_unref (priv->revision);
97
G_OBJECT_CLASS (giggle_git_log_parent_class)->finalize (object);
101
git_log_get_property (GObject *object,
106
GiggleGitLogPriv *priv;
108
priv = GET_PRIV (object);
112
g_value_set_object (value, priv->revision);
115
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
121
git_log_set_property (GObject *object,
126
GiggleGitLogPriv *priv;
128
priv = GET_PRIV (object);
132
#if GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION > 12
133
priv->revision = g_value_dup_object (value);
135
priv->revision = GIGGLE_REVISION (g_value_dup_object (value));
139
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
145
git_log_get_command_line (GiggleJob *job,
146
gchar **command_line)
148
GiggleGitLogPriv *priv;
152
priv = GET_PRIV (job);
153
sha = giggle_revision_get_sha (priv->revision);
154
str = g_string_new (GIT_COMMAND);
155
g_string_append_printf (str, " rev-list --pretty=raw %s^..%s", sha, sha);
157
*command_line = g_string_free (str, FALSE);
162
git_log_parse_log (const gchar *output)
168
lines = g_strsplit (output, "\n", -1);
169
long_log = g_string_new ("");
172
gchar* converted = NULL;
174
if (g_utf8_validate (lines[i], -1, NULL)) {
175
converted = g_strdup (lines[i]);
179
converted = g_locale_to_utf8 (lines[i], -1,
181
NULL); // FIXME: add GError
185
converted = g_filename_to_utf8 (lines[i], -1,
187
NULL); // FIXME: add GError
191
converted = g_convert (lines[i], -1,
192
"UTF-8", "ISO-8859-15",
193
NULL, NULL, NULL); // FIXME: add GError
197
converted = g_strescape (lines[i], "\n\r\\\"\'");
201
g_warning ("Error while converting string");
205
if (g_str_has_prefix (converted, " ")) {
206
g_strstrip (converted);
207
g_string_append_printf (long_log, "%s\n", converted);
215
return g_string_free (long_log, FALSE);
219
git_log_handle_output (GiggleJob *job,
220
const gchar *output_str,
223
GiggleGitLogPriv *priv;
226
priv = GET_PRIV (job);
228
lines = g_strsplit (output_str, "\n", -1);
229
priv->log = git_log_parse_log (output_str);
234
giggle_git_log_new (GiggleRevision *revision)
236
g_return_val_if_fail (GIGGLE_IS_REVISION (revision), NULL);
238
return g_object_new (GIGGLE_TYPE_GIT_LOG,
239
"revision", revision,
243
G_CONST_RETURN gchar *
244
giggle_git_log_get_log (GiggleGitLog *log)
246
GiggleGitLogPriv *priv;
248
g_return_val_if_fail (GIGGLE_IS_GIT_LOG (log), NULL);
250
priv = GET_PRIV (log);