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_set_author (GitRevision
*self
, const gchar
*author
)
96 g_free (self
->priv
->author
);
97 self
->priv
->author
= g_strdup (author
);
101 git_revision_get_author (GitRevision
*self
)
103 return g_strdup (self
->priv
->author
);
107 git_revision_set_short_log (GitRevision
*self
, const gchar
*short_log
)
109 g_free (self
->priv
->short_log
);
110 self
->priv
->short_log
= g_strdup (short_log
);
112 g_strchug (self
->priv
->short_log
);
116 git_revision_get_short_log (GitRevision
*self
)
118 return g_strdup (self
->priv
->short_log
);
122 git_revision_get_time_format (struct tm
*revision_time
)
127 t1
= mktime ((struct tm
*) revision_time
);
129 /* check whether it's ahead in time */
136 /* check whether it's as fresh as today's bread */
138 tm
= localtime (&t2
);
139 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
144 /* TRANSLATORS: it's a strftime format string */
148 /* check whether it's older than a week */
150 tm
= localtime (&t2
);
151 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
154 t2
-= 60 * 60 * 24 * 6; /* substract 1 week */
158 /* TRANSLATORS: it's a strftime format string */
159 return "%a %I:%M %p";
162 /* check whether it's more recent than the new year hangover */
164 tm
= localtime (&t2
);
165 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= tm
->tm_mon
= 0;
171 /* TRANSLATORS: it's a strftime format string */
172 return "%b %d %I:%M %p";
176 /* TRANSLATORS: it's a strftime format string */
181 git_revision_set_date (GitRevision
*self
, time_t unix_time
)
187 localtime_r (&unix_time
, &time
);
188 format
= git_revision_get_time_format (&time
);
189 strftime (buffer
, sizeof (buffer
), format
, &time
);
191 g_free (self
->priv
->date
);
192 self
->priv
->date
= g_strdup (buffer
);
196 git_revision_get_formatted_date (GitRevision
*self
)
198 return g_strdup (self
->priv
->date
);
202 git_revision_add_child (GitRevision
*self
, GitRevision
*child
)
204 self
->priv
->children
= g_list_prepend (self
->priv
->children
,
205 g_object_ref (child
));
206 git_revision_set_has_parents (child
, TRUE
);
210 git_revision_get_children (GitRevision
*self
)
212 return self
->priv
->children
;
216 git_revision_set_has_parents (GitRevision
*self
, gboolean has_parents
)
218 self
->priv
->has_parents
= has_parents
;
222 git_revision_has_parents (GitRevision
*self
)
224 return self
->priv
->has_parents
;