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.
23
#include "giggle-git-list-files.h"
25
typedef struct GiggleGitListFilesPriv GiggleGitListFilesPriv;
27
struct GiggleGitListFilesPriv {
31
static void git_list_files_finalize (GObject *object);
33
static gboolean git_list_files_get_command_line (GiggleJob *job,
34
gchar **command_line);
35
static void git_list_files_handle_output (GiggleJob *job,
36
const gchar *output_str,
39
G_DEFINE_TYPE (GiggleGitListFiles, giggle_git_list_files, GIGGLE_TYPE_JOB)
41
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_LIST_FILES, GiggleGitListFilesPriv))
44
giggle_git_list_files_class_init (GiggleGitListFilesClass *class)
46
GObjectClass *object_class = G_OBJECT_CLASS (class);
47
GiggleJobClass *job_class = GIGGLE_JOB_CLASS (class);
49
object_class->finalize = git_list_files_finalize;
51
job_class->get_command_line = git_list_files_get_command_line;
52
job_class->handle_output = git_list_files_handle_output;
54
g_type_class_add_private (object_class, sizeof (GiggleGitListFilesPriv));
58
giggle_git_list_files_init (GiggleGitListFiles *list_files)
60
GiggleGitListFilesPriv *priv;
62
priv = GET_PRIV (list_files);
64
priv->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
68
git_list_files_finalize (GObject *object)
70
GiggleGitListFilesPriv *priv;
72
priv = GET_PRIV (object);
74
g_hash_table_destroy (priv->files);
76
G_OBJECT_CLASS (giggle_git_list_files_parent_class)->finalize (object);
80
git_list_files_get_command_line (GiggleJob *job, gchar **command_line)
82
*command_line = g_strdup_printf (GIT_COMMAND " ls-files "
83
"--cached --deleted --modified --others "
84
"--killed -t --full-name");
89
static GiggleGitListFilesStatus
90
git_list_files_char_to_status (gchar status)
94
return GIGGLE_GIT_FILE_STATUS_CACHED;
96
return GIGGLE_GIT_FILE_STATUS_UNMERGED;
98
return GIGGLE_GIT_FILE_STATUS_DELETED;
100
return GIGGLE_GIT_FILE_STATUS_CHANGED;
102
return GIGGLE_GIT_FILE_STATUS_KILLED;
104
return GIGGLE_GIT_FILE_STATUS_OTHER;
106
g_assert_not_reached ();
107
return GIGGLE_GIT_FILE_STATUS_OTHER;
112
git_list_files_handle_output (GiggleJob *job,
113
const gchar *output_str,
116
GiggleGitListFilesPriv *priv;
117
GiggleGitListFilesStatus status;
123
priv = GET_PRIV (job);
124
lines = g_strsplit (output_str, "\n", -1);
126
for (i = 0; lines[i] && *lines[i]; i++) {
127
status_char = lines[i][0];
128
file = g_strdup (&lines[i][2]); /* just the file name */
129
status = git_list_files_char_to_status (status_char);
132
g_hash_table_insert (priv->files, file, GINT_TO_POINTER (status));
139
giggle_git_list_files_new ()
141
return g_object_new (GIGGLE_TYPE_GIT_LIST_FILES, NULL);
144
GiggleGitListFilesStatus
145
giggle_git_list_files_get_file_status (GiggleGitListFiles *list_files,
148
GiggleGitListFilesPriv *priv;
149
GiggleGitListFilesStatus status;
151
g_return_val_if_fail (GIGGLE_IS_GIT_LIST_FILES (list_files),
152
GIGGLE_GIT_FILE_STATUS_OTHER);
154
priv = GET_PRIV (list_files);
156
status = GPOINTER_TO_INT (g_hash_table_lookup (priv->files, file));