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

« back to all changes in this revision

Viewing changes to src/giggle-git-list-files.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-list-files.h"
24
 
 
25
 
typedef struct GiggleGitListFilesPriv GiggleGitListFilesPriv;
26
 
 
27
 
struct GiggleGitListFilesPriv {
28
 
        GHashTable *files;
29
 
};
30
 
 
31
 
static void     git_list_files_finalize            (GObject           *object);
32
 
 
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,
37
 
                                                    gsize              output_len);
38
 
 
39
 
G_DEFINE_TYPE (GiggleGitListFiles, giggle_git_list_files, GIGGLE_TYPE_JOB)
40
 
 
41
 
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_GIT_LIST_FILES, GiggleGitListFilesPriv))
42
 
 
43
 
static void
44
 
giggle_git_list_files_class_init (GiggleGitListFilesClass *class)
45
 
{
46
 
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
47
 
        GiggleJobClass *job_class    = GIGGLE_JOB_CLASS (class);
48
 
 
49
 
        object_class->finalize     = git_list_files_finalize;
50
 
 
51
 
        job_class->get_command_line = git_list_files_get_command_line;
52
 
        job_class->handle_output    = git_list_files_handle_output;
53
 
 
54
 
        g_type_class_add_private (object_class, sizeof (GiggleGitListFilesPriv));
55
 
}
56
 
 
57
 
static void
58
 
giggle_git_list_files_init (GiggleGitListFiles *list_files)
59
 
{
60
 
        GiggleGitListFilesPriv *priv;
61
 
 
62
 
        priv = GET_PRIV (list_files);
63
 
 
64
 
        priv->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
65
 
}
66
 
 
67
 
static void
68
 
git_list_files_finalize (GObject *object)
69
 
{
70
 
        GiggleGitListFilesPriv *priv;
71
 
 
72
 
        priv = GET_PRIV (object);
73
 
 
74
 
        g_hash_table_destroy (priv->files);
75
 
 
76
 
        G_OBJECT_CLASS (giggle_git_list_files_parent_class)->finalize (object);
77
 
}
78
 
 
79
 
static gboolean
80
 
git_list_files_get_command_line (GiggleJob *job, gchar **command_line)
81
 
{
82
 
        *command_line = g_strdup_printf (GIT_COMMAND " ls-files "
83
 
                                         "--cached --deleted --modified --others "
84
 
                                         "--killed -t --full-name");
85
 
 
86
 
        return TRUE;
87
 
}
88
 
 
89
 
static GiggleGitListFilesStatus
90
 
git_list_files_char_to_status (gchar status)
91
 
{
92
 
        switch (status) {
93
 
        case 'H':
94
 
                return GIGGLE_GIT_FILE_STATUS_CACHED;
95
 
        case 'M':
96
 
                return GIGGLE_GIT_FILE_STATUS_UNMERGED;
97
 
        case 'R':
98
 
                return GIGGLE_GIT_FILE_STATUS_DELETED;
99
 
        case 'C':
100
 
                return GIGGLE_GIT_FILE_STATUS_CHANGED;
101
 
        case 'K':
102
 
                return GIGGLE_GIT_FILE_STATUS_KILLED;
103
 
        case '?':
104
 
                return GIGGLE_GIT_FILE_STATUS_OTHER;
105
 
        default:
106
 
                g_assert_not_reached ();
107
 
                return GIGGLE_GIT_FILE_STATUS_OTHER;
108
 
        }
109
 
}
110
 
 
111
 
static void
112
 
git_list_files_handle_output (GiggleJob   *job,
113
 
                        const gchar *output_str,
114
 
                        gsize        output_len)
115
 
{
116
 
        GiggleGitListFilesPriv    *priv;
117
 
        GiggleGitListFilesStatus   status;
118
 
        gchar                    **lines;
119
 
        gchar                     *file;
120
 
        gchar                      status_char;
121
 
        gint                       i;
122
 
 
123
 
        priv = GET_PRIV (job);
124
 
        lines = g_strsplit (output_str, "\n", -1);
125
 
 
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);
130
 
                
131
 
                /* add filename */
132
 
                g_hash_table_insert (priv->files, file, GINT_TO_POINTER (status));
133
 
        }
134
 
 
135
 
        g_strfreev (lines);
136
 
}
137
 
 
138
 
GiggleJob *
139
 
giggle_git_list_files_new ()
140
 
{
141
 
        return g_object_new (GIGGLE_TYPE_GIT_LIST_FILES, NULL);
142
 
}
143
 
 
144
 
GiggleGitListFilesStatus
145
 
giggle_git_list_files_get_file_status (GiggleGitListFiles *list_files,
146
 
                                       const gchar        *file)
147
 
{
148
 
        GiggleGitListFilesPriv   *priv;
149
 
        GiggleGitListFilesStatus  status;
150
 
 
151
 
        g_return_val_if_fail (GIGGLE_IS_GIT_LIST_FILES (list_files),
152
 
                              GIGGLE_GIT_FILE_STATUS_OTHER);
153
 
 
154
 
        priv = GET_PRIV (list_files);
155
 
 
156
 
        status = GPOINTER_TO_INT (g_hash_table_lookup (priv->files, file));
157
 
        return status;
158
 
}