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
)
50 self
= GIT_REVISION (object
);
52 g_free (self
->priv
->sha
);
53 g_free (self
->priv
->author
);
54 g_free (self
->priv
->date
);
55 g_free (self
->priv
->short_log
);
57 g_list_free (self
->priv
->children
);
60 G_OBJECT_CLASS (git_revision_parent_class
)->finalize (object
);
64 git_revision_class_init (GitRevisionClass
*klass
)
66 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
68 object_class
->finalize
= git_revision_finalize
;
72 git_revision_new (void)
74 return g_object_new (GIT_TYPE_REVISION
, NULL
);
78 git_revision_set_sha (GitRevision
*self
, const gchar
*sha
)
80 g_free (self
->priv
->sha
);
81 self
->priv
->sha
= g_strdup (sha
);
85 git_revision_get_sha (GitRevision
*self
)
87 return g_strdup (self
->priv
->sha
);
91 git_revision_get_short_sha (GitRevision
*self
)
93 return g_strndup (self
->priv
->sha
, 7);
97 git_revision_set_author (GitRevision
*self
, const gchar
*author
)
99 g_free (self
->priv
->author
);
100 self
->priv
->author
= g_strdup (author
);
104 git_revision_get_author (GitRevision
*self
)
106 return g_strdup (self
->priv
->author
);
110 git_revision_set_short_log (GitRevision
*self
, const gchar
*short_log
)
112 g_free (self
->priv
->short_log
);
113 self
->priv
->short_log
= g_strdup (short_log
);
115 g_strchug (self
->priv
->short_log
);
119 git_revision_get_short_log (GitRevision
*self
)
121 return g_strdup (self
->priv
->short_log
);
125 git_revision_get_time_format (struct tm
*revision_time
)
130 t1
= mktime ((struct tm
*) revision_time
);
132 /* check whether it's ahead in time */
139 /* check whether it's as fresh as today's bread */
141 tm
= localtime (&t2
);
142 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
147 /* TRANSLATORS: it's a strftime format string */
151 /* check whether it's older than a week */
153 tm
= localtime (&t2
);
154 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= 0;
157 t2
-= 60 * 60 * 24 * 6; /* substract 1 week */
161 /* TRANSLATORS: it's a strftime format string */
162 return "%a %I:%M %p";
165 /* check whether it's more recent than the new year hangover */
167 tm
= localtime (&t2
);
168 tm
->tm_sec
= tm
->tm_min
= tm
->tm_hour
= tm
->tm_mon
= 0;
174 /* TRANSLATORS: it's a strftime format string */
175 return "%b %d %I:%M %p";
179 /* TRANSLATORS: it's a strftime format string */
184 git_revision_set_date (GitRevision
*self
, time_t unix_time
)
190 localtime_r (&unix_time
, &time
);
191 format
= git_revision_get_time_format (&time
);
192 strftime (buffer
, sizeof (buffer
), format
, &time
);
194 g_free (self
->priv
->date
);
195 self
->priv
->date
= g_strdup (buffer
);
199 git_revision_get_formatted_date (GitRevision
*self
)
201 return g_strdup (self
->priv
->date
);
205 git_revision_add_child (GitRevision
*self
, GitRevision
*child
)
207 self
->priv
->children
= g_list_prepend (self
->priv
->children
,
209 git_revision_set_has_parents (child
, TRUE
);
213 git_revision_get_children (GitRevision
*self
)
215 return self
->priv
->children
;
219 git_revision_set_has_parents (GitRevision
*self
, gboolean has_parents
)
221 self
->priv
->has_parents
= has_parents
;
225 git_revision_has_parents (GitRevision
*self
)
227 return self
->priv
->has_parents
;