Copyright header fixes...
[anjuta-git-plugin.git] / plugins / git / git-ignore-command.c
blob09259f165b07d346217e8a66e0ea92b9628a8ec2
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "git-ignore-command.h"
27 struct _GitIgnoreCommandPriv
29 GList *paths;
32 G_DEFINE_TYPE (GitIgnoreCommand, git_ignore_command, GIT_TYPE_FILE_COMMAND);
34 static void
35 git_ignore_command_init (GitIgnoreCommand *self)
37 self->priv = g_new0 (GitIgnoreCommandPriv, 1);
40 static void
41 git_ignore_command_finalize (GObject *object)
43 GitIgnoreCommand *self;
45 self = GIT_IGNORE_COMMAND (object);
47 git_command_free_path_list (self->priv->paths);
48 g_free (self->priv);
50 G_OBJECT_CLASS (git_ignore_command_parent_class)->finalize (object);
53 static guint
54 git_ignore_command_run (AnjutaCommand *command)
56 GitIgnoreCommand *self;
57 gchar *working_directory;
58 GList *current_path;
59 gchar *ignore_file_path;
60 GFile *ignore_file;
61 GFile *ignore_file_parent;
62 GFile *gitignore_file;
63 gchar *ignore_path_basename;
64 GFileOutputStream *gitignore_stream;
66 self = GIT_IGNORE_COMMAND (command);
67 g_object_get (self, "working-directory", &working_directory, NULL);
68 current_path = self->priv->paths;
70 while (current_path)
72 ignore_file_path = g_build_filename (working_directory,
73 current_path->data, NULL);
74 ignore_file = g_file_new_for_path (ignore_file_path);
75 ignore_file_parent = g_file_get_parent (ignore_file);
76 gitignore_file = g_file_get_child (ignore_file_parent, ".gitignore");
77 ignore_path_basename = g_file_get_basename (ignore_file);
78 gitignore_stream = g_file_append_to (gitignore_file, 0, NULL, NULL);
80 g_output_stream_write (G_OUTPUT_STREAM (gitignore_stream),
81 ignore_path_basename,
82 strlen (ignore_path_basename),
83 NULL, NULL);
84 g_output_stream_write (G_OUTPUT_STREAM (gitignore_stream),
85 "\n", 1, NULL, NULL);
87 g_free (ignore_file_path);
88 g_free (ignore_path_basename);
89 g_object_unref (ignore_file);
90 g_object_unref (ignore_file_parent);
91 g_object_unref (gitignore_file);
92 g_object_unref (gitignore_stream);
94 current_path = g_list_next (current_path);
97 g_free (working_directory);
99 return 0;
102 static void
103 git_ignore_command_class_init (GitIgnoreCommandClass *klass)
105 GObjectClass* object_class = G_OBJECT_CLASS (klass);
106 AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
108 object_class->finalize = git_ignore_command_finalize;
109 command_class->run = git_ignore_command_run;
113 GitIgnoreCommand *
114 git_ignore_command_new_path (const gchar *working_directory, const gchar *path)
116 GitIgnoreCommand *self;
118 self = g_object_new (GIT_TYPE_IGNORE_COMMAND,
119 "working-directory", working_directory,
120 NULL);
122 self->priv->paths = g_list_append (self->priv->paths, g_strdup (path));
124 return self;
128 GitIgnoreCommand *
129 git_ignore_command_new_list (const gchar *working_directory, GList *path_list)
131 GitIgnoreCommand *self;
133 self = g_object_new (GIT_TYPE_IGNORE_COMMAND,
134 "working-directory", working_directory,
135 NULL);
137 self->priv->paths = git_command_copy_path_list (path_list);
139 return self;