changed the refresh hotkey
[giggle.git] / libgiggle / giggle-git-add-ref.c
blobf096cd5a7653efdcc1f3b3b237cf9bc80217727a
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright (C) 2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <config.h>
23 #include <string.h>
25 #include "giggle-git-add-ref.h"
26 #include "giggle-branch.h"
27 #include "giggle-tag.h"
28 #include "giggle-revision.h"
30 typedef struct GiggleGitAddRefPriv GiggleGitAddRefPriv;
32 struct GiggleGitAddRefPriv {
33 GiggleRevision *revision;
34 GiggleRef *ref;
37 static void git_add_ref_finalize (GObject *object);
38 static void git_add_ref_get_property (GObject *object,
39 guint param_id,
40 GValue *value,
41 GParamSpec *pspec);
42 static void git_add_ref_set_property (GObject *object,
43 guint param_id,
44 const GValue *value,
45 GParamSpec *pspec);
47 static gboolean git_add_ref_get_command_line (GiggleJob *job,
48 gchar **command_line);
51 G_DEFINE_TYPE (GiggleGitAddRef, giggle_git_add_ref, GIGGLE_TYPE_JOB)
53 enum {
54 PROP_0,
55 PROP_REF,
56 PROP_REVISION,
59 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_ADD_REF, GiggleGitAddRefPriv))
62 static void
63 giggle_git_add_ref_class_init (GiggleGitAddRefClass *class)
65 GObjectClass *object_class = G_OBJECT_CLASS (class);
66 GiggleJobClass *job_class = GIGGLE_JOB_CLASS (class);
68 object_class->finalize = git_add_ref_finalize;
69 object_class->get_property = git_add_ref_get_property;
70 object_class->set_property = git_add_ref_set_property;
72 job_class->get_command_line = git_add_ref_get_command_line;
74 g_object_class_install_property (
75 object_class,
76 PROP_REF,
77 g_param_spec_object ("ref",
78 "Ref",
79 "Reference to create",
80 GIGGLE_TYPE_REF,
81 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
82 g_object_class_install_property (
83 object_class,
84 PROP_REVISION,
85 g_param_spec_object ("revision",
86 "Revision",
87 "Base revision for the ref",
88 GIGGLE_TYPE_REVISION,
89 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
91 g_type_class_add_private (object_class, sizeof (GiggleGitAddRefPriv));
94 static void
95 giggle_git_add_ref_init (GiggleGitAddRef *add_ref)
99 static void
100 git_add_ref_finalize (GObject *object)
102 GiggleGitAddRefPriv *priv;
104 priv = GET_PRIV (object);
106 g_object_unref (priv->ref);
107 g_object_unref (priv->revision);
109 G_OBJECT_CLASS (giggle_git_add_ref_parent_class)->finalize (object);
112 static void
113 git_add_ref_get_property (GObject *object,
114 guint param_id,
115 GValue *value,
116 GParamSpec *pspec)
118 GiggleGitAddRefPriv *priv;
120 priv = GET_PRIV (object);
122 switch (param_id) {
123 case PROP_REF:
124 g_value_set_object (value, priv->ref);
125 break;
126 case PROP_REVISION:
127 g_value_set_object (value, priv->revision);
128 break;
129 default:
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
131 break;
135 static void
136 git_add_ref_set_property (GObject *object,
137 guint param_id,
138 const GValue *value,
139 GParamSpec *pspec)
141 GiggleGitAddRefPriv *priv;
143 priv = GET_PRIV (object);
145 switch (param_id) {
146 case PROP_REF:
147 if (priv->ref) {
148 g_object_unref (priv->ref);
150 #if GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION > 12
151 priv->ref = g_value_dup_object (value);
152 #else
153 priv->ref = GIGGLE_REF (g_value_dup_object (value));
154 #endif
155 break;
156 case PROP_REVISION:
157 if (priv->revision) {
158 g_object_unref (priv->revision);
160 #if GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION > 12
161 priv->revision = g_value_dup_object (value);
162 #else
163 priv->revision = GIGGLE_REVISION (g_value_dup_object (value));
164 #endif
165 break;
166 default:
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
168 break;
172 static gboolean
173 git_add_ref_get_command_line (GiggleJob *job, gchar **command_line)
175 GiggleGitAddRefPriv *priv;
177 priv = GET_PRIV (job);
179 if (GIGGLE_IS_BRANCH (priv->ref)) {
180 *command_line = g_strdup_printf (GIT_COMMAND " branch %s %s",
181 giggle_ref_get_name (priv->ref),
182 giggle_revision_get_sha (priv->revision));
183 } else {
184 *command_line = g_strdup_printf (GIT_COMMAND " tag -a -m \"Tagged %s\" %s %s",
185 giggle_ref_get_name (priv->ref),
186 giggle_ref_get_name (priv->ref),
187 giggle_revision_get_sha (priv->revision));
190 return TRUE;
193 GiggleJob *
194 giggle_git_add_ref_new (GiggleRef *ref,
195 GiggleRevision *revision)
197 g_return_val_if_fail (GIGGLE_IS_REF (ref), NULL);
198 g_return_val_if_fail (GIGGLE_IS_REVISION (revision), NULL);
200 return g_object_new (GIGGLE_TYPE_GIT_ADD_REF,
201 "ref", ref,
202 "revision", revision,
203 NULL);