~ubuntu-branches/ubuntu/lucid/giggle/lucid

« back to all changes in this revision

Viewing changes to src/giggle-git-commit.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrea Corradi
  • Date: 2009-03-30 19:41:43 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090330194143-nyr9ze1xola1shm5
Tags: 0.4.91-1
* New upstream release (Closes:  #519014)
* Use Standards-Version 3.8.1
* Add new Build-Depends
* Update Homepage and watch file
* Update debian/copyright
* Remove patch
* Update path in debian/rules
* Remove defs option from LDFLAGS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * Copyright (C) 2007 Imendio AB
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
 
23
 
#include "giggle-git-commit.h"
24
 
 
25
 
typedef struct GiggleGitCommitPriv GiggleGitCommitPriv;
26
 
 
27
 
struct GiggleGitCommitPriv {
28
 
        GList *files;
29
 
        gchar *log;
30
 
};
31
 
 
32
 
static void     git_commit_finalize            (GObject           *object);
33
 
static void     git_commit_get_property        (GObject           *object,
34
 
                                                guint              param_id,
35
 
                                                GValue            *value,
36
 
                                                GParamSpec        *pspec);
37
 
static void     git_commit_set_property        (GObject           *object,
38
 
                                                guint              param_id,
39
 
                                                const GValue      *value,
40
 
                                                GParamSpec        *pspec);
41
 
 
42
 
static gboolean git_commit_get_command_line    (GiggleJob         *job,
43
 
                                                gchar            **command_line);
44
 
 
45
 
 
46
 
G_DEFINE_TYPE (GiggleGitCommit, giggle_git_commit, GIGGLE_TYPE_JOB)
47
 
 
48
 
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_COMMIT, GiggleGitCommitPriv))
49
 
 
50
 
enum {
51
 
        PROP_0,
52
 
        PROP_FILES,
53
 
        PROP_LOG,
54
 
};
55
 
 
56
 
static void
57
 
giggle_git_commit_class_init (GiggleGitCommitClass *class)
58
 
{
59
 
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
60
 
        GiggleJobClass *job_class    = GIGGLE_JOB_CLASS (class);
61
 
 
62
 
        object_class->finalize     = git_commit_finalize;
63
 
        object_class->get_property = git_commit_get_property;
64
 
        object_class->set_property = git_commit_set_property;
65
 
 
66
 
        job_class->get_command_line = git_commit_get_command_line;
67
 
 
68
 
        g_object_class_install_property (object_class,
69
 
                                         PROP_FILES,
70
 
                                         g_param_spec_pointer ("files",
71
 
                                                               "Files",
72
 
                                                               "List of files to commit",
73
 
                                                               G_PARAM_READWRITE));
74
 
        g_object_class_install_property (object_class,
75
 
                                         PROP_LOG,
76
 
                                         g_param_spec_string ("log",
77
 
                                                              "Log",
78
 
                                                              "Log for the changeset",
79
 
                                                              NULL,
80
 
                                                              G_PARAM_READWRITE));
81
 
 
82
 
        g_type_class_add_private (object_class, sizeof (GiggleGitCommitPriv));
83
 
}
84
 
 
85
 
static void
86
 
giggle_git_commit_init (GiggleGitCommit *dummy)
87
 
{
88
 
}
89
 
 
90
 
static void
91
 
git_commit_finalize (GObject *object)
92
 
{
93
 
        GiggleGitCommitPriv *priv;
94
 
 
95
 
        priv = GET_PRIV (object);
96
 
 
97
 
        g_free (priv->log);
98
 
 
99
 
        g_list_foreach (priv->files, (GFunc) g_free, NULL);
100
 
        g_list_free (priv->files);
101
 
 
102
 
        G_OBJECT_CLASS (giggle_git_commit_parent_class)->finalize (object);
103
 
}
104
 
 
105
 
static void
106
 
git_commit_get_property (GObject    *object,
107
 
                         guint       param_id,
108
 
                         GValue     *value,
109
 
                         GParamSpec *pspec)
110
 
{
111
 
        GiggleGitCommitPriv *priv;
112
 
 
113
 
        priv = GET_PRIV (object);
114
 
 
115
 
        switch (param_id) {
116
 
        case PROP_FILES:
117
 
                g_value_set_pointer (value, priv->files);
118
 
                break;
119
 
        case PROP_LOG:
120
 
                g_value_set_string (value, priv->log);
121
 
                break;
122
 
        default:
123
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
124
 
                break;
125
 
        }
126
 
}
127
 
 
128
 
static void
129
 
git_commit_set_property (GObject      *object,
130
 
                         guint         param_id,
131
 
                         const GValue *value,
132
 
                         GParamSpec   *pspec)
133
 
{
134
 
        GiggleGitCommitPriv *priv;
135
 
 
136
 
        priv = GET_PRIV (object);
137
 
 
138
 
        switch (param_id) {
139
 
        case PROP_FILES:
140
 
                priv->files = g_value_get_pointer (value);
141
 
                break;
142
 
        case PROP_LOG:
143
 
                priv->log = g_value_dup_string (value);
144
 
                break;
145
 
        default:
146
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
147
 
                break;
148
 
        }
149
 
}
150
 
 
151
 
static gboolean
152
 
git_commit_get_command_line (GiggleJob *job, gchar **command_line)
153
 
{
154
 
        GiggleGitCommitPriv *priv;
155
 
        GString             *str;
156
 
        GList               *files;
157
 
        gchar               *escaped;
158
 
 
159
 
        priv = GET_PRIV (job);
160
 
        files = priv->files;
161
 
        str = g_string_new (GIT_COMMAND " commit");
162
 
 
163
 
        if (priv->log) {
164
 
                escaped = g_strescape (priv->log, "\b\f\n\r\t\\");
165
 
        } else {
166
 
                escaped = g_strdup ("");
167
 
        }
168
 
 
169
 
        g_string_append_printf (str, " -m \"%s\"", escaped);
170
 
 
171
 
        if (!files) {
172
 
                g_string_append_printf (str, " -a");
173
 
        } else {
174
 
                while (files) {
175
 
                        g_string_append_printf (str, " %s", (gchar *) files->data);
176
 
                        files = files->next;
177
 
                }
178
 
        }
179
 
 
180
 
        *command_line = g_string_free (str, FALSE);
181
 
        return TRUE;
182
 
}
183
 
 
184
 
GiggleJob *
185
 
giggle_git_commit_new (const gchar *log)
186
 
{
187
 
        return g_object_new (GIGGLE_TYPE_GIT_COMMIT,
188
 
                             "log", log,
189
 
                             NULL);
190
 
}
191
 
 
192
 
void
193
 
giggle_git_commit_set_files (GiggleGitCommit *commit,
194
 
                             GList           *files)
195
 
{
196
 
        g_return_if_fail (GIGGLE_IS_GIT_COMMIT (commit));
197
 
 
198
 
        g_object_set (commit,
199
 
                      "files", files,
200
 
                      NULL);
201
 
}