1 /*
2  * ggit-checkout-options.c
3  * This file is part of libgit2-glib
4  *
5  * Copyright (C) 2013 - 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-checkout-options.h"
22 #include "ggit-enum-types.h"
23 #include "ggit-tree.h"
24 #include "ggit-diff-file.h"
25 
26 /**
27  * GgitCheckoutOptions:
28  *
29  * Represents the options used when doign a checkout.
30  */
31 
32 typedef struct _GgitCheckoutOptionsPrivate
33 {
34 	git_checkout_options options;
35 
36 	gchar **paths;
37 	GgitTree *baseline;
38 
39 	gchar *target_directory;
40 	gchar *ancestor_label;
41 	gchar *our_label;
42 	gchar *their_label;
43 } GgitCheckoutOptionsPrivate;
44 
45 G_DEFINE_TYPE_WITH_PRIVATE (GgitCheckoutOptions, ggit_checkout_options, G_TYPE_OBJECT)
46 
47 enum
48 {
49 	PROP_0,
50 	PROP_STRATEGY,
51 	PROP_DISABLE_FILTERS,
52 	PROP_DIR_MODE,
53 	PROP_FILE_MODE,
54 	PROP_FILE_OPEN_FLAGS,
55 	PROP_NOTIFY_FLAGS,
56 	PROP_BASELINE,
57 	PROP_TARGET_DIRECTORY,
58 	PROP_ANCESTOR_LABEL,
59 	PROP_OUR_LABEL,
60 	PROP_THEIR_LABEL
61 };
62 
63 static void
ggit_checkout_options_finalize(GObject * object)64 ggit_checkout_options_finalize (GObject *object)
65 {
66 	GgitCheckoutOptions *options;
67 	GgitCheckoutOptionsPrivate *priv;
68 
69 	options = GGIT_CHECKOUT_OPTIONS (object);
70 	priv = ggit_checkout_options_get_instance_private (options);
71 
72 	g_strfreev (priv->paths);
73 	g_clear_object (&priv->baseline);
74 
75 	g_free (priv->target_directory);
76 	g_free (priv->ancestor_label);
77 	g_free (priv->our_label);
78 	g_free (priv->their_label);
79 
80 	G_OBJECT_CLASS (ggit_checkout_options_parent_class)->finalize (object);
81 }
82 
83 static void
ggit_checkout_options_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)84 ggit_checkout_options_set_property (GObject      *object,
85                                     guint         prop_id,
86                                     const GValue *value,
87                                     GParamSpec   *pspec)
88 {
89 	GgitCheckoutOptions *options = GGIT_CHECKOUT_OPTIONS (object);
90 	GgitCheckoutOptionsPrivate *priv;
91 
92 	priv = ggit_checkout_options_get_instance_private (options);
93 
94 	switch (prop_id)
95 	{
96 	case PROP_STRATEGY:
97 		priv->options.checkout_strategy = g_value_get_flags (value);
98 		break;
99 	case PROP_DISABLE_FILTERS:
100 		priv->options.disable_filters = g_value_get_boolean (value);
101 		break;
102 	case PROP_DIR_MODE:
103 		priv->options.dir_mode = g_value_get_uint (value);
104 		break;
105 	case PROP_FILE_MODE:
106 		priv->options.file_mode = g_value_get_uint (value);
107 		break;
108 	case PROP_FILE_OPEN_FLAGS:
109 		priv->options.file_open_flags = g_value_get_int (value);
110 		break;
111 	case PROP_NOTIFY_FLAGS:
112 		priv->options.notify_flags = g_value_get_flags (value);
113 		break;
114 	case PROP_BASELINE:
115 		ggit_checkout_options_set_baseline (options,
116 		                                    g_value_get_object (value));
117 		break;
118 	case PROP_TARGET_DIRECTORY:
119 		ggit_checkout_options_set_target_directory (options,
120 		                                            g_value_get_string (value));
121 		break;
122 	case PROP_ANCESTOR_LABEL:
123 		ggit_checkout_options_set_ancestor_label (options,
124 		                                          g_value_get_string (value));
125 		break;
126 	case PROP_OUR_LABEL:
127 		ggit_checkout_options_set_our_label (options,
128 		                                     g_value_get_string (value));
129 		break;
130 	case PROP_THEIR_LABEL:
131 		ggit_checkout_options_set_their_label (options,
132 		                                       g_value_get_string (value));
133 		break;
134 	default:
135 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 		break;
137 	}
138 }
139 
140 static void
ggit_checkout_options_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)141 ggit_checkout_options_get_property (GObject    *object,
142                                     guint       prop_id,
143                                     GValue     *value,
144                                     GParamSpec *pspec)
145 {
146 	GgitCheckoutOptions *options = GGIT_CHECKOUT_OPTIONS (object);
147 	GgitCheckoutOptionsPrivate *priv;
148 
149 	priv = ggit_checkout_options_get_instance_private (options);
150 
151 	switch (prop_id)
152 	{
153 	case PROP_STRATEGY:
154 		g_value_set_flags (value, priv->options.checkout_strategy);
155 		break;
156 	case PROP_DISABLE_FILTERS:
157 		g_value_set_boolean (value, priv->options.disable_filters);
158 		break;
159 	case PROP_DIR_MODE:
160 		g_value_set_uint (value, priv->options.dir_mode);
161 		break;
162 	case PROP_FILE_MODE:
163 		g_value_set_uint (value, priv->options.file_mode);
164 		break;
165 	case PROP_FILE_OPEN_FLAGS:
166 		g_value_set_int (value, priv->options.file_open_flags);
167 		break;
168 	case PROP_NOTIFY_FLAGS:
169 		g_value_set_flags (value, priv->options.notify_flags);
170 		break;
171 	case PROP_BASELINE:
172 		g_value_set_object (value, priv->baseline);
173 		break;
174 	case PROP_TARGET_DIRECTORY:
175 		g_value_set_string (value, priv->target_directory);
176 		break;
177 	case PROP_ANCESTOR_LABEL:
178 		g_value_set_string (value, priv->ancestor_label);
179 		break;
180 	case PROP_OUR_LABEL:
181 		g_value_set_string (value, priv->our_label);
182 		break;
183 	case PROP_THEIR_LABEL:
184 		g_value_set_string (value, priv->their_label);
185 		break;
186 	default:
187 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
188 		break;
189 	}
190 }
191 
192 static void
progress_callback_wrapper(const gchar * path,gsize completed_steps,gsize total_steps,gpointer payload)193 progress_callback_wrapper (const gchar *path,
194                            gsize        completed_steps,
195                            gsize        total_steps,
196                            gpointer     payload)
197 {
198 	GgitCheckoutOptions *options = payload;
199 
200 	GGIT_CHECKOUT_OPTIONS_GET_CLASS (options)->progress (options,
201 	                                                     path,
202 	                                                     completed_steps,
203 	                                                     total_steps);
204 }
205 
206 static gint
notify_callback_wrapper(git_checkout_notify_t flags,const gchar * path,const git_diff_file * baseline,const git_diff_file * target,const git_diff_file * workdir,gpointer payload)207 notify_callback_wrapper (git_checkout_notify_t  flags,
208                          const gchar           *path,
209                          const git_diff_file   *baseline,
210                          const git_diff_file   *target,
211                          const git_diff_file   *workdir,
212                          gpointer               payload)
213 {
214 	GgitCheckoutOptions *options = payload;
215 	GgitDiffFile *gbaseline;
216 	GgitDiffFile *gtarget;
217 	GgitDiffFile *gworkdir;
218 	GgitCheckoutNotifyFlags gflags;
219 	gint ret;
220 
221 	gbaseline = _ggit_diff_file_wrap (baseline);
222 	gtarget = _ggit_diff_file_wrap (target);
223 	gworkdir = _ggit_diff_file_wrap (workdir);
224 
225 	gflags = (GgitCheckoutNotifyFlags)flags;
226 
227 	ret = GGIT_CHECKOUT_OPTIONS_GET_CLASS (options)->notify (options,
228 	                                                         gflags,
229 	                                                         path,
230 	                                                         gbaseline,
231 	                                                         gtarget,
232 	                                                         gworkdir);
233 
234 	ggit_diff_file_unref (gbaseline);
235 	ggit_diff_file_unref (gtarget);
236 	ggit_diff_file_unref (gworkdir);
237 
238 	return ret;
239 }
240 
241 static void
ggit_checkout_options_constructed(GObject * object)242 ggit_checkout_options_constructed (GObject *object)
243 {
244 	GgitCheckoutOptions *options = GGIT_CHECKOUT_OPTIONS (object);
245 	GgitCheckoutOptionsPrivate *priv;
246 
247 	priv = ggit_checkout_options_get_instance_private (options);
248 
249 	if (GGIT_CHECKOUT_OPTIONS_GET_CLASS (object)->progress != NULL)
250 	{
251 		priv->options.progress_cb = progress_callback_wrapper;
252 		priv->options.progress_payload = options;
253 	}
254 
255 	if (GGIT_CHECKOUT_OPTIONS_GET_CLASS (object)->notify != NULL)
256 	{
257 		priv->options.notify_cb = notify_callback_wrapper;
258 		priv->options.notify_payload = options;
259 	}
260 }
261 
262 static void
ggit_checkout_options_class_init(GgitCheckoutOptionsClass * klass)263 ggit_checkout_options_class_init (GgitCheckoutOptionsClass *klass)
264 {
265 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
266 	git_checkout_options defaultopts = GIT_CHECKOUT_OPTIONS_INIT;
267 
268 	object_class->finalize = ggit_checkout_options_finalize;
269 
270 	object_class->get_property = ggit_checkout_options_get_property;
271 	object_class->set_property = ggit_checkout_options_set_property;
272 
273 	object_class->constructed = ggit_checkout_options_constructed;
274 
275 	/**
276 	 * GgitCheckoutOptions::strategy: (type GgitCheckoutStrategy):
277 	 *
278 	 * The checkout strategy.
279 	 */
280 	g_object_class_install_property (object_class,
281 	                                 PROP_STRATEGY,
282 	                                 g_param_spec_flags ("strategy",
283 	                                                     "Strategy",
284 	                                                     "Strategy",
285 	                                                     GGIT_TYPE_CHECKOUT_STRATEGY,
286 	                                                     defaultopts.checkout_strategy,
287 	                                                     G_PARAM_READWRITE |
288 	                                                     G_PARAM_STATIC_STRINGS));
289 
290 	g_object_class_install_property (object_class,
291 	                                 PROP_DISABLE_FILTERS,
292 	                                 g_param_spec_boolean ("disable-filters",
293 	                                                       "Disable Filters",
294 	                                                       "Disable filters",
295 	                                                       defaultopts.disable_filters,
296 	                                                       G_PARAM_READWRITE |
297 	                                                       G_PARAM_STATIC_STRINGS));
298 
299 	g_object_class_install_property (object_class,
300 	                                 PROP_DIR_MODE,
301 	                                 g_param_spec_uint ("dir-mode",
302 	                                                    "Dir Mode",
303 	                                                    "Dir mode",
304 	                                                    0,
305 	                                                    G_MAXUINT,
306 	                                                    defaultopts.dir_mode,
307 	                                                    G_PARAM_READWRITE |
308 	                                                    G_PARAM_STATIC_STRINGS));
309 
310 	g_object_class_install_property (object_class,
311 	                                 PROP_FILE_MODE,
312 	                                 g_param_spec_uint ("file-mode",
313 	                                                    "File Mode",
314 	                                                    "File mode",
315 	                                                    0,
316 	                                                    G_MAXUINT,
317 	                                                    defaultopts.file_mode,
318 	                                                    G_PARAM_READWRITE |
319 	                                                    G_PARAM_STATIC_STRINGS));
320 
321 	g_object_class_install_property (object_class,
322 	                                 PROP_FILE_OPEN_FLAGS,
323 	                                 g_param_spec_int ("file-open-flags",
324 	                                                   "File Open Flags",
325 	                                                   "File open flags",
326 	                                                   G_MININT,
327 	                                                   G_MAXINT,
328 	                                                   defaultopts.file_open_flags,
329 	                                                   G_PARAM_READWRITE |
330 	                                                   G_PARAM_STATIC_STRINGS));
331 
332 	/**
333 	 * GgitCheckoutOptions:notify-flags: (type GgitCheckoutNotifyFlags):
334 	 *
335 	 * The checkout notify flags.
336 	 */
337 	g_object_class_install_property (object_class,
338 	                                 PROP_NOTIFY_FLAGS,
339 	                                 g_param_spec_flags ("notify-flags",
340 	                                                     "Notify Flags",
341 	                                                     "Notify flags",
342 	                                                     GGIT_TYPE_CHECKOUT_NOTIFY_FLAGS,
343 	                                                     defaultopts.notify_flags,
344 	                                                     G_PARAM_READWRITE |
345 	                                                     G_PARAM_STATIC_STRINGS));
346 
347 	g_object_class_install_property (object_class,
348 	                                 PROP_BASELINE,
349 	                                 g_param_spec_object ("baseline",
350 	                                                      "Baseline",
351 	                                                      "Baseline",
352 	                                                      GGIT_TYPE_TREE,
353 	                                                      G_PARAM_READWRITE |
354 	                                                      G_PARAM_STATIC_STRINGS));
355 
356 	g_object_class_install_property (object_class,
357 	                                 PROP_TARGET_DIRECTORY,
358 	                                 g_param_spec_string ("target-directory",
359 	                                                      "Target Directory",
360 	                                                      "Target directory",
361 	                                                      defaultopts.target_directory,
362 	                                                      G_PARAM_READWRITE |
363 	                                                      G_PARAM_STATIC_STRINGS));
364 
365 	g_object_class_install_property (object_class,
366 	                                 PROP_ANCESTOR_LABEL,
367 	                                 g_param_spec_string ("ancestor-label",
368 	                                                      "Ancestor Label",
369 	                                                      "Ancestor label",
370 	                                                      defaultopts.ancestor_label,
371 	                                                      G_PARAM_READWRITE |
372 	                                                      G_PARAM_STATIC_STRINGS));
373 
374 	g_object_class_install_property (object_class,
375 	                                 PROP_OUR_LABEL,
376 	                                 g_param_spec_string ("our-label",
377 	                                                      "Our Label",
378 	                                                      "Our label",
379 	                                                      defaultopts.our_label,
380 	                                                      G_PARAM_READWRITE |
381 	                                                      G_PARAM_STATIC_STRINGS));
382 
383 	g_object_class_install_property (object_class,
384 	                                 PROP_THEIR_LABEL,
385 	                                 g_param_spec_string ("their-label",
386 	                                                      "Their Label",
387 	                                                      "Their label",
388 	                                                      defaultopts.their_label,
389 	                                                      G_PARAM_READWRITE |
390 	                                                      G_PARAM_STATIC_STRINGS));
391 }
392 
393 static void
ggit_checkout_options_init(GgitCheckoutOptions * options)394 ggit_checkout_options_init (GgitCheckoutOptions *options)
395 {
396 	GgitCheckoutOptionsPrivate *priv;
397 
398 	priv = ggit_checkout_options_get_instance_private (options);
399 
400 	git_checkout_init_options (&priv->options, GIT_CHECKOUT_OPTIONS_VERSION);
401 }
402 
403 /**
404  * ggit_checkout_options_new:
405  *
406  * Create a new checkout options object.
407  *
408  * Returns: (transfer full) (nullable): a #GgitCheckoutOptions or %NULL.
409  *
410  **/
411 GgitCheckoutOptions *
ggit_checkout_options_new(void)412 ggit_checkout_options_new (void)
413 {
414 	return g_object_new (GGIT_TYPE_CHECKOUT_OPTIONS, NULL);
415 }
416 
417 const git_checkout_options *
_ggit_checkout_options_get_checkout_options(GgitCheckoutOptions * options)418 _ggit_checkout_options_get_checkout_options (GgitCheckoutOptions *options)
419 {
420 	GgitCheckoutOptionsPrivate *priv;
421 
422 	priv = ggit_checkout_options_get_instance_private (options);
423 
424 	return (options != NULL) ? &priv->options : NULL;
425 }
426 
427 /**
428  * ggit_checkout_options_get_strategy:
429  * @options: a #GgitCheckoutOptions.
430  *
431  * Get the checkout strategy.
432  *
433  * Returns: a #GgitCheckoutStrategy.
434  *
435  **/
436 GgitCheckoutStrategy
ggit_checkout_options_get_strategy(GgitCheckoutOptions * options)437 ggit_checkout_options_get_strategy (GgitCheckoutOptions *options)
438 {
439 	GgitCheckoutOptionsPrivate *priv;
440 
441 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
442 
443 	priv = ggit_checkout_options_get_instance_private (options);
444 
445 	return (GgitCheckoutStrategy)priv->options.checkout_strategy;
446 }
447 
448 /**
449  * ggit_checkout_options_set_strategy:
450  * @options: a #GgitCheckoutOptions.
451  * @strategy: a #GgitCheckoutStrategy.
452  *
453  * Set the checkout strategy.
454  *
455  **/
456 void
ggit_checkout_options_set_strategy(GgitCheckoutOptions * options,GgitCheckoutStrategy strategy)457 ggit_checkout_options_set_strategy (GgitCheckoutOptions  *options,
458                                     GgitCheckoutStrategy  strategy)
459 {
460 	GgitCheckoutOptionsPrivate *priv;
461 
462 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
463 
464 	priv = ggit_checkout_options_get_instance_private (options);
465 
466 	priv->options.checkout_strategy = strategy;
467 	g_object_notify (G_OBJECT (options), "strategy");
468 }
469 
470 /**
471  * ggit_checkout_options_get_disable_filters:
472  * @options: a #GgitCheckoutOptions.
473  *
474  * Get whether filters are disabled.
475  *
476  * Returns: %TRUE if filters are disabled, %FALSE otherwise.
477  *
478  **/
479 gboolean
ggit_checkout_options_get_disable_filters(GgitCheckoutOptions * options)480 ggit_checkout_options_get_disable_filters (GgitCheckoutOptions *options)
481 {
482 	GgitCheckoutOptionsPrivate *priv;
483 
484 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), FALSE);
485 
486 	priv = ggit_checkout_options_get_instance_private (options);
487 
488 	return (gboolean)priv->options.disable_filters;
489 }
490 
491 /**
492  * ggit_checkout_options_set_disable_filters:
493  * @options: a #GgitCheckoutOptions.
494  * @disable: disable filters.
495  *
496  * Set whether to disable filters.
497  *
498  **/
499 void
ggit_checkout_options_set_disable_filters(GgitCheckoutOptions * options,gboolean disable)500 ggit_checkout_options_set_disable_filters (GgitCheckoutOptions *options,
501                                            gboolean             disable)
502 {
503 	GgitCheckoutOptionsPrivate *priv;
504 
505 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
506 
507 	priv = ggit_checkout_options_get_instance_private (options);
508 
509 	priv->options.disable_filters = (gboolean)disable;
510 	g_object_notify (G_OBJECT (options), "disable-filters");
511 }
512 
513 /**
514  * ggit_checkout_options_get_dir_mode:
515  * @options: a #GgitCheckoutOptions.
516  *
517  * Get the default checkout directory mode.
518  *
519  * Returns: the default directory mode.
520  *
521  **/
522 guint
ggit_checkout_options_get_dir_mode(GgitCheckoutOptions * options)523 ggit_checkout_options_get_dir_mode (GgitCheckoutOptions *options)
524 {
525 	GgitCheckoutOptionsPrivate *priv;
526 
527 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
528 
529 	priv = ggit_checkout_options_get_instance_private (options);
530 
531 	return (guint)priv->options.dir_mode;
532 }
533 
534 /**
535  * ggit_checkout_options_set_dir_mode:
536  * @options: a #GgitCheckoutOptions.
537  * @dir_mode: the dir mode.
538  *
539  * Set the default checkout directory mode.
540  *
541  **/
542 void
ggit_checkout_options_set_dir_mode(GgitCheckoutOptions * options,guint dir_mode)543 ggit_checkout_options_set_dir_mode (GgitCheckoutOptions *options,
544                                     guint                dir_mode)
545 {
546 	GgitCheckoutOptionsPrivate *priv;
547 
548 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
549 
550 	priv = ggit_checkout_options_get_instance_private (options);
551 
552 	priv->options.dir_mode = dir_mode;
553 	g_object_notify (G_OBJECT (options), "dir-mode");
554 }
555 
556 /**
557  * ggit_checkout_options_get_file_mode:
558  * @options: a #GgitCheckoutOptions.
559  *
560  * Get the default checkout file mode.
561  *
562  * Returns: the default checkout file mode.
563  *
564  **/
565 guint
ggit_checkout_options_get_file_mode(GgitCheckoutOptions * options)566 ggit_checkout_options_get_file_mode (GgitCheckoutOptions *options)
567 {
568 	GgitCheckoutOptionsPrivate *priv;
569 
570 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
571 
572 	priv = ggit_checkout_options_get_instance_private (options);
573 
574 	return (guint)priv->options.file_mode;
575 }
576 
577 /**
578  * ggit_checkout_options_set_file_mode:
579  * @options: a #GgitCheckoutOptions.
580  * @file_mode: the file mode.
581  *
582  * Set the default checkout file mode.
583  *
584  **/
585 void
ggit_checkout_options_set_file_mode(GgitCheckoutOptions * options,guint file_mode)586 ggit_checkout_options_set_file_mode (GgitCheckoutOptions *options,
587                                      guint                file_mode)
588 {
589 	GgitCheckoutOptionsPrivate *priv;
590 
591 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
592 
593 	priv = ggit_checkout_options_get_instance_private (options);
594 
595 	priv->options.file_mode = file_mode;
596 	g_object_notify (G_OBJECT (options), "file-mode");
597 }
598 
599 /**
600  * ggit_checkout_options_get_file_open_flags:
601  * @options: a #GgitCheckoutOptions.
602  *
603  * Get the checkout file open flags. These flags are platform specific,
604  * e.g. on Unix these would include O_CREAT, O_TRUNC, etc.
605  *
606  * Returns: the checkout file open flags.
607  *
608  **/
609 gint
ggit_checkout_options_get_file_open_flags(GgitCheckoutOptions * options)610 ggit_checkout_options_get_file_open_flags (GgitCheckoutOptions *options)
611 {
612 	GgitCheckoutOptionsPrivate *priv;
613 
614 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
615 
616 	priv = ggit_checkout_options_get_instance_private (options);
617 
618 	return priv->options.file_open_flags;
619 }
620 
621 /**
622  * ggit_checkout_options_set_file_open_flags:
623  * @options: a #GgitCheckoutOptions.
624  * @flags: the file open flags.
625  *
626  * Set the checkout file open flags. These flags are platform dependent,
627  * e.g. on Unix use O_CREAT, O_TRUNC, etc.
628  *
629  **/
630 void
ggit_checkout_options_set_file_open_flags(GgitCheckoutOptions * options,gint flags)631 ggit_checkout_options_set_file_open_flags (GgitCheckoutOptions *options,
632                                            gint                 flags)
633 {
634 	GgitCheckoutOptionsPrivate *priv;
635 
636 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
637 
638 	priv = ggit_checkout_options_get_instance_private (options);
639 
640 	priv->options.file_open_flags = flags;
641 	g_object_notify (G_OBJECT (options), "file-open-flags");
642 }
643 
644 /**
645  * ggit_checkout_options_get_notify_flags:
646  * @options: a #GgitCheckoutOptions.
647  *
648  * Get the checkout notify flags.
649  *
650  * Returns: a #GgitCheckoutNotifyFlags.
651  *
652  **/
653 GgitCheckoutNotifyFlags
ggit_checkout_options_get_notify_flags(GgitCheckoutOptions * options)654 ggit_checkout_options_get_notify_flags (GgitCheckoutOptions *options)
655 {
656 	GgitCheckoutOptionsPrivate *priv;
657 
658 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), 0);
659 
660 	priv = ggit_checkout_options_get_instance_private (options);
661 
662 	return (GgitCheckoutNotifyFlags)priv->options.notify_flags;
663 }
664 
665 /**
666  * ggit_checkout_options_set_notify_flags:
667  * @options: a #GgitCheckoutOptions.
668  * @flags: a #GgitCheckoutNotifyFlags.
669  *
670  * Set the checkout notify flags.
671  *
672  **/
673 void
ggit_checkout_options_set_notify_flags(GgitCheckoutOptions * options,GgitCheckoutNotifyFlags flags)674 ggit_checkout_options_set_notify_flags (GgitCheckoutOptions     *options,
675                                         GgitCheckoutNotifyFlags  flags)
676 {
677 	GgitCheckoutOptionsPrivate *priv;
678 
679 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
680 
681 	priv = ggit_checkout_options_get_instance_private (options);
682 
683 	priv->options.notify_flags = flags;
684 	g_object_notify (G_OBJECT (options), "notify-flags");
685 }
686 
687 /**
688  * ggit_checkout_options_get_paths:
689  * @options: a #GgitCheckoutOptions.
690  *
691  * Get the list of file paths to checkout.
692  *
693  * Returns: (array zero-terminated=1) (nullable): a %NULL terminated list of file paths, or %NULL.
694  *
695  **/
696 const gchar * const *
ggit_checkout_options_get_paths(GgitCheckoutOptions * options)697 ggit_checkout_options_get_paths (GgitCheckoutOptions *options)
698 {
699 	GgitCheckoutOptionsPrivate *priv;
700 
701 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
702 
703 	priv = ggit_checkout_options_get_instance_private (options);
704 
705 	return (const gchar * const *)priv->paths;
706 }
707 
708 /**
709  * ggit_checkout_options_set_paths:
710  * @options: a #GgitCheckoutOptions.
711  * @paths: (array zero-terminated=1) (allow-none): a %NULL terminated list of paths.
712  *
713  * Set the list of file paths to checkout. If @paths is %NULL, then all files
714  * will be checked out.
715  *
716  **/
717 void
ggit_checkout_options_set_paths(GgitCheckoutOptions * options,const gchar * const * paths)718 ggit_checkout_options_set_paths (GgitCheckoutOptions *options,
719                                  const gchar * const *paths)
720 {
721 	GgitCheckoutOptionsPrivate *priv;
722 
723 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
724 
725 	priv = ggit_checkout_options_get_instance_private (options);
726 
727 	g_strfreev (priv->paths);
728 
729 	priv->paths = g_strdupv ((gchar **)paths);
730 	priv->options.paths.strings = priv->paths;
731 	priv->options.paths.count = g_strv_length (priv->paths);
732 
733 	g_object_notify (G_OBJECT (options), "paths");
734 }
735 
736 /**
737  * ggit_checkout_options_get_baseline:
738  * @options: a #GgitCheckoutOptions.
739  *
740  * Get the baseline, i.e. the expected content of workdir. Defaults to HEAD.
741  *
742  * Returns: (transfer none) (nullable): a #GgitTree or %NULL.
743  *
744  **/
745 GgitTree *
ggit_checkout_options_get_baseline(GgitCheckoutOptions * options)746 ggit_checkout_options_get_baseline (GgitCheckoutOptions *options)
747 {
748 	GgitCheckoutOptionsPrivate *priv;
749 
750 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
751 
752 	priv = ggit_checkout_options_get_instance_private (options);
753 
754 	return priv->baseline;
755 }
756 
757 /**
758  * ggit_checkout_options_set_baseline:
759  * @options: a #GgitCheckoutOptions.
760  * @tree: (allow-none): a #GgitTree.
761  *
762  * Set the baseline, i.e. the expected content of workdir. If @tree is set
763  * to %NULL, the default (HEAD) will be used as the baseline.
764  *
765  **/
766 void
ggit_checkout_options_set_baseline(GgitCheckoutOptions * options,GgitTree * tree)767 ggit_checkout_options_set_baseline (GgitCheckoutOptions *options,
768                                     GgitTree            *tree)
769 {
770 	GgitCheckoutOptionsPrivate *priv;
771 
772 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
773 	g_return_if_fail (tree == NULL || GGIT_IS_TREE (tree));
774 
775 	priv = ggit_checkout_options_get_instance_private (options);
776 
777 	if (priv->baseline)
778 	{
779 		g_object_unref (priv->baseline);
780 	}
781 
782 	if (tree)
783 	{
784 		priv->baseline = g_object_ref (tree);
785 		priv->options.baseline = _ggit_native_get (tree);
786 	}
787 	else
788 	{
789 		priv->baseline = NULL;
790 		priv->options.baseline = NULL;
791 	}
792 
793 	g_object_notify (G_OBJECT (options), "baseline");
794 }
795 
796 /**
797  * ggit_checkout_options_get_target_directory:
798  * @options: a #GgitCheckoutOptions.
799  *
800  * Get the checkout target directory.
801  *
802  * Returns: (transfer none) (nullable): the checkout target directory or %NULL.
803  *
804  **/
805 const gchar *
ggit_checkout_options_get_target_directory(GgitCheckoutOptions * options)806 ggit_checkout_options_get_target_directory (GgitCheckoutOptions *options)
807 {
808 	GgitCheckoutOptionsPrivate *priv;
809 
810 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
811 
812 	priv = ggit_checkout_options_get_instance_private (options);
813 
814 	return priv->target_directory;
815 }
816 
817 /**
818  * ggit_checkout_options_set_target_directory:
819  * @options: a #GgitCheckoutOptions.
820  * @directory: (allow-none): the target directory.
821  *
822  * Set the checkout target directory.
823  *
824  **/
825 void
ggit_checkout_options_set_target_directory(GgitCheckoutOptions * options,const gchar * directory)826 ggit_checkout_options_set_target_directory (GgitCheckoutOptions *options,
827                                             const gchar         *directory)
828 {
829 	GgitCheckoutOptionsPrivate *priv;
830 
831 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
832 
833 	priv = ggit_checkout_options_get_instance_private (options);
834 
835 	g_free (priv->target_directory);
836 	priv->target_directory = g_strdup (directory);
837 
838 	priv->options.target_directory = priv->target_directory;
839 
840 	g_object_notify (G_OBJECT (options), "target-directory");
841 }
842 
843 /**
844  * ggit_checkout_options_get_ancestor_label:
845  * @options: a #GgitCheckoutOptions.
846  *
847  * Get the checkout ancestor label.
848  *
849  * Returns: (transfer none) (nullable): the checkout ancestor label or %NULL.
850  *
851  **/
852 const gchar *
ggit_checkout_options_get_ancestor_label(GgitCheckoutOptions * options)853 ggit_checkout_options_get_ancestor_label (GgitCheckoutOptions *options)
854 {
855 	GgitCheckoutOptionsPrivate *priv;
856 
857 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
858 
859 	priv = ggit_checkout_options_get_instance_private (options);
860 
861 	return priv->ancestor_label;
862 }
863 
864 /**
865  * ggit_checkout_options_set_ancestor_label:
866  * @options: a #GgitCheckoutOptions.
867  * @label: (allow-none): the ancestor label.
868  *
869  * Set the checkout ancestor label.
870  *
871  **/
872 void
ggit_checkout_options_set_ancestor_label(GgitCheckoutOptions * options,const gchar * label)873 ggit_checkout_options_set_ancestor_label (GgitCheckoutOptions *options,
874                                           const gchar         *label)
875 {
876 	GgitCheckoutOptionsPrivate *priv;
877 
878 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
879 
880 	priv = ggit_checkout_options_get_instance_private (options);
881 
882 	g_free (priv->ancestor_label);
883 	priv->ancestor_label = g_strdup (label);
884 
885 	priv->options.ancestor_label = priv->ancestor_label;
886 
887 	g_object_notify (G_OBJECT (options), "ancestor-label");
888 }
889 
890 /**
891  * ggit_checkout_options_get_our_label:
892  * @options: a #GgitCheckoutOptions.
893  *
894  * Get the checkout our label.
895  *
896  * Returns: (transfer none) (nullable): the checkout our label or %NULL.
897  *
898  **/
899 const gchar *
ggit_checkout_options_get_our_label(GgitCheckoutOptions * options)900 ggit_checkout_options_get_our_label (GgitCheckoutOptions *options)
901 {
902 	GgitCheckoutOptionsPrivate *priv;
903 
904 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
905 
906 	priv = ggit_checkout_options_get_instance_private (options);
907 
908 	return priv->our_label;
909 }
910 
911 /**
912  * ggit_checkout_options_set_our_label:
913  * @options: a #GgitCheckoutOptions.
914  * @label: (allow-none): the our label.
915  *
916  * Set the checkout our label.
917  *
918  **/
919 void
ggit_checkout_options_set_our_label(GgitCheckoutOptions * options,const gchar * label)920 ggit_checkout_options_set_our_label (GgitCheckoutOptions *options,
921                                      const gchar         *label)
922 {
923 	GgitCheckoutOptionsPrivate *priv;
924 
925 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
926 
927 	priv = ggit_checkout_options_get_instance_private (options);
928 
929 	g_free (priv->our_label);
930 	priv->our_label = g_strdup (label);
931 
932 	priv->options.our_label = priv->our_label;
933 
934 	g_object_notify (G_OBJECT (options), "our-label");
935 }
936 
937 /**
938  * ggit_checkout_options_get_their_label:
939  * @options: a #GgitCheckoutOptions.
940  *
941  * Get the checkout their label.
942  *
943  * Returns: (transfer none) (nullable): the checkout their label or %NULL.
944  *
945  **/
946 const gchar *
ggit_checkout_options_get_their_label(GgitCheckoutOptions * options)947 ggit_checkout_options_get_their_label (GgitCheckoutOptions *options)
948 {
949 	GgitCheckoutOptionsPrivate *priv;
950 
951 	g_return_val_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options), NULL);
952 
953 	priv = ggit_checkout_options_get_instance_private (options);
954 
955 	return priv->their_label;
956 }
957 
958 /**
959  * ggit_checkout_options_set_their_label:
960  * @options: a #GgitCheckoutOptions.
961  * @label: (allow-none): the their label.
962  *
963  * Set the checkout their label.
964  *
965  **/
966 void
ggit_checkout_options_set_their_label(GgitCheckoutOptions * options,const gchar * label)967 ggit_checkout_options_set_their_label (GgitCheckoutOptions *options,
968                                        const gchar         *label)
969 {
970 	GgitCheckoutOptionsPrivate *priv;
971 
972 	g_return_if_fail (GGIT_IS_CHECKOUT_OPTIONS (options));
973 
974 	priv = ggit_checkout_options_get_instance_private (options);
975 
976 	g_free (priv->their_label);
977 	priv->their_label = g_strdup (label);
978 
979 	priv->options.their_label = priv->their_label;
980 
981 	g_object_notify (G_OBJECT (options), "their-label");
982 }
983 
984