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-revision.h"
27 struct _GitRevisionPriv
37 G_DEFINE_TYPE (GitRevision
, git_revision
, G_TYPE_OBJECT
);
40 git_revision_init (GitRevision
*self
)
42 self
->priv
= g_new0 (GitRevisionPriv
, 1);
46 git_revision_finalize (GObject
*object
)
51 self
= GIT_REVISION (object
);
53 g_free (self
->priv
->sha
);
54 g_free (self
->priv
->author
);
55 g_free (self
->priv
->date
);
56 g_free (self
->priv
->short_log
);
58 current_child
= self
->priv
->children
;
62 g_object_unref (current_child
->data
);
63 current_child
= g_list_next (current_child
);
66 g_list_free (self
->priv
->children
);
69 G_OBJECT_CLASS (git_revision_parent_class
)->finalize (object
);
73 git_revision_class_init (GitRevisionClass
*klass
)
75 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
77 object_class
->finalize
= git_revision_finalize
;
81 git_revision_new (void)
83 return g_object_new (GIT_TYPE_REVISION
, NULL
);
87 git_revision_set_sha (GitRevision
*self
, const gchar
*sha
)
89 g_free (self
->priv
->sha
);
90 self
->priv
->sha
= g_strdup (sha
);
94 git_revision_get_sha (GitRevision
*self
)
96 return g_strdup (self
->priv
->sha
);
100 git_revision_get_short_sha (GitRevision
*self
)
102 return g_strndup (self
->priv
->sha
, 7);
106 git_revision_set_author (GitRevision
*self
, const gchar
*author
)
108 g_free (self
->priv
->author
);
109 self
->priv
->author
= g_strdup (author
);
113 git_revision_get_author (GitRevision
*self
)
115 return g_strdup (self
->priv
->author
);
119 git_revision_set_short_log (GitRevision
*self
, const gchar
*short_log
)
121 g_free (self
->priv
->short_log
);
122 self
->priv
->short_log
= g_strdup (short_log
);
124 g_strchug (self
->priv
->short_log
);
128 git_revision_get_short_log (GitRevision
*self
)
130 return g_strdup (self
->priv
->short_log
);
134 git_revision_get_time_format (struct tm
*revision_time
)
139 t1
= mktime ((struct tm
*) revision_time
);
141 /* check whether it's ahead in time */
148 /* check whether it's as fresh as today's bread */
150 tm
= localtime (&t2
);
151 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
156 /* TRANSLATORS: it's a strftime format string */
160 /* check whether it's older than a week */
162 tm
= localtime (&t2
);
163 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
166 t2
-= 60 * 60 * 24 * 6; /* substract 1 week */
170 /* TRANSLATORS: it's a strftime format string */
171 return "%a %I:%M %p";
174 /* check whether it's more recent than the new year hangover */
176 tm
= localtime (&t2
);
177 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= tm
->tm_mon
= 0;
183 /* TRANSLATORS: it's a strftime format string */
184 return "%b %d %I:%M %p";
188 /* TRANSLATORS: it's a strftime format string */
193 git_revision_set_date (GitRevision
*self
, time_t unix_time
)
199 localtime_r (&unix_time
, &time
);
200 format
= git_revision_get_time_format (&time
);
201 strftime (buffer
, sizeof (buffer
), format
, &time
);
203 g_free (self
->priv
->date
);
204 self
->priv
->date
= g_strdup (buffer
);
208 git_revision_get_formatted_date (GitRevision
*self
)
210 return g_strdup (self
->priv
->date
);
214 git_revision_add_child (GitRevision
*self
, GitRevision
*child
)
216 self
->priv
->children
= g_list_prepend (self
->priv
->children
,
217 g_object_ref (child
));
218 git_revision_set_has_parents (child
, TRUE
);
222 git_revision_get_children (GitRevision
*self
)
224 return self
->priv
->children
;
228 git_revision_set_has_parents (GitRevision
*self
, gboolean has_parents
)
230 self
->priv
->has_parents
= has_parents
;
234 git_revision_has_parents (GitRevision
*self
)
236 return self
->priv
->has_parents
;