mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-08-25 02:47:01 +00:00
Changed revision from full GObject to mini refcount Boxed type
This commit is contained in:
parent
cdd2a14566
commit
93b84c4366
|
@ -151,7 +151,7 @@ tree_model_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, G
|
|||
switch (column)
|
||||
{
|
||||
case OBJECT_COLUMN:
|
||||
g_value_set_object(value, rv);
|
||||
g_value_set_boxed(value, rv);
|
||||
break;
|
||||
case SUBJECT_COLUMN:
|
||||
g_value_set_string(value, gitg_revision_get_subject(rv));
|
||||
|
@ -281,7 +281,7 @@ do_clear(GitgRepository *repository, gboolean emit)
|
|||
}
|
||||
|
||||
gtk_tree_path_prev(path);
|
||||
g_object_unref(repository->priv->storage[i]);
|
||||
gitg_revision_unref(repository->priv->storage[i]);
|
||||
}
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
|
@ -421,7 +421,7 @@ on_loader_update(GitgRunner *object, gchar **buffer, GitgRepository *self)
|
|||
|
||||
gitg_repository_add(self, rv, NULL);
|
||||
|
||||
g_object_unref(rv);
|
||||
gitg_revision_unref(rv);
|
||||
g_strfreev(components);
|
||||
}
|
||||
}
|
||||
|
@ -580,12 +580,11 @@ gitg_repository_add(GitgRepository *self, GitgRevision *obj, GtkTreeIter *iter)
|
|||
|
||||
/* validate our parameters */
|
||||
g_return_if_fail(GITG_IS_REPOSITORY(self));
|
||||
g_return_if_fail(GITG_IS_REVISION(obj));
|
||||
|
||||
grow_storage(self, 1);
|
||||
|
||||
/* put this object in our data storage */
|
||||
self->priv->storage[self->priv->size++] = g_object_ref(obj);
|
||||
self->priv->storage[self->priv->size++] = gitg_revision_ref(obj);
|
||||
|
||||
g_hash_table_insert(self->priv->hashtable, (gpointer)gitg_revision_get_hash(obj), GUINT_TO_POINTER(self->priv->size - 1));
|
||||
|
||||
|
@ -630,8 +629,6 @@ gitg_repository_find_by_hash(GitgRepository *store, gchar const *hash, GtkTreeIt
|
|||
gboolean
|
||||
gitg_repository_find(GitgRepository *store, GitgRevision *revision, GtkTreeIter *iter)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), FALSE);
|
||||
|
||||
return gitg_repository_find_by_hash(store, gitg_revision_get_hash(revision), iter);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "gitg-revision-tree-store.h"
|
||||
#include "gitg-runner.h"
|
||||
#include "gitg-utils.h"
|
||||
#include "gitg-revision.h"
|
||||
|
||||
#define GITG_REVISION_TREE_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GITG_TYPE_REVISION_TREE, GitgRevisionTreeViewPrivate))
|
||||
|
||||
|
@ -51,7 +52,7 @@ gitg_revision_tree_view_finalize(GObject *object)
|
|||
GitgRevisionTreeView *self = GITG_REVISION_TREE_VIEW(object);
|
||||
|
||||
if (self->priv->revision)
|
||||
g_object_unref(self->priv->revision);
|
||||
gitg_revision_unref(self->priv->revision);
|
||||
|
||||
if (self->priv->repository)
|
||||
g_object_unref(self->priv->repository);
|
||||
|
@ -78,7 +79,7 @@ gitg_revision_tree_view_get_property(GObject *object, guint prop_id, GValue *val
|
|||
switch (prop_id)
|
||||
{
|
||||
case PROP_REVISION:
|
||||
g_value_set_object(value, self->priv->revision);
|
||||
g_value_set_boxed(value, self->priv->revision);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
|
@ -96,7 +97,7 @@ gitg_revision_tree_view_set_property(GObject *object, guint prop_id, const GValu
|
|||
case PROP_REPOSITORY:
|
||||
if (self->priv->revision)
|
||||
{
|
||||
g_object_unref(self->priv->revision);
|
||||
gitg_revision_unref(self->priv->revision);
|
||||
self->priv->revision = NULL;
|
||||
g_object_notify(object, "revision");
|
||||
}
|
||||
|
@ -109,9 +110,9 @@ gitg_revision_tree_view_set_property(GObject *object, guint prop_id, const GValu
|
|||
break;
|
||||
case PROP_REVISION:
|
||||
if (self->priv->revision)
|
||||
g_object_unref(self->priv->revision);
|
||||
gitg_revision_unref(self->priv->revision);
|
||||
|
||||
self->priv->revision = g_value_dup_object(value);
|
||||
self->priv->revision = g_value_dup_boxed(value);
|
||||
gitg_revision_tree_view_reload(self);
|
||||
break;
|
||||
default:
|
||||
|
@ -443,7 +444,7 @@ gitg_revision_tree_view_class_init(GitgRevisionTreeViewClass *klass)
|
|||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(object_class, PROP_REVISION,
|
||||
g_param_spec_object ("revision",
|
||||
g_param_spec_boxed ("revision",
|
||||
"REVISION",
|
||||
"The revision",
|
||||
GITG_TYPE_REVISION,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "gitg-revision.h"
|
||||
#include "gitg-utils.h"
|
||||
|
||||
#define GITG_REVISION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GITG_TYPE_REVISION, GitgRevisionPrivate))
|
||||
|
||||
struct _GitgRevisionPrivate
|
||||
struct _GitgRevision
|
||||
{
|
||||
gint refcount;
|
||||
|
||||
Hash hash;
|
||||
gchar *author;
|
||||
gchar *subject;
|
||||
|
@ -17,44 +17,40 @@ struct _GitgRevisionPrivate
|
|||
gint64 timestamp;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(GitgRevision, gitg_revision, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
free_lanes(GitgRevision *rv)
|
||||
{
|
||||
g_slist_foreach(rv->priv->lanes, (GFunc)gitg_lane_free, NULL);
|
||||
g_slist_free(rv->priv->lanes);
|
||||
rv->priv->lanes = NULL;
|
||||
g_slist_foreach(rv->lanes, (GFunc)gitg_lane_free, NULL);
|
||||
g_slist_free(rv->lanes);
|
||||
rv->lanes = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gitg_revision_finalize(GObject *object)
|
||||
gitg_revision_finalize(GitgRevision *revision)
|
||||
{
|
||||
GitgRevision *rv = GITG_REVISION(object);
|
||||
g_free(revision->author);
|
||||
g_free(revision->subject);
|
||||
g_free(revision->parents);
|
||||
|
||||
g_free(rv->priv->author);
|
||||
g_free(rv->priv->subject);
|
||||
g_free(rv->priv->parents);
|
||||
free_lanes(revision);
|
||||
|
||||
free_lanes(rv);
|
||||
|
||||
G_OBJECT_CLASS(gitg_revision_parent_class)->finalize(object);
|
||||
g_slice_free(GitgRevision, revision);
|
||||
}
|
||||
|
||||
static void
|
||||
gitg_revision_class_init(GitgRevisionClass *klass)
|
||||
GitgRevision *
|
||||
gitg_revision_ref(GitgRevision *revision)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
object_class->finalize = gitg_revision_finalize;
|
||||
|
||||
g_type_class_add_private(object_class, sizeof(GitgRevisionPrivate));
|
||||
g_atomic_int_inc(&revision->refcount);
|
||||
return revision;
|
||||
}
|
||||
|
||||
static void
|
||||
gitg_revision_init(GitgRevision *self)
|
||||
void
|
||||
gitg_revision_unref(GitgRevision *revision)
|
||||
{
|
||||
self->priv = GITG_REVISION_GET_PRIVATE(self);
|
||||
if (!g_atomic_int_dec_and_test(&revision->refcount))
|
||||
return;
|
||||
|
||||
gitg_revision_finalize(revision);
|
||||
}
|
||||
|
||||
GitgRevision *gitg_revision_new(gchar const *sha,
|
||||
|
@ -63,23 +59,25 @@ GitgRevision *gitg_revision_new(gchar const *sha,
|
|||
gchar const *parents,
|
||||
gint64 timestamp)
|
||||
{
|
||||
GitgRevision *rv = g_object_new(GITG_TYPE_REVISION, NULL);
|
||||
GitgRevision *rv = g_slice_new0 (GitgRevision);
|
||||
|
||||
gitg_utils_sha1_to_hash(sha, rv->priv->hash);
|
||||
rv->priv->author = g_strdup(author);
|
||||
rv->priv->subject = g_strdup(subject);
|
||||
rv->priv->timestamp = timestamp;
|
||||
rv->refcount = 1;
|
||||
|
||||
gitg_utils_sha1_to_hash(sha, rv->hash);
|
||||
rv->author = g_strdup(author);
|
||||
rv->subject = g_strdup(subject);
|
||||
rv->timestamp = timestamp;
|
||||
|
||||
gchar **shas = g_strsplit(parents, " ", 0);
|
||||
gint num = g_strv_length(shas);
|
||||
rv->priv->parents = g_new(Hash, num + 1);
|
||||
rv->parents = g_new(Hash, num + 1);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < num; ++i)
|
||||
gitg_utils_sha1_to_hash(shas[i], rv->priv->parents[i]);
|
||||
gitg_utils_sha1_to_hash(shas[i], rv->parents[i]);
|
||||
|
||||
g_strfreev(shas);
|
||||
rv->priv->num_parents = num;
|
||||
rv->num_parents = num;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -87,38 +85,32 @@ GitgRevision *gitg_revision_new(gchar const *sha,
|
|||
gchar const *
|
||||
gitg_revision_get_author(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
return revision->priv->author;
|
||||
return revision->author;
|
||||
}
|
||||
|
||||
gchar const *
|
||||
gitg_revision_get_subject(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
return revision->priv->subject;
|
||||
return revision->subject;
|
||||
}
|
||||
|
||||
guint64
|
||||
gitg_revision_get_timestamp(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), 0);
|
||||
return revision->priv->timestamp;
|
||||
return revision->timestamp;
|
||||
}
|
||||
|
||||
gchar const *
|
||||
gitg_revision_get_hash(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
return revision->priv->hash;
|
||||
return revision->hash;
|
||||
}
|
||||
|
||||
gchar *
|
||||
gitg_revision_get_sha1(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
|
||||
char res[40];
|
||||
gitg_utils_hash_to_sha1(revision->priv->hash, res);
|
||||
gitg_utils_hash_to_sha1(revision->hash, res);
|
||||
|
||||
return g_strndup(res, 40);
|
||||
}
|
||||
|
@ -126,31 +118,27 @@ gitg_revision_get_sha1(GitgRevision *revision)
|
|||
Hash *
|
||||
gitg_revision_get_parents_hash(GitgRevision *revision, guint *num_parents)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
|
||||
if (num_parents)
|
||||
*num_parents = revision->priv->num_parents;
|
||||
*num_parents = revision->num_parents;
|
||||
|
||||
return revision->priv->parents;
|
||||
return revision->parents;
|
||||
}
|
||||
|
||||
gchar **
|
||||
gitg_revision_get_parents(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
|
||||
gchar **ret = g_new(gchar *, revision->priv->num_parents + 1);
|
||||
gchar **ret = g_new(gchar *, revision->num_parents + 1);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < revision->priv->num_parents; ++i)
|
||||
for (i = 0; i < revision->num_parents; ++i)
|
||||
{
|
||||
ret[i] = g_new(gchar, 41);
|
||||
gitg_utils_hash_to_sha1(revision->priv->parents[i], ret[i]);
|
||||
gitg_utils_hash_to_sha1(revision->parents[i], ret[i]);
|
||||
|
||||
ret[i][40] = '\0';
|
||||
}
|
||||
|
||||
ret[revision->priv->num_parents] = NULL;
|
||||
ret[revision->num_parents] = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -158,29 +146,38 @@ gitg_revision_get_parents(GitgRevision *revision)
|
|||
GSList *
|
||||
gitg_revision_get_lanes(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), NULL);
|
||||
return g_slist_copy(revision->priv->lanes);
|
||||
return g_slist_copy(revision->lanes);
|
||||
}
|
||||
|
||||
void
|
||||
gitg_revision_set_lanes(GitgRevision *revision, GSList *lanes)
|
||||
{
|
||||
g_return_if_fail(GITG_IS_REVISION(revision));
|
||||
|
||||
free_lanes(revision);
|
||||
revision->priv->lanes = lanes;
|
||||
revision->lanes = lanes;
|
||||
}
|
||||
|
||||
gint8
|
||||
gitg_revision_get_mylane(GitgRevision *revision)
|
||||
{
|
||||
g_return_val_if_fail(GITG_IS_REVISION(revision), -1);
|
||||
return revision->priv->mylane;
|
||||
return revision->mylane;
|
||||
}
|
||||
|
||||
void
|
||||
gitg_revision_set_mylane(GitgRevision *revision, gint8 mylane)
|
||||
{
|
||||
g_return_if_fail(GITG_IS_REVISION(revision));
|
||||
revision->priv->mylane = mylane;
|
||||
revision->mylane = mylane;
|
||||
}
|
||||
|
||||
GType
|
||||
gitg_revision_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (!our_type)
|
||||
our_type = g_boxed_type_register_static(
|
||||
"GitgRevision",
|
||||
(GBoxedCopyFunc)gitg_revision_ref,
|
||||
(GBoxedFreeFunc)gitg_revision_unref);
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
|
|
@ -7,28 +7,12 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
#define GITG_TYPE_REVISION (gitg_revision_get_type ())
|
||||
#define GITG_REVISION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_REVISION, GitgRevision))
|
||||
#define GITG_REVISION_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_REVISION, GitgRevision const))
|
||||
#define GITG_REVISION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_REVISION, GitgRevisionClass))
|
||||
#define GITG_IS_REVISION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_REVISION))
|
||||
#define GITG_IS_REVISION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_REVISION))
|
||||
#define GITG_REVISION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_REVISION, GitgRevisionClass))
|
||||
#define GITG_REVISION(obj) ((GitgRevision *)obj)
|
||||
#define GITG_REVISION_CONST(obj) ((GitgRevision const *)obj)
|
||||
|
||||
#include "gitg-types.h"
|
||||
|
||||
typedef struct _GitgRevision GitgRevision;
|
||||
typedef struct _GitgRevisionClass GitgRevisionClass;
|
||||
typedef struct _GitgRevisionPrivate GitgRevisionPrivate;
|
||||
|
||||
struct _GitgRevision {
|
||||
GObject parent;
|
||||
|
||||
GitgRevisionPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GitgRevisionClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType gitg_revision_get_type (void) G_GNUC_CONST;
|
||||
|
||||
|
@ -50,6 +34,9 @@ void gitg_revision_set_lanes(GitgRevision *revision, GSList *lanes);
|
|||
gint8 gitg_revision_get_mylane(GitgRevision *revision);
|
||||
void gitg_revision_set_mylane(GitgRevision *revision, gint8 mylane);
|
||||
|
||||
GitgRevision *gitg_revision_ref(GitgRevision *revision);
|
||||
void gitg_revision_unref(GitgRevision *revision);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GITG_REVISION_H__ */
|
||||
|
|
|
@ -110,7 +110,7 @@ search_hash_equal_func(GtkTreeModel *model, gchar const *key, GtkTreeIter *iter)
|
|||
gboolean ret = strncmp(sha, key, strlen(key)) != 0;
|
||||
|
||||
g_free(sha);
|
||||
g_object_unref(rv);
|
||||
gitg_revision_unref(rv);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -218,14 +218,14 @@ on_renderer_path(GtkTreeViewColumn *column, GitgCellRendererPath *renderer, GtkT
|
|||
gtk_tree_model_get(model, &iter1, 0, &next, -1);
|
||||
|
||||
next_lanes = gitg_revision_get_lanes(next);
|
||||
g_object_unref(next);
|
||||
gitg_revision_unref(next);
|
||||
}
|
||||
|
||||
GSList *labels = gitg_repository_get_refs_for_hash(GITG_REPOSITORY(model), gitg_revision_get_hash(rv));
|
||||
|
||||
g_object_set(renderer, "lane", gitg_revision_get_mylane(rv), "lanes", gitg_revision_get_lanes(rv), "next_lanes", next_lanes, "labels", labels, NULL);
|
||||
|
||||
g_object_unref(rv);
|
||||
gitg_revision_unref(rv);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
Loading…
Reference in a new issue