[anjuta] Support custom author name and e-mail addresses in Git commits



commit c7b1225a7b9c4a2f6aa8923fd24a9299152c825e
Author: James Liggett <jrliggett cox net>
Date:   Sun Apr 19 18:24:02 2009 -0700

    Support custom author name and e-mail addresses in Git commits
    
    We'll need this for applying contributors' patches so their names and e-mail addresses can show up in
    the log.
---
 plugins/git/anjuta-git.glade     |  112 +++++++++++++++++++++++++++++++++++---
 plugins/git/git-commit-command.c |   22 +++++++-
 plugins/git/git-commit-command.h |    5 ++-
 plugins/git/git-commit-dialog.c  |   62 +++++++++++++++++++++
 4 files changed, 191 insertions(+), 10 deletions(-)

diff --git a/plugins/git/anjuta-git.glade b/plugins/git/anjuta-git.glade
index e2b4154..445f970 100644
--- a/plugins/git/anjuta-git.glade
+++ b/plugins/git/anjuta-git.glade
@@ -7,8 +7,6 @@
   <!-- interface-requires gnome 2366.5320 -->
   <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkDialog" id="commit_dialog">
-    <property name="width_request">600</property>
-    <property name="height_request">400</property>
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Commit Changes</property>
@@ -46,6 +44,8 @@
                         <property name="shadow_type">in</property>
                         <child>
                           <widget class="GtkTextView" id="commit_log_view">
+                            <property name="width_request">600</property>
+                            <property name="height_request">100</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -83,13 +83,107 @@
                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                     <property name="left_padding">12</property>
                     <child>
-                      <widget class="GtkCheckButton" id="resolve_check">
-                        <property name="label" translatable="yes">This commit concludes a failed merge (use -i)</property>
+                      <widget class="GtkVBox" id="vbox1">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                        <property name="draw_indicator">True</property>
+                        <child>
+                          <widget class="GtkCheckButton" id="resolve_check">
+                            <property name="label" translatable="yes">This commit concludes a failed merge (use -i)</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                            <property name="draw_indicator">True</property>
+                          </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkCheckButton" id="commit_custom_author_info_check">
+                            <property name="label" translatable="yes">Use custom author information:</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="draw_indicator">True</property>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkAlignment" id="commit_author_info_alignment">
+                            <property name="visible">True</property>
+                            <property name="sensitive">False</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <widget class="GtkVBox" id="vbox2">
+                                <property name="visible">True</property>
+                                <property name="spacing">2</property>
+                                <child>
+                                  <widget class="GtkHBox" id="hbox1">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">2</property>
+                                    <child>
+                                      <widget class="GtkLabel" id="label1">
+                                        <property name="visible">True</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Name:</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkEntry" id="commit_author_name_entry">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkHBox" id="hbox2">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">2</property>
+                                    <child>
+                                      <widget class="GtkLabel" id="label2">
+                                        <property name="visible">True</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">E-mail:</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkEntry" id="commit_author_email_entry">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -132,6 +226,8 @@
                         <property name="shadow_type">in</property>
                         <child>
                           <widget class="AnjutaVcsStatusTreeView" id="commit_status_view">
+                            <property name="width_request">600</property>
+                            <property name="height_request">100</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
diff --git a/plugins/git/git-commit-command.c b/plugins/git/git-commit-command.c
index d72e112..567712c 100644
--- a/plugins/git/git-commit-command.c
+++ b/plugins/git/git-commit-command.c
@@ -29,6 +29,8 @@ struct _GitCommitCommandPriv
 	GList *paths;
 	gboolean resolve_merge;
 	gchar *log;
+	gchar *author_name;
+	gchar *author_email;
 };
 
 G_DEFINE_TYPE (GitCommitCommand, git_commit_command, GIT_TYPE_COMMAND);
@@ -37,10 +39,21 @@ static guint
 git_commit_command_run (AnjutaCommand *command)
 {
 	GitCommitCommand *self;
+	gchar *author;
 	
 	self = GIT_COMMIT_COMMAND (command);
 	
 	git_command_add_arg (GIT_COMMAND (self), "commit");
+
+	if (self->priv->author_name && self->priv->author_email)
+	{
+		author = g_strdup_printf ("--author=%s <%s>", self->priv->author_name,
+		                          self->priv->author_email);
+		git_command_add_arg (GIT_COMMAND (self), author);
+
+		g_free (author);
+	}
+	
 	git_command_add_arg (GIT_COMMAND (self), "-m");
 	git_command_add_arg (GIT_COMMAND (self), self->priv->log);
 	
@@ -67,6 +80,8 @@ git_commit_command_finalize (GObject *object)
 	
 	git_command_free_path_list (self->priv->paths);
 	g_free (self->priv->log);
+	g_free (self->priv->author_name);
+	g_free (self->priv->author_email);
 	g_free (self->priv);
 
 	G_OBJECT_CLASS (git_commit_command_parent_class)->finalize (object);
@@ -87,7 +102,10 @@ git_commit_command_class_init (GitCommitCommandClass *klass)
 
 GitCommitCommand *
 git_commit_command_new (const gchar *working_directory, gboolean resolve_merge,
-						const gchar *log, GList *paths)
+						const gchar *log, 
+                        const gchar *author_name, 
+                        const gchar *author_email,
+                        GList *paths)
 {
 	GitCommitCommand *self;
 	
@@ -99,6 +117,8 @@ git_commit_command_new (const gchar *working_directory, gboolean resolve_merge,
 	self->priv->paths = git_command_copy_path_list (paths);
 	self->priv->resolve_merge = resolve_merge;
 	self->priv->log = g_strdup (log);
+	self->priv->author_name = g_strdup (author_name);
+	self->priv->author_email = g_strdup (author_email);
 	
 	return self;
 }
diff --git a/plugins/git/git-commit-command.h b/plugins/git/git-commit-command.h
index e000e20..23efbc0 100644
--- a/plugins/git/git-commit-command.h
+++ b/plugins/git/git-commit-command.h
@@ -56,7 +56,10 @@ struct _GitCommitCommand
 GType git_commit_command_get_type (void) G_GNUC_CONST;
 GitCommitCommand *git_commit_command_new (const gchar *working_directory,
 										  gboolean resolve_merge, 
-										  const gchar *log, GList *paths);
+										  const gchar *log, 
+										  const gchar *author_name,
+                                          const gchar *author_email,
+                                          GList *paths);
 										  
 
 G_END_DECLS
diff --git a/plugins/git/git-commit-dialog.c b/plugins/git/git-commit-dialog.c
index 0b6c17c..92231c4 100644
--- a/plugins/git/git-commit-dialog.c
+++ b/plugins/git/git-commit-dialog.c
@@ -50,6 +50,12 @@ on_commit_dialog_response (GtkDialog *dialog, gint response_id,
 	GtkWidget *log_prompt_dialog;
 	gint prompt_response;
 	GtkWidget *commit_status_view;
+	GtkWidget *commit_custom_author_info_check;
+	GtkWidget *commit_author_info_alignment;
+	GtkWidget *commit_author_name_entry;
+	GtkWidget *commit_author_email_entry;
+	gchar *author_name;
+	gchar *author_email;
 	GtkWidget *resolve_check;
 	GList *selected_paths;
 	GitCommitCommand *commit_command;
@@ -74,12 +80,50 @@ on_commit_dialog_response (GtkDialog *dialog, gint response_id,
 				return;
 		}
 		
+		commit_custom_author_info_check = glade_xml_get_widget (data->gxml, 
+		                                                        "commit_custom_author_info_check");
+		commit_author_info_alignment = glade_xml_get_widget (data->gxml,
+		                                                     "commit_author_info_alignment");
+		commit_author_name_entry = glade_xml_get_widget (data->gxml,
+		                                                 "commit_author_name_entry");
+		commit_author_email_entry = glade_xml_get_widget (data->gxml,
+		                                                  "commit_author_email_entry");
+
+		author_name = NULL;
+		author_email = NULL;
+
+		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (commit_custom_author_info_check)))
+		{
+			author_name = gtk_editable_get_chars (GTK_EDITABLE (commit_author_name_entry), 0, -1);
+			if (!git_check_input (GTK_WIDGET (dialog), commit_author_name_entry,
+			                      author_name,
+			                      _("Please enter the commit author's name.")))
+			{
+				g_free (log);
+				return;
+			}
+
+			author_email = gtk_editable_get_chars (GTK_EDITABLE (commit_author_email_entry), 0, -1);
+
+			if (!git_check_input (GTK_WIDGET (dialog), commit_author_email_entry,
+			                      author_email,
+			                      _("Please enter the commit author's e-mail address.")))
+			{
+				g_free (log);
+				g_free (author_name);
+				return;
+			}
+		}
+		   
+
 		commit_status_view = glade_xml_get_widget (data->gxml, "commit_status_view");
 		resolve_check = glade_xml_get_widget (data->gxml, "resolve_check");
 		selected_paths = anjuta_vcs_status_tree_view_get_selected (ANJUTA_VCS_STATUS_TREE_VIEW (commit_status_view));
 		commit_command = git_commit_command_new (data->plugin->project_root_directory,
 												 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (resolve_check)),
 												 log,
+		                                         author_name,
+		                                         author_email,
 												 selected_paths);
 		
 		g_free (log);
@@ -110,10 +154,20 @@ select_all_files (AnjutaCommand *command, guint return_code,
 }
 
 static void
+set_author_info_alignment_sensitive (GtkToggleButton *button,
+                            		 GtkWidget *commit_author_info_alignment)
+{
+	gtk_widget_set_sensitive (commit_author_info_alignment,
+	                          gtk_toggle_button_get_active (button));
+}
+
+static void
 commit_dialog (Git *plugin)
 {
 	GladeXML *gxml;
 	GtkWidget *dialog;
+	GtkWidget *commit_custom_author_info_check;
+	GtkWidget *commit_author_info_alignment;
 	GtkWidget *commit_select_all_button;
 	GtkWidget *commit_clear_button;
 	GtkWidget *commit_status_view;
@@ -124,6 +178,8 @@ commit_dialog (Git *plugin)
 	gxml = glade_xml_new (GLADE_FILE, "commit_dialog", NULL);
 	
 	dialog = glade_xml_get_widget (gxml, "commit_dialog");
+	commit_custom_author_info_check = glade_xml_get_widget (gxml, "commit_custom_author_info_check");
+	commit_author_info_alignment = glade_xml_get_widget (gxml, "commit_author_info_alignment");
 	commit_select_all_button = glade_xml_get_widget (gxml, "commit_select_all_button");
 	commit_clear_button = glade_xml_get_widget (gxml, "commit_clear_button");
 	commit_status_view = glade_xml_get_widget (gxml, "commit_status_view");
@@ -132,6 +188,10 @@ commit_dialog (Git *plugin)
 	status_command = git_status_command_new (plugin->project_root_directory,
 											 GIT_STATUS_SECTION_MODIFIED);
 	
+	g_signal_connect (G_OBJECT (commit_custom_author_info_check), "toggled",
+	                  G_CALLBACK (set_author_info_alignment_sensitive),
+	                  commit_author_info_alignment);
+
 	g_signal_connect (G_OBJECT (commit_select_all_button), "clicked",
 					  G_CALLBACK (git_select_all_status_items),
 					  commit_status_view);
@@ -165,6 +225,8 @@ commit_dialog (Git *plugin)
 	g_object_weak_ref (G_OBJECT (commit_status_view),
 					   (GWeakNotify) git_disconnect_data_arrived_signals,
 					   status_command);
+
+	
 	
 	anjuta_command_start (ANJUTA_COMMAND (status_command));
 	



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]