From 2659d63e3ebe8bbda4d9bcf0c6657105480cb59f Mon Sep 17 00:00:00 2001 From: James Liggett Date: Fri, 16 May 2008 16:49:21 -0700 Subject: [PATCH] Support creating branches at any revision. Branch creation is also now integrated with the log viewer. --- plugins/git/anjuta-git.glade | 82 +++++++++++++++++++++++++- plugins/git/anjuta-git.ui | 2 + plugins/git/git-branch-create-command.c | 9 ++- plugins/git/git-branch-create-command.h | 3 +- plugins/git/git-create-branch-dialog.c | 100 ++++++++++++++++++++++++++++++-- plugins/git/git-create-branch-dialog.h | 2 + plugins/git/plugin.c | 12 +++- 7 files changed, 198 insertions(+), 12 deletions(-) diff --git a/plugins/git/anjuta-git.glade b/plugins/git/anjuta-git.glade index 4dbaa4b9..9900dfbd 100644 --- a/plugins/git/anjuta-git.glade +++ b/plugins/git/anjuta-git.glade @@ -1,6 +1,6 @@ - + @@ -1039,6 +1039,82 @@ + + True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + + + True + True + Head + 0 + True + True + + + + + True + + + True + True + Revision/Tag: + 0 + True + True + branch_head_radio + + + False + False + + + + + True + False + True + 40 + + + 1 + + + + + 1 + + + + + + + + + True + <b>Revision:</b> + True + + + label_item + + + + + False + 2 + + + True 0 @@ -1048,7 +1124,7 @@ True 12 - + True True Check out the branch after it is created @@ -1071,7 +1147,7 @@ False - 2 + 3 diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui index 6141fb9f..5fb1b98b 100644 --- a/plugins/git/anjuta-git.ui +++ b/plugins/git/anjuta-git.ui @@ -27,5 +27,7 @@ + + diff --git a/plugins/git/git-branch-create-command.c b/plugins/git/git-branch-create-command.c index 6cc4c329..cfc3eace 100644 --- a/plugins/git/git-branch-create-command.c +++ b/plugins/git/git-branch-create-command.c @@ -27,6 +27,7 @@ struct _GitBranchCreateCommandPriv { gchar *name; + gchar *revision; gboolean checkout; }; @@ -46,6 +47,7 @@ git_branch_create_command_finalize (GObject *object) self = GIT_BRANCH_CREATE_COMMAND (object); g_free (self->priv->name); + g_free (self->priv->revision); g_free (self->priv); G_OBJECT_CLASS (git_branch_create_command_parent_class)->finalize (object); @@ -68,6 +70,9 @@ git_branch_create_command_run (AnjutaCommand *command) git_command_add_arg (GIT_COMMAND (command), self->priv->name); + if (self->priv->revision) + git_command_add_arg (GIT_COMMAND (command), self->priv->revision); + return 0; } @@ -86,7 +91,8 @@ git_branch_create_command_class_init (GitBranchCreateCommandClass *klass) GitBranchCreateCommand * git_branch_create_command_new (const gchar *working_directory, - const gchar *name, gboolean checkout) + const gchar *name, const gchar *revision, + gboolean checkout) { GitBranchCreateCommand *self; @@ -96,6 +102,7 @@ git_branch_create_command_new (const gchar *working_directory, NULL); self->priv->name = g_strdup (name); + self->priv->revision = g_strdup (revision); self->priv->checkout = checkout; return self; diff --git a/plugins/git/git-branch-create-command.h b/plugins/git/git-branch-create-command.h index e985267b..10c7c85b 100644 --- a/plugins/git/git-branch-create-command.h +++ b/plugins/git/git-branch-create-command.h @@ -55,7 +55,8 @@ struct _GitBranchCreateCommand GType git_branch_create_command_get_type (void) G_GNUC_CONST; GitBranchCreateCommand *git_branch_create_command_new (const gchar *working_directory, - const gchar *name, + const gchar *name, + const gchar *revision, gboolean checkout); gchar *git_branch_create_command_get_branch_name (GitBranchCreateCommand *self); diff --git a/plugins/git/git-create-branch-dialog.c b/plugins/git/git-create-branch-dialog.c index a0ebe5bb..51ffe04b 100644 --- a/plugins/git/git-create-branch-dialog.c +++ b/plugins/git/git-create-branch-dialog.c @@ -59,8 +59,11 @@ on_create_branch_dialog_response (GtkDialog *dialog, gint response_id, GitUIData *data) { GtkWidget *branch_name_entry; - GtkWidget *checkout_check; + GtkWidget *branch_checkout_check; + GtkWidget *branch_revision_radio; + GtkWidget *branch_revision_entry; gchar *branch_name; + gchar *revision; gboolean checkout; GitBranchCreateCommand *create_command; @@ -68,13 +71,43 @@ on_create_branch_dialog_response (GtkDialog *dialog, gint response_id, { branch_name_entry = glade_xml_get_widget (data->gxml, "branch_name_entry"); - checkout_check = glade_xml_get_widget (data->gxml, "checkout_check"); + branch_checkout_check = glade_xml_get_widget (data->gxml, + "branch_checkout_check"); + branch_revision_radio = glade_xml_get_widget (data->gxml, + "branch_revision_radio"); + branch_revision_entry = glade_xml_get_widget (data->gxml, + "branch_revision_entry"); branch_name = gtk_editable_get_chars (GTK_EDITABLE (branch_name_entry), 0, -1); - checkout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkout_check)); + revision = NULL; + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (branch_revision_radio))) + { + revision = gtk_editable_get_chars (GTK_EDITABLE (branch_revision_entry), + 0, -1); + if (!check_input (GTK_WIDGET (dialog), branch_revision_entry, + revision, _("Please enter a revision."))) + { + g_free (revision); + g_free (branch_name); + return; + } + } + + if (!check_input (GTK_WIDGET (dialog), branch_revision_entry, + branch_name, _("Please enter a branch name."))) + { + + g_free (revision); + g_free (branch_name); + return; + } + + checkout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (branch_checkout_check)); create_command = git_branch_create_command_new (data->plugin->project_root_directory, branch_name, + revision, checkout); g_free (branch_name); @@ -97,25 +130,82 @@ on_create_branch_dialog_response (GtkDialog *dialog, gint response_id, } static void -create_branch_dialog (Git *plugin) +on_branch_revision_radio_toggled (GtkToggleButton *toggle_button, + GitUIData *data) +{ + GtkWidget *create_branch_dialog; + GtkWidget *branch_revision_entry; + gboolean active; + + create_branch_dialog = glade_xml_get_widget (data->gxml, + "create_branch_dialog"); + branch_revision_entry = glade_xml_get_widget (data->gxml, + "branch_revision_entry"); + + active = gtk_toggle_button_get_active (toggle_button); + gtk_widget_set_sensitive (branch_revision_entry, active); + + if (active) + { + gtk_window_set_focus (GTK_WINDOW (create_branch_dialog), + branch_revision_entry); + } + +} + +static void +create_branch_dialog (Git *plugin, const gchar *revision) { GladeXML *gxml; GtkWidget *dialog; + GtkWidget *branch_revision_radio; + GtkWidget *branch_revision_entry; GitUIData *data; gxml = glade_xml_new (GLADE_FILE, "create_branch_dialog", NULL); dialog = glade_xml_get_widget (gxml, "create_branch_dialog"); + branch_revision_radio = glade_xml_get_widget (gxml, + "branch_revision_radio"); + branch_revision_entry = glade_xml_get_widget (gxml, + "branch_revision_entry"); data = git_ui_data_new (plugin, gxml); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_create_branch_dialog_response), data); + g_signal_connect (G_OBJECT (branch_revision_radio), "toggled", + G_CALLBACK (on_branch_revision_radio_toggled), + data); + + if (revision) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (branch_revision_radio), TRUE); + gtk_entry_set_text (GTK_ENTRY (branch_revision_entry), revision); + } + gtk_widget_show_all (dialog); } void on_menu_git_create_branch (GtkAction *action, Git *plugin) { - create_branch_dialog (plugin); + create_branch_dialog (plugin, NULL); +} + +void +on_log_menu_git_create_branch (GtkAction *action, Git *plugin) +{ + GitRevision *revision; + gchar *sha; + + revision = git_log_get_selected_revision (plugin); + + if (revision) + { + sha = git_revision_get_sha (revision); + + create_branch_dialog (plugin, sha); + g_free (sha); + } } diff --git a/plugins/git/git-create-branch-dialog.h b/plugins/git/git-create-branch-dialog.h index 79dccb9f..c29d369b 100644 --- a/plugins/git/git-create-branch-dialog.h +++ b/plugins/git/git-create-branch-dialog.h @@ -26,8 +26,10 @@ #define _GIT_CREATE_BRANCH_DIALOG_H #include "git-branch-create-command.h" +#include "git-log-dialog.h" #include "git-ui-utils.h" void on_menu_git_create_branch (GtkAction *action, Git *plugin); +void on_log_menu_git_create_branch (GtkAction *action, Git *plugin); #endif diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c index 34af35d6..9b259408 100644 --- a/plugins/git/plugin.c +++ b/plugins/git/plugin.c @@ -105,7 +105,7 @@ static GtkActionEntry actions_git[] = }, { "ActionGitCreateBranch", /* Action name */ - GTK_STOCK_NEW, /* Stock icon, if any */ + NULL, /* Stock icon, if any */ N_("_Create branch..."), /* Display label */ NULL, /* short-cut */ NULL, /* Tooltip */ @@ -154,7 +154,15 @@ static GtkActionEntry actions_log[] = NULL, /* short-cut */ NULL, /* Tooltip */ G_CALLBACK (on_log_menu_git_commit_diff) /* action callback */ - } + }, + { + "ActionGitLogCreateBranch", /* Action name */ + NULL, /* Stock icon, if any */ + N_("_Create Branch..."), /* Display label */ + NULL, /* short-cut */ + NULL, /* Tooltip */ + G_CALLBACK (on_log_menu_git_create_branch) /* action callback */ + }, }; static void -- 2.11.4.GIT