1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2007 <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 "svn-log-entry.h"
27 struct _SvnLogEntryPriv
36 G_DEFINE_TYPE (SvnLogEntry
, svn_log_entry
, G_TYPE_OBJECT
);
39 svn_log_entry_init (SvnLogEntry
*self
)
41 self
->priv
= g_new0 (SvnLogEntryPriv
, 1);
45 svn_log_entry_finalize (GObject
*object
)
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
);
57 G_OBJECT_CLASS (svn_log_entry_parent_class
)->finalize (object
);
61 svn_log_entry_class_init (SvnLogEntryClass
*klass
)
63 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
65 object_class
->finalize
= svn_log_entry_finalize
;
69 strip_whitespace (gchar
*buffer
)
77 if (g_ascii_isspace (*buffer_pos
))
87 svn_log_entry_new (gchar
*author
, gchar
*date
, glong revision
, gchar
*log
)
90 gchar
*log_filtered
; /* No leading whitespace */
92 size_t first_newline_pos
;
93 gchar
*first_log_line
;
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');
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
);
124 short_log
= g_strdup (log_filtered
);
126 self
->priv
->short_log
= g_strdup (short_log
);
133 svn_log_entry_destroy (SvnLogEntry
*self
)
135 g_object_unref (self
);
139 svn_log_entry_get_author (SvnLogEntry
*self
)
141 return g_strdup (self
->priv
->author
);
145 svn_log_entry_get_date (SvnLogEntry
*self
)
147 return g_strdup (self
->priv
->date
);
151 svn_log_entry_get_revision (SvnLogEntry
*self
)
153 return self
->priv
->revision
;
157 svn_log_entry_get_short_log (SvnLogEntry
*self
)
159 return g_strdup (self
->priv
->short_log
);
163 svn_log_entry_get_full_log (SvnLogEntry
*self
)
165 return g_strdup (self
->priv
->log
);