1 /*
2 * ggit-submodule-update-options.c
3 * This file is part of libgit2-glib
4 *
5 * Copyright (C) 2015 - Ignacio Casal Quinteiro
6 *
7 * libgit2-glib is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * libgit2-glib is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "ggit-submodule-update-options.h"
22 #include "ggit-enum-types.h"
23 #include "ggit-checkout-options.h"
24 #include "ggit-fetch-options.h"
25
26 /**
27 * GgitSubmoduleUpdateOptions:
28 *
29 * Represents options for a submodule update.
30 */
31
32 typedef struct _GgitSubmoduleUpdateOptionsPrivate
33 {
34 git_submodule_update_options options;
35
36 GgitCheckoutOptions *checkout_options;
37 GgitFetchOptions *fetch_options;
38 } GgitSubmoduleUpdateOptionsPrivate;
39
40 G_DEFINE_TYPE_WITH_PRIVATE (GgitSubmoduleUpdateOptions, ggit_submodule_update_options, G_TYPE_OBJECT)
41
42 enum
43 {
44 PROP_0,
45 PROP_CHECKOUT_OPTIONS,
46 PROP_FETCH_OPTIONS,
47 };
48
49 static void
ggit_submodule_update_options_finalize(GObject * object)50 ggit_submodule_update_options_finalize (GObject *object)
51 {
52 GgitSubmoduleUpdateOptions *options = GGIT_SUBMODULE_UPDATE_OPTIONS (object);
53 GgitSubmoduleUpdateOptionsPrivate *priv;
54
55 priv = ggit_submodule_update_options_get_instance_private (options);
56
57 g_clear_object (&priv->checkout_options);
58 g_clear_pointer (&priv->fetch_options, ggit_fetch_options_free);
59
60 G_OBJECT_CLASS (ggit_submodule_update_options_parent_class)->finalize (object);
61 }
62
63 static void
ggit_submodule_update_options_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)64 ggit_submodule_update_options_set_property (GObject *object,
65 guint prop_id,
66 const GValue *value,
67 GParamSpec *pspec)
68 {
69 GgitSubmoduleUpdateOptions *options = GGIT_SUBMODULE_UPDATE_OPTIONS (object);
70
71 switch (prop_id)
72 {
73 case PROP_CHECKOUT_OPTIONS:
74 ggit_submodule_update_options_set_checkout_options (options,
75 g_value_get_object (value));
76 break;
77 case PROP_FETCH_OPTIONS:
78 ggit_submodule_update_options_set_fetch_options (options,
79 g_value_get_boxed (value));
80 break;
81 default:
82 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
83 break;
84 }
85 }
86
87 static void
ggit_submodule_update_options_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)88 ggit_submodule_update_options_get_property (GObject *object,
89 guint prop_id,
90 GValue *value,
91 GParamSpec *pspec)
92 {
93 GgitSubmoduleUpdateOptions *options = GGIT_SUBMODULE_UPDATE_OPTIONS (object);
94 GgitSubmoduleUpdateOptionsPrivate *priv;
95
96 priv = ggit_submodule_update_options_get_instance_private (options);
97
98 switch (prop_id)
99 {
100 case PROP_CHECKOUT_OPTIONS:
101 g_value_set_object (value, priv->checkout_options);
102 break;
103 case PROP_FETCH_OPTIONS:
104 g_value_set_boxed (value, priv->fetch_options);
105 break;
106 default:
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
108 break;
109 }
110 }
111
112 static void
ggit_submodule_update_options_class_init(GgitSubmoduleUpdateOptionsClass * klass)113 ggit_submodule_update_options_class_init (GgitSubmoduleUpdateOptionsClass *klass)
114 {
115 GObjectClass *object_class = G_OBJECT_CLASS (klass);
116
117 object_class->finalize = ggit_submodule_update_options_finalize;
118 object_class->get_property = ggit_submodule_update_options_get_property;
119 object_class->set_property = ggit_submodule_update_options_set_property;
120
121 g_object_class_install_property (object_class,
122 PROP_CHECKOUT_OPTIONS,
123 g_param_spec_object ("checkout-options",
124 "Checkout Options",
125 "Checkout options",
126 GGIT_TYPE_CHECKOUT_OPTIONS,
127 G_PARAM_READWRITE |
128 G_PARAM_STATIC_STRINGS));
129
130 g_object_class_install_property (object_class,
131 PROP_FETCH_OPTIONS,
132 g_param_spec_boxed ("fetch-options",
133 "Fetch options",
134 "Fetch options",
135 GGIT_TYPE_FETCH_OPTIONS,
136 G_PARAM_READWRITE |
137 G_PARAM_STATIC_STRINGS));
138 }
139
140 static void
ggit_submodule_update_options_init(GgitSubmoduleUpdateOptions * options)141 ggit_submodule_update_options_init (GgitSubmoduleUpdateOptions *options)
142 {
143 GgitSubmoduleUpdateOptionsPrivate *priv;
144
145 priv = ggit_submodule_update_options_get_instance_private (options);
146
147 git_submodule_update_init_options (&priv->options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION);
148 }
149
150 /**
151 * ggit_submodule_update_options_new:
152 *
153 * Creates a new submodule options object.
154 *
155 * Returns: (transfer full) (nullable): a #GgitSubmoduleUpdateOptions or %NULL.
156 *
157 **/
158 GgitSubmoduleUpdateOptions *
ggit_submodule_update_options_new(void)159 ggit_submodule_update_options_new (void)
160 {
161 return g_object_new (GGIT_TYPE_SUBMODULE_UPDATE_OPTIONS, NULL);
162 }
163
164 const git_submodule_update_options *
_ggit_submodule_update_options_get_submodule_update_options(GgitSubmoduleUpdateOptions * options)165 _ggit_submodule_update_options_get_submodule_update_options (GgitSubmoduleUpdateOptions *options)
166 {
167 if (options != NULL)
168 {
169 GgitSubmoduleUpdateOptionsPrivate *priv;
170
171 priv = ggit_submodule_update_options_get_instance_private (options);
172
173 /* Make sure to synchronize the wrapped checkout options
174 * with the internal checkout options */
175 if (priv->checkout_options)
176 {
177 priv->options.checkout_opts =
178 *_ggit_checkout_options_get_checkout_options (priv->checkout_options);
179 }
180
181 return &priv->options;
182 }
183 else
184 {
185 return NULL;
186 }
187 }
188
189 /**
190 * ggit_submodule_update_options_get_checkout_options:
191 * @options: a #GgitSubmoduleUpdateOptions.
192 *
193 * Get the checkout options.
194 *
195 * Returns: (transfer none) (nullable): a #GgitCheckoutOptions or %NULL.
196 *
197 **/
198 GgitCheckoutOptions *
ggit_submodule_update_options_get_checkout_options(GgitSubmoduleUpdateOptions * options)199 ggit_submodule_update_options_get_checkout_options (GgitSubmoduleUpdateOptions *options)
200 {
201 GgitSubmoduleUpdateOptionsPrivate *priv;
202
203 g_return_val_if_fail (GGIT_IS_SUBMODULE_UPDATE_OPTIONS (options), NULL);
204
205 priv = ggit_submodule_update_options_get_instance_private (options);
206
207 return priv->checkout_options;
208 }
209
210 /**
211 * ggit_submodule_update_options_set_checkout_options:
212 * @options: a #GgitSubmoduleUpdateOptions.
213 * @checkout_options: (allow-none): a #GgitCheckoutOptions.
214 *
215 * Set the checkout options.
216 *
217 **/
218 void
ggit_submodule_update_options_set_checkout_options(GgitSubmoduleUpdateOptions * options,GgitCheckoutOptions * checkout_options)219 ggit_submodule_update_options_set_checkout_options (GgitSubmoduleUpdateOptions *options,
220 GgitCheckoutOptions *checkout_options)
221 {
222 GgitSubmoduleUpdateOptionsPrivate *priv;
223
224 g_return_if_fail (GGIT_IS_SUBMODULE_UPDATE_OPTIONS (options));
225 g_return_if_fail (checkout_options == NULL || GGIT_IS_CHECKOUT_OPTIONS (checkout_options));
226
227 priv = ggit_submodule_update_options_get_instance_private (options);
228
229 if (priv->checkout_options)
230 {
231 g_object_unref (priv->checkout_options);
232 priv->checkout_options = NULL;
233
234 git_checkout_init_options (&priv->options.checkout_opts, GIT_CHECKOUT_OPTIONS_VERSION);
235 }
236
237 if (checkout_options)
238 {
239 priv->checkout_options = g_object_ref (checkout_options);
240 priv->options.checkout_opts = *_ggit_checkout_options_get_checkout_options (priv->checkout_options);
241 }
242
243 g_object_notify (G_OBJECT (options), "checkout-options");
244 }
245
246 /**
247 * ggit_submodule_update_options_get_remote_callbacks:
248 * @options: a #GgitSubmoduleUpdateOptions.
249 *
250 * Gets the fetch options.
251 *
252 * Returns: (transfer none) (nullable): a #GgitFetchOptions or %NULL.
253 *
254 **/
255 GgitFetchOptions *
ggit_submodule_update_options_get_fetch_options(GgitSubmoduleUpdateOptions * options)256 ggit_submodule_update_options_get_fetch_options (GgitSubmoduleUpdateOptions *options)
257 {
258 GgitSubmoduleUpdateOptionsPrivate *priv;
259
260 g_return_val_if_fail (GGIT_IS_SUBMODULE_UPDATE_OPTIONS (options), NULL);
261
262 priv = ggit_submodule_update_options_get_instance_private (options);
263
264 return priv->fetch_options;
265
266 }
267
268 /**
269 * ggit_submodule_update_options_set_fetch_options:
270 * @options: a #GgitSubmoduleUpdateOptions.
271 * @fetch_options: (allow-none): a #GgitFetchOptions.
272 *
273 * Sets the fetch options.
274 **/
275 void
ggit_submodule_update_options_set_fetch_options(GgitSubmoduleUpdateOptions * options,GgitFetchOptions * fetch_options)276 ggit_submodule_update_options_set_fetch_options (GgitSubmoduleUpdateOptions *options,
277 GgitFetchOptions *fetch_options)
278 {
279 GgitSubmoduleUpdateOptionsPrivate *priv;
280
281 g_return_if_fail (GGIT_IS_SUBMODULE_UPDATE_OPTIONS (options));
282
283 priv = ggit_submodule_update_options_get_instance_private (options);
284
285 if (priv->fetch_options)
286 {
287 ggit_fetch_options_free (priv->fetch_options);
288 priv->fetch_options = NULL;
289
290 git_fetch_init_options (&priv->options.fetch_opts, GIT_FETCH_OPTIONS_VERSION);
291 }
292
293 if (fetch_options)
294 {
295 priv->fetch_options = ggit_fetch_options_copy (fetch_options);
296 priv->options.fetch_opts = *_ggit_fetch_options_get_fetch_options (priv->fetch_options);
297 }
298
299 g_object_notify (G_OBJECT (options), "fetch-options");
300 }
301
302 /* ex:set ts=8 noet: */
303