Updated Spanish translation
[anjuta-git-plugin.git] / plugins / subversion / svn-log-entry.c
blob76a2dd26aaf0e16b51c25ee9ac35523ef88b43c4
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-entry.h"
27 struct _SvnLogEntryPriv
29 gchar *author;
30 gchar *date;
31 glong revision;
32 gchar *log;
33 gchar *short_log;
36 G_DEFINE_TYPE (SvnLogEntry, svn_log_entry, G_TYPE_OBJECT);
38 static void
39 svn_log_entry_init (SvnLogEntry *self)
41 self->priv = g_new0 (SvnLogEntryPriv, 1);
44 static void
45 svn_log_entry_finalize (GObject *object)
47 SvnLogEntry *self;
49 self = SVN_LOG_ENTRY (object);
51 g_free (self->priv->author);
52 g_free (self->priv->date);
53 g_free (self->priv->log);
54 g_free (self->priv->short_log);
55 g_free (self->priv);
57 G_OBJECT_CLASS (svn_log_entry_parent_class)->finalize (object);
60 static void
61 svn_log_entry_class_init (SvnLogEntryClass *klass)
63 GObjectClass *object_class = G_OBJECT_CLASS (klass);
65 object_class->finalize = svn_log_entry_finalize;
68 static gchar *
69 strip_whitespace (gchar *buffer)
71 gchar *buffer_pos;
73 buffer_pos = buffer;
75 while (buffer_pos)
77 if (g_ascii_isspace (*buffer_pos))
78 buffer_pos++;
79 else
80 break;
83 return buffer_pos;
86 SvnLogEntry *
87 svn_log_entry_new (gchar *author, gchar *date, glong revision, gchar *log)
89 SvnLogEntry *self;
90 gchar *log_filtered; /* No leading whitespace */
91 gchar *first_newline;
92 size_t first_newline_pos;
93 gchar *first_log_line;
94 gchar *short_log;
96 self = g_object_new (SVN_TYPE_LOG_ENTRY, NULL);
97 self->priv->author = g_strdup (author);
98 self->priv->date = g_strdup (date);
99 self->priv->revision = revision;
100 self->priv->log = g_strdup (log);
102 /* Now create the "short log", or a one-line summary of a log.
103 * This is just the first line of a commit log message. If there is more
104 * than one line to a message, take the first line and put an ellipsis
105 * after it to create the short log. Otherwise, the short log is just a
106 * copy of the log messge. */
107 log_filtered = strip_whitespace (log);
108 first_newline = strchr (log_filtered, '\n');
110 if (first_newline)
112 first_newline_pos = first_newline - log_filtered;
114 if (first_newline_pos < (strlen (log_filtered) - 1))
116 first_log_line = g_strndup (log_filtered, first_newline_pos);
117 short_log = g_strconcat (first_log_line, " ...", NULL);
118 g_free (first_log_line);
120 else /* There could be a newline and nothing after it... */
121 short_log = g_strndup (log_filtered, first_newline_pos);
123 else
124 short_log = g_strdup (log_filtered);
126 self->priv->short_log = g_strdup (short_log);
127 g_free (short_log);
129 return self;
132 void
133 svn_log_entry_destroy (SvnLogEntry *self)
135 g_object_unref (self);
138 gchar *
139 svn_log_entry_get_author (SvnLogEntry *self)
141 return g_strdup (self->priv->author);
144 gchar *
145 svn_log_entry_get_date (SvnLogEntry *self)
147 return g_strdup (self->priv->date);
150 glong
151 svn_log_entry_get_revision (SvnLogEntry *self)
153 return self->priv->revision;
156 gchar *
157 svn_log_entry_get_short_log (SvnLogEntry *self)
159 return g_strdup (self->priv->short_log);
162 gchar *
163 svn_log_entry_get_full_log (SvnLogEntry *self)
165 return g_strdup (self->priv->log);