Commit 250db751 authored by James Liggett's avatar James Liggett

git: Add a cherry-picking interface

parent 2d608c2d
......@@ -189,7 +189,11 @@ libanjuta_git_la_SOURCES = \
git-apply-mailbox-continue-command.c \
git-apply-mailbox-continue-command.h \
git-apply-mailbox-dialog.c \
git-apply-mailbox-dialog.h
git-apply-mailbox-dialog.h \
git-cherry-pick-command.c \
git-cherry-pick-command.h \
git-cherry-pick-dialog.c \
git-cherry-pick-dialog.h
libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
......
This diff is collapsed.
......@@ -48,6 +48,7 @@
<menuitem name="Delete branch..." action="ActionGitDeleteBranch" />
<menuitem name="Switch to another branch..." action="ActionGitSwitch" />
<menuitem name="Merge..." action="ActionGitMerge" />
<menuitem name="Cherry pick..." action="ActionGitCherryPick" />
<placeholder name="PlaceholderRemoteMenu">
<menu name="Remote branches" action="ActionMenuGitRemoteBranches">
<menuitem name="Add..." action="ActionGitRemoteAdd" />
......@@ -88,6 +89,8 @@
<menuitem name="Reset tree..." action="ActionGitLogReset" />
<menuitem name="Revert commit..." action="ActionGitLogRevert" />
<separator />
<menuitem name="Cherry pick..." action="ActionGitLogCherryPick" />
<separator />
<placeholder name="PlaceholderLogBisectMenu">
<menu name="Bisect" action="ActionMenuGitLogBisect">
<menuitem name="Set good revision" action="ActionGitLogBisectGood" />
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) James Liggett 2008 <jrliggett@cox.net>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#include "git-cherry-pick-command.h"
struct _GitCherryPickCommandPriv
{
gchar *revision;
gboolean no_commit;
gboolean show_source;
gboolean add_signoff;
};
G_DEFINE_TYPE (GitCherryPickCommand, git_cherry_pick_command, GIT_TYPE_COMMAND);
static void
git_cherry_pick_command_init (GitCherryPickCommand *self)
{
self->priv = g_new0 (GitCherryPickCommandPriv, 1);
}
static void
git_cherry_pick_command_finalize (GObject *object)
{
GitCherryPickCommand *self;
self = GIT_CHERRY_PICK_COMMAND (object);
g_free (self->priv->revision);
g_free (self->priv);
G_OBJECT_CLASS (git_cherry_pick_command_parent_class)->finalize (object);
}
static guint
git_cherry_pick_command_run (AnjutaCommand *command)
{
GitCherryPickCommand *self;
self = GIT_CHERRY_PICK_COMMAND (command);
git_command_add_arg (GIT_COMMAND (command), "cherry-pick");
if (self->priv->no_commit)
git_command_add_arg (GIT_COMMAND (command), "-n");
if (self->priv->show_source)
git_command_add_arg (GIT_COMMAND (command), "-x");
if (self->priv->add_signoff)
git_command_add_arg (GIT_COMMAND (command), "-s");
git_command_add_arg (GIT_COMMAND (command), self->priv->revision);
return 0;
}
static void
git_cherry_pick_command_class_init (GitCherryPickCommandClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
GitCommandClass* parent_class = GIT_COMMAND_CLASS (klass);
AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
object_class->finalize = git_cherry_pick_command_finalize;
parent_class->output_handler = git_command_send_output_to_info;
command_class->run = git_cherry_pick_command_run;
}
GitCherryPickCommand *
git_cherry_pick_command_new (const gchar *working_directory,
const gchar *revision, gboolean no_commit,
gboolean show_source, gboolean add_signoff)
{
GitCherryPickCommand *self;
self = g_object_new (GIT_TYPE_CHERRY_PICK_COMMAND,
"working-directory", working_directory,
"single-line-output", TRUE,
NULL);
self->priv->revision = g_strdup (revision);
self->priv->no_commit = no_commit;
self->priv->show_source = show_source;
self->priv->add_signoff = add_signoff;
return self;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) James Liggett 2008 <jrliggett@cox.net>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _GIT_CHERRY_PICK_COMMAND_H_
#define _GIT_CHERRY_PICK_COMMAND_H_
#include <glib-object.h>
#include "git-command.h"
G_BEGIN_DECLS
#define GIT_TYPE_CHERRY_PICK_COMMAND (git_cherry_pick_command_get_type ())
#define GIT_CHERRY_PICK_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_CHERRY_PICK_COMMAND, GitCherryPickCommand))
#define GIT_CHERRY_PICK_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_CHERRY_PICK_COMMAND, GitCherryPickCommandClass))
#define GIT_IS_CHERRY_PICK_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_CHERRY_PICK_COMMAND))
#define GIT_IS_CHERRY_PICK_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_CHERRY_PICK_COMMAND))
#define GIT_CHERRY_PICK_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_CHERRY_PICK_COMMAND, GitCherryPickCommandClass))
typedef struct _GitCherryPickCommandClass GitCherryPickCommandClass;
typedef struct _GitCherryPickCommand GitCherryPickCommand;
typedef struct _GitCherryPickCommandPriv GitCherryPickCommandPriv;
struct _GitCherryPickCommandClass
{
GitCommandClass parent_class;
};
struct _GitCherryPickCommand
{
GitCommand parent_instance;
GitCherryPickCommandPriv *priv;
};
GType git_cherry_pick_command_get_type (void) G_GNUC_CONST;
GitCherryPickCommand *git_cherry_pick_command_new (const gchar *working_directory,
const gchar *revision,
gboolean no_commit,
gboolean show_source,
gboolean add_signoff);
G_END_DECLS
#endif /* _GIT_REVERT_COMMAND_H_ */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) James Liggett 2008 <jrliggett@cox.net>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#include "git-cherry-pick-dialog.h"
static void
on_cherry_pick_dialog_response (GtkDialog *dialog, gint response_id,
GitUIData *data)
{
GtkWidget *cherry_pick_revision_entry;
GtkWidget *cherry_pick_no_commit_check;
GtkWidget *cherry_pick_show_source_check;
GtkWidget *cherry_pick_signoff_check;
gchar *revision;
GitCherryPickCommand *cherry_pick_command;
if (response_id == GTK_RESPONSE_OK)
{
cherry_pick_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_revision_entry"));
cherry_pick_no_commit_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_no_commit_check"));
cherry_pick_show_source_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_show_source_check"));
cherry_pick_signoff_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_signoff_check"));
revision = gtk_editable_get_chars (GTK_EDITABLE (cherry_pick_revision_entry),
0, -1);
if (git_check_input (GTK_WIDGET (dialog), cherry_pick_revision_entry, revision,
_("Please enter a revision.")))
{
cherry_pick_command = git_cherry_pick_command_new (data->plugin->project_root_directory,
revision,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cherry_pick_no_commit_check)),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cherry_pick_show_source_check)),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cherry_pick_signoff_check)));
g_free (revision);
git_create_message_view (data->plugin);
g_signal_connect (G_OBJECT (cherry_pick_command), "command-finished",
G_CALLBACK (on_git_command_finished),
data->plugin);
g_signal_connect (G_OBJECT (cherry_pick_command), "data-arrived",
G_CALLBACK (on_git_command_info_arrived),
data->plugin);
anjuta_command_start (ANJUTA_COMMAND (cherry_pick_command));
}
else
{
g_free (revision);
return;
}
}
gtk_widget_destroy (GTK_WIDGET (dialog));
git_ui_data_free (data);
}
static void
on_cherry_pick_no_commit_check_toggled (GtkToggleButton *toggle_button,
GitUIData *data)
{
GtkWidget *cherry_pick_show_source_check;
GtkWidget *cherry_pick_signoff_check;
gboolean active;
cherry_pick_show_source_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_show_source_check"));
cherry_pick_signoff_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
"cherry_pick_signoff_check"));
active = gtk_toggle_button_get_active (toggle_button);
/* It doesn't make much sense to show a source revision or add a signed off
* line when there's no commit to be made. */
if (active)
{
gtk_widget_set_sensitive (cherry_pick_show_source_check, FALSE);
gtk_widget_set_sensitive (cherry_pick_signoff_check, FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cherry_pick_show_source_check), FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cherry_pick_signoff_check), FALSE);
}
else
{
gtk_widget_set_sensitive (cherry_pick_show_source_check, TRUE);
gtk_widget_set_sensitive (cherry_pick_signoff_check, TRUE);
}
}
static void
cherry_pick_dialog (Git *plugin, const gchar *revision)
{
GtkBuilder *bxml;
gchar *objects[] = {"cherry_pick_dialog", NULL};
GError *error;
GtkWidget *dialog;
GtkWidget *cherry_pick_revision_entry;
GtkWidget *cherry_pick_no_commit_check;
GitUIData *data;
bxml = gtk_builder_new ();
error = NULL;
if (!gtk_builder_add_objects_from_file (bxml, BUILDER_FILE, objects,
&error))
{
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
}
dialog = GTK_WIDGET (gtk_builder_get_object (bxml, "cherry_pick_dialog"));
cherry_pick_revision_entry = GTK_WIDGET (gtk_builder_get_object (bxml,
"cherry_pick_revision_entry"));
cherry_pick_no_commit_check = GTK_WIDGET (gtk_builder_get_object (bxml,
"cherry_pick_no_commit_check"));
data = git_ui_data_new (plugin, bxml);
if (revision)
gtk_entry_set_text (GTK_ENTRY (cherry_pick_revision_entry), revision);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (on_cherry_pick_dialog_response),
data);
g_signal_connect (G_OBJECT (cherry_pick_no_commit_check), "toggled",
G_CALLBACK (on_cherry_pick_no_commit_check_toggled),
data);
gtk_widget_show_all (dialog);
}
void
on_menu_git_cherry_pick (GtkAction *action, Git *plugin)
{
cherry_pick_dialog (plugin, NULL);
}
void
on_log_menu_git_cherry_pick (GtkAction *action, Git *plugin)
{
GitRevision *revision;
gchar *sha;
revision = git_log_get_selected_revision (plugin);
if (revision)
{
sha = git_revision_get_sha (revision);
cherry_pick_dialog (plugin, sha);
g_free (sha);
}
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* anjuta
* Copyright (C) James Liggett 2008 <jrliggett@cox.net>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _GIT_CHERRY_PICK_DIALOG_H
#define _GIT_CHERRY_PICK_DIALOG_H
#include "git-cherry-pick-command.h"
#include "git-log-dialog.h"
#include "git-ui-utils.h"
void on_menu_git_cherry_pick (GtkAction *action, Git *plugin);
void on_log_menu_git_cherry_pick (GtkAction *action, Git *plugin);
#endif
......@@ -47,6 +47,7 @@
#include "git-cat-file-menu.h"
#include "git-push-dialog.h"
#include "git-apply-mailbox-dialog.h"
#include "git-cherry-pick-dialog.h"
#define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.xml"
......@@ -286,6 +287,14 @@ static GtkActionEntry actions_git[] =
NULL, /* Tooltip */
G_CALLBACK (on_menu_git_merge) /* action callback */
},
{
"ActionGitCherryPick", /* Action name */
NULL, /* Stock icon, if any */
N_("_Cherry pick..."), /* Display label */
NULL, /* short-cut */
NULL, /* Tooltip */
G_CALLBACK (on_menu_git_cherry_pick) /* action callback */
},
{
"ActionMenuGitRemoteBranches", /* Action name */
GTK_STOCK_NETWORK, /* Stock icon, if any */
......@@ -434,6 +443,14 @@ static GtkActionEntry actions_log[] =
NULL, /* Tooltip */
G_CALLBACK (on_log_menu_git_revert) /* action callback */
},
{
"ActionGitLogCherryPick", /* Action name */
NULL, /* Stock icon, if any */
N_("_Cherry pick..."), /* Display label */
NULL, /* short-cut */
NULL, /* Tooltip */
G_CALLBACK (on_log_menu_git_cherry_pick) /* action callback */
},
{
"ActionMenuGitLogBisect", /* Action name */
NULL, /* Stock icon, if any */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment