1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
6 * anjuta is free software.
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)
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-tag-list-command.h"
27 struct _GitTagListCommandPriv
29 GFileMonitor
*tags_monitor
;
30 GFileMonitor
*packed_refs_monitor
;
33 G_DEFINE_TYPE (GitTagListCommand
, git_tag_list_command
, GIT_TYPE_RAW_OUTPUT_COMMAND
);
36 git_tag_list_command_init (GitTagListCommand
*self
)
38 self
->priv
= g_new0 (GitTagListCommandPriv
, 1);
42 git_tag_list_command_finalize (GObject
*object
)
44 GitTagListCommand
*self
;
46 self
= GIT_TAG_LIST_COMMAND (object
);
48 anjuta_command_stop_automatic_monitor (ANJUTA_COMMAND (object
));
51 G_OBJECT_CLASS (git_tag_list_command_parent_class
)->finalize (object
);
55 git_tag_list_command_run (AnjutaCommand
*command
)
57 git_command_add_arg (GIT_COMMAND (command
), "tag");
63 on_file_monitor_changed (GFileMonitor
*monitor
, GFile
*file
, GFile
*other_file
,
64 GFileMonitorEvent event
, AnjutaCommand
*command
)
66 if (event
== G_FILE_MONITOR_EVENT_CREATED
||
67 event
== G_FILE_MONITOR_EVENT_DELETED
)
69 anjuta_command_start (command
);
74 git_tag_list_command_start_automatic_monitor (AnjutaCommand
*command
)
76 GitTagListCommand
*self
;
77 gchar
*working_directory
;
79 gchar
*git_packed_refs_path
;
80 GFile
*git_packed_refs_file
;
83 self
= GIT_TAG_LIST_COMMAND (command
);
85 g_object_get (G_OBJECT (self
), "working-directory", &working_directory
,
88 /* Git keeps tag info in two places: as individual files in .git/refs/tags
89 * and as a file in .git/packed-refs. These "packed refs"
90 * are used in cases where repositories might have a lot of tags, as having
91 * to go through tons of individual files is can be a large performance
92 * drain. From what I can tell, tags created with git tag get their own
93 * file, while tags that are fetched from remote repositories are packed
95 git_tags_path
= g_strjoin (G_DIR_SEPARATOR_S
,
101 git_packed_refs_path
= g_strjoin (G_DIR_SEPARATOR_S
,
107 git_tags_file
= g_file_new_for_path (git_tags_path
);
108 git_packed_refs_file
= g_file_new_for_path (git_packed_refs_path
);
110 self
->priv
->tags_monitor
= g_file_monitor_directory (git_tags_file
, 0, NULL
,
112 self
->priv
->packed_refs_monitor
= g_file_monitor_file (git_packed_refs_file
,
115 g_signal_connect (G_OBJECT (self
->priv
->tags_monitor
), "changed",
116 G_CALLBACK (on_file_monitor_changed
),
119 g_signal_connect (G_OBJECT (self
->priv
->packed_refs_monitor
), "changed",
120 G_CALLBACK (on_file_monitor_changed
),
123 g_free (working_directory
);
124 g_free (git_tags_path
);
125 g_free (git_packed_refs_path
);
126 g_object_unref (git_packed_refs_file
);
127 g_object_unref (git_tags_file
);
133 git_tag_list_command_stop_automatic_monitor (AnjutaCommand
*command
)
135 GitTagListCommand
*self
;
137 self
= GIT_TAG_LIST_COMMAND (command
);
139 if (self
->priv
->tags_monitor
)
141 g_file_monitor_cancel (self
->priv
->tags_monitor
);
142 g_object_unref (self
->priv
->tags_monitor
);
143 self
->priv
->tags_monitor
= NULL
;
146 if (self
->priv
->packed_refs_monitor
)
148 g_file_monitor_cancel (self
->priv
->packed_refs_monitor
);
149 g_object_unref (self
->priv
->packed_refs_monitor
);
150 self
->priv
->packed_refs_monitor
= NULL
;
155 git_tag_list_command_class_init (GitTagListCommandClass
*klass
)
157 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
158 AnjutaCommandClass
*command_class
= ANJUTA_COMMAND_CLASS (klass
);
160 object_class
->finalize
= git_tag_list_command_finalize
;
161 command_class
->run
= git_tag_list_command_run
;
162 command_class
->start_automatic_monitor
= git_tag_list_command_start_automatic_monitor
;
163 command_class
->stop_automatic_monitor
= git_tag_list_command_stop_automatic_monitor
;
168 git_tag_list_command_new (const gchar
*working_directory
)
170 return g_object_new (GIT_TYPE_TAG_LIST_COMMAND
,
171 "working-directory", working_directory
,
172 "single-line-output", TRUE
,
173 "strip-newlines", TRUE
,