From 860dcaa37b90b5d2b54840483bcd97a76db6f92e Mon Sep 17 00:00:00 2001 From: James Liggett Date: Sun, 27 Apr 2008 18:12:13 -0700 Subject: [PATCH] Make the status command aware of different sections in its output. This is needed because two different commands are needed to revert uncommitted changes. --- plugins/git/git-commit-dialog.c | 3 +- plugins/git/git-resolve-dialog.c | 3 +- plugins/git/git-status-command.c | 75 +++++++++++++++++++++++++++++----------- plugins/git/git-status-command.h | 11 +++++- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/plugins/git/git-commit-dialog.c b/plugins/git/git-commit-dialog.c index 65c0ac93..e819ec06 100644 --- a/plugins/git/git-commit-dialog.c +++ b/plugins/git/git-commit-dialog.c @@ -129,7 +129,8 @@ commit_dialog (Git *plugin) status_view = glade_xml_get_widget (gxml, "status_view"); status_progress_bar = glade_xml_get_widget (gxml, "status_progress_bar"); - status_command = git_status_command_new (plugin->project_root_directory); + status_command = git_status_command_new (plugin->project_root_directory, + GIT_STATUS_SECTION_MODIFIED); g_signal_connect (G_OBJECT (select_all_button), "clicked", G_CALLBACK (select_all_status_items), diff --git a/plugins/git/git-resolve-dialog.c b/plugins/git/git-resolve-dialog.c index 1c206b01..cba8e221 100644 --- a/plugins/git/git-resolve-dialog.c +++ b/plugins/git/git-resolve-dialog.c @@ -89,7 +89,8 @@ resolve_dialog (Git *plugin) status_view = glade_xml_get_widget (gxml, "status_view"); status_progress_bar = glade_xml_get_widget (gxml, "status_progress_bar"); - status_command = git_status_command_new (plugin->project_root_directory); + status_command = git_status_command_new (plugin->project_root_directory, + GIT_STATUS_SECTION_NOT_UPDATED); g_signal_connect (G_OBJECT (select_all_button), "clicked", G_CALLBACK (select_all_status_items), diff --git a/plugins/git/git-status-command.c b/plugins/git/git-status-command.c index e077f029..e6a9c9ed 100644 --- a/plugins/git/git-status-command.c +++ b/plugins/git/git-status-command.c @@ -25,12 +25,18 @@ #include "git-status-command.h" #define STATUS_REGEX "(modified|new file|deleted|unmerged): (.*)" +#define SECTION_COMMIT_REGEX "Changes to be committed:" +#define SECTION_NOT_UPDATED_REGEX "Changed but not updated:" struct _GitStatusCommandPriv { GQueue *status_queue; GHashTable *path_lookup_table; + GitStatusSections sections; + GitStatusSections current_section; GRegex *status_regex; + GRegex *section_commit_regex; + GRegex *section_not_updated_regex; }; G_DEFINE_TYPE (GitStatusCommand, git_status_command, GIT_TYPE_COMMAND); @@ -54,28 +60,42 @@ git_status_command_handle_output (GitCommand *git_command, const gchar *output) self = GIT_STATUS_COMMAND (git_command); - if (g_regex_match (self->priv->status_regex, output, 0, &match_info)) + /* See if the section has changed */ + if (g_regex_match (self->priv->section_commit_regex, output, 0, NULL)) { - /* Git sometimes mentions paths twice in status output. This can - * happen, for example, where there is a conflict, in which case a - * path would show up as both "unmerged" and "modified." */ - - status = g_match_info_fetch (match_info, 1); - path = g_match_info_fetch (match_info, 2); - - if (!g_hash_table_lookup_extended (self->priv->path_lookup_table, path, - NULL, NULL)) + self->priv->current_section = GIT_STATUS_SECTION_COMMIT; + } + else if (g_regex_match (self->priv->section_not_updated_regex, output, 0, + NULL)) + { + self->priv->current_section = GIT_STATUS_SECTION_NOT_UPDATED; + } + + if (self->priv->sections & self->priv->current_section) + { + if (g_regex_match (self->priv->status_regex, output, 0, &match_info)) { - status_object = git_status_new (path, status); - g_queue_push_tail (self->priv->status_queue, status_object); - g_hash_table_insert (self->priv->path_lookup_table, g_strdup (path), - NULL); - anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); - } + /* Git sometimes mentions paths twice in status output. This can + * happen, for example, where there is a conflict, in which case a + * path would show up as both "unmerged" and "modified." */ + + status = g_match_info_fetch (match_info, 1); + path = g_match_info_fetch (match_info, 2); - g_free (status); - g_free (path); - g_match_info_free (match_info); + if (!g_hash_table_lookup_extended (self->priv->path_lookup_table, + path, NULL, NULL)) + { + status_object = git_status_new (path, status); + g_queue_push_tail (self->priv->status_queue, status_object); + g_hash_table_insert (self->priv->path_lookup_table, + g_strdup (path), NULL); + anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); + } + + g_free (status); + g_free (path); + g_match_info_free (match_info); + } } } @@ -88,6 +108,10 @@ git_status_command_init (GitStatusCommand *self) g_str_equal, g_free, NULL); self->priv->status_regex = g_regex_new (STATUS_REGEX, 0, 0, NULL); + self->priv->section_commit_regex = g_regex_new (SECTION_COMMIT_REGEX, 0, 0, + NULL); + self->priv->section_not_updated_regex = g_regex_new (SECTION_NOT_UPDATED_REGEX, + 0, 0, NULL); } static void @@ -108,6 +132,8 @@ git_status_command_finalize (GObject *object) g_queue_free (self->priv->status_queue); g_hash_table_destroy (self->priv->path_lookup_table); g_regex_unref (self->priv->status_regex); + g_regex_unref (self->priv->section_commit_regex); + g_regex_unref (self->priv->section_not_updated_regex); g_free (self->priv); @@ -128,12 +154,19 @@ git_status_command_class_init (GitStatusCommandClass *klass) GitStatusCommand * -git_status_command_new (const gchar *working_directory) +git_status_command_new (const gchar *working_directory, + GitStatusSections sections) { - return g_object_new (GIT_TYPE_STATUS_COMMAND, + GitStatusCommand *self; + + self = g_object_new (GIT_TYPE_STATUS_COMMAND, "working-directory", working_directory, "single-line-output", TRUE, NULL); + + self->priv->sections = sections; + + return self; } GQueue * diff --git a/plugins/git/git-status-command.h b/plugins/git/git-status-command.h index f59ea1f7..70ef593a 100644 --- a/plugins/git/git-status-command.h +++ b/plugins/git/git-status-command.h @@ -42,6 +42,14 @@ typedef struct _GitStatusCommandClass GitStatusCommandClass; typedef struct _GitStatusCommand GitStatusCommand; typedef struct _GitStatusCommandPriv GitStatusCommandPriv; +typedef enum +{ + GIT_STATUS_SECTION_COMMIT = 1 << 0, + GIT_STATUS_SECTION_NOT_UPDATED = 1 << 1, + GIT_STATUS_SECTION_MODIFIED = (GIT_STATUS_SECTION_COMMIT | + GIT_STATUS_SECTION_NOT_UPDATED) +} GitStatusSections; + struct _GitStatusCommandClass { GitCommandClass parent_class; @@ -55,7 +63,8 @@ struct _GitStatusCommand }; GType git_status_command_get_type (void) G_GNUC_CONST; -GitStatusCommand *git_status_command_new (const gchar *working_directory); +GitStatusCommand *git_status_command_new (const gchar *working_directory, + GitStatusSections sections); GQueue *git_status_command_get_status_queue (GitStatusCommand *self); G_END_DECLS -- 2.11.4.GIT