1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
5 * git-command-test is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * git-command-test is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "git-revision.h"
21 struct _GitRevisionPriv
31 G_DEFINE_TYPE (GitRevision
, git_revision
, G_TYPE_OBJECT
);
34 git_revision_init (GitRevision
*self
)
36 self
->priv
= g_new0 (GitRevisionPriv
, 1);
40 git_revision_finalize (GObject
*object
)
45 self
= GIT_REVISION (object
);
47 g_free (self
->priv
->sha
);
48 g_free (self
->priv
->author
);
49 g_free (self
->priv
->date
);
50 g_free (self
->priv
->short_log
);
52 current_child
= self
->priv
->children
;
56 g_object_unref (current_child
->data
);
57 current_child
= g_list_next (current_child
);
60 g_list_free (self
->priv
->children
);
63 G_OBJECT_CLASS (git_revision_parent_class
)->finalize (object
);
67 git_revision_class_init (GitRevisionClass
*klass
)
69 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
71 object_class
->finalize
= git_revision_finalize
;
75 git_revision_new (void)
77 return g_object_new (GIT_TYPE_REVISION
, NULL
);
81 git_revision_set_sha (GitRevision
*self
, const gchar
*sha
)
83 g_free (self
->priv
->sha
);
84 self
->priv
->sha
= g_strdup (sha
);
88 git_revision_get_sha (GitRevision
*self
)
90 return g_strdup (self
->priv
->sha
);
94 git_revision_get_short_sha (GitRevision
*self
)
96 return g_strndup (self
->priv
->sha
, 7);
100 git_revision_set_author (GitRevision
*self
, const gchar
*author
)
102 g_free (self
->priv
->author
);
103 self
->priv
->author
= g_strdup (author
);
107 git_revision_get_author (GitRevision
*self
)
109 return g_strdup (self
->priv
->author
);
113 git_revision_set_short_log (GitRevision
*self
, const gchar
*short_log
)
115 g_free (self
->priv
->short_log
);
116 self
->priv
->short_log
= g_strdup (short_log
);
118 g_strchug (self
->priv
->short_log
);
122 git_revision_get_short_log (GitRevision
*self
)
124 return g_strdup (self
->priv
->short_log
);
128 git_revision_get_time_format (struct tm
*revision_time
)
133 t1
= mktime ((struct tm
*) revision_time
);
135 /* check whether it's ahead in time */
142 /* check whether it's as fresh as today's bread */
144 tm
= localtime (&t2
);
145 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
150 /* TRANSLATORS: it's a strftime format string */
154 /* check whether it's older than a week */
156 tm
= localtime (&t2
);
157 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
160 t2
-= 60 * 60 * 24 * 6; /* substract 1 week */
164 /* TRANSLATORS: it's a strftime format string */
165 return "%a %I:%M %p";
168 /* check whether it's more recent than the new year hangover */
170 tm
= localtime (&t2
);
171 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= tm
->tm_mon
= 0;
177 /* TRANSLATORS: it's a strftime format string */
178 return "%b %d %I:%M %p";
182 /* TRANSLATORS: it's a strftime format string */
187 git_revision_set_date (GitRevision
*self
, time_t unix_time
)
193 localtime_r (&unix_time
, &time
);
194 format
= git_revision_get_time_format (&time
);
195 strftime (buffer
, sizeof (buffer
), format
, &time
);
197 g_free (self
->priv
->date
);
198 self
->priv
->date
= g_strdup (buffer
);
202 git_revision_get_formatted_date (GitRevision
*self
)
204 return g_strdup (self
->priv
->date
);
208 git_revision_add_child (GitRevision
*self
, GitRevision
*child
)
210 self
->priv
->children
= g_list_prepend (self
->priv
->children
,
211 g_object_ref (child
));
212 git_revision_set_has_parents (child
, TRUE
);
216 git_revision_get_children (GitRevision
*self
)
218 return self
->priv
->children
;
222 git_revision_set_has_parents (GitRevision
*self
, gboolean has_parents
)
224 self
->priv
->has_parents
= has_parents
;
228 git_revision_has_parents (GitRevision
*self
)
230 return self
->priv
->has_parents
;