1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2007 Imendio AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "giggle-git-add-ref.h"
#include <libgiggle/giggle-branch.h>
#include <libgiggle/giggle-revision.h>
#include <libgiggle/giggle-tag.h>
#include <string.h>
typedef struct GiggleGitAddRefPriv GiggleGitAddRefPriv;
struct GiggleGitAddRefPriv {
GiggleRevision *revision;
GiggleRef *ref;
};
static void git_add_ref_finalize (GObject *object);
static void git_add_ref_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void git_add_ref_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static gboolean git_add_ref_get_command_line (GiggleJob *job,
gchar **command_line);
G_DEFINE_TYPE (GiggleGitAddRef, giggle_git_add_ref, GIGGLE_TYPE_JOB)
enum {
PROP_0,
PROP_REF,
PROP_REVISION,
};
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_ADD_REF, GiggleGitAddRefPriv))
static void
giggle_git_add_ref_class_init (GiggleGitAddRefClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GiggleJobClass *job_class = GIGGLE_JOB_CLASS (class);
object_class->finalize = git_add_ref_finalize;
object_class->get_property = git_add_ref_get_property;
object_class->set_property = git_add_ref_set_property;
job_class->get_command_line = git_add_ref_get_command_line;
g_object_class_install_property (
object_class,
PROP_REF,
g_param_spec_object ("ref",
"Ref",
"Reference to create",
GIGGLE_TYPE_REF,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
object_class,
PROP_REVISION,
g_param_spec_object ("revision",
"Revision",
"Base revision for the ref",
GIGGLE_TYPE_REVISION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (GiggleGitAddRefPriv));
}
static void
giggle_git_add_ref_init (GiggleGitAddRef *add_ref)
{
}
static void
git_add_ref_finalize (GObject *object)
{
GiggleGitAddRefPriv *priv;
priv = GET_PRIV (object);
g_object_unref (priv->ref);
g_object_unref (priv->revision);
G_OBJECT_CLASS (giggle_git_add_ref_parent_class)->finalize (object);
}
static void
git_add_ref_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GiggleGitAddRefPriv *priv;
priv = GET_PRIV (object);
switch (param_id) {
case PROP_REF:
g_value_set_object (value, priv->ref);
break;
case PROP_REVISION:
g_value_set_object (value, priv->revision);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
git_add_ref_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GiggleGitAddRefPriv *priv;
priv = GET_PRIV (object);
switch (param_id) {
case PROP_REF:
if (priv->ref)
g_object_unref (priv->ref);
priv->ref = g_value_dup_object (value);
break;
case PROP_REVISION:
if (priv->revision)
g_object_unref (priv->revision);
priv->revision = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static gboolean
git_add_ref_get_command_line (GiggleJob *job, gchar **command_line)
{
GiggleGitAddRefPriv *priv;
priv = GET_PRIV (job);
if (GIGGLE_IS_BRANCH (priv->ref)) {
*command_line = g_strdup_printf (GIT_COMMAND " branch %s %s",
giggle_ref_get_name (priv->ref),
giggle_revision_get_sha (priv->revision));
} else {
*command_line = g_strdup_printf (GIT_COMMAND " tag -a -m \"Tagged %s\" %s %s",
giggle_ref_get_name (priv->ref),
giggle_ref_get_name (priv->ref),
giggle_revision_get_sha (priv->revision));
}
return TRUE;
}
GiggleJob *
giggle_git_add_ref_new (GiggleRef *ref,
GiggleRevision *revision)
{
g_return_val_if_fail (GIGGLE_IS_REF (ref), NULL);
g_return_val_if_fail (GIGGLE_IS_REVISION (revision), NULL);
return g_object_new (GIGGLE_TYPE_GIT_ADD_REF,
"ref", ref,
"revision", revision,
NULL);
}
|