1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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.
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
;
37 static void git_add_ref_finalize (GObject
*object
);
38 static void git_add_ref_get_property (GObject
*object
,
42 static void git_add_ref_set_property (GObject
*object
,
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
)
59 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_ADD_REF, GiggleGitAddRefPriv))
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 (
77 g_param_spec_object ("ref",
79 "Reference to create",
81 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
82 g_object_class_install_property (
85 g_param_spec_object ("revision",
87 "Base revision for the ref",
89 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
91 g_type_class_add_private (object_class
, sizeof (GiggleGitAddRefPriv
));
95 giggle_git_add_ref_init (GiggleGitAddRef
*add_ref
)
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
);
113 git_add_ref_get_property (GObject
*object
,
118 GiggleGitAddRefPriv
*priv
;
120 priv
= GET_PRIV (object
);
124 g_value_set_object (value
, priv
->ref
);
127 g_value_set_object (value
, priv
->revision
);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
136 git_add_ref_set_property (GObject
*object
,
141 GiggleGitAddRefPriv
*priv
;
143 priv
= GET_PRIV (object
);
148 g_object_unref (priv
->ref
);
150 #if GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION > 12
151 priv
->ref
= g_value_dup_object (value
);
153 priv
->ref
= GIGGLE_REF (g_value_dup_object (value
));
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
);
163 priv
->revision
= GIGGLE_REVISION (g_value_dup_object (value
));
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
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
));
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
));
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
,
202 "revision", revision
,