[gitg] Set author to original author when amending a commit



commit b79bad2adb72767679744d24dc8ef89f971685e7
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sat Jul 6 16:48:27 2013 +0200

    Set author to original author when amending a commit

 gitg/commit/gitg-commit-dialog.vala |   65 +++++++++++++++++++++++------------
 gitg/commit/gitg-commit.vala        |   29 ++++++++++------
 2 files changed, 61 insertions(+), 33 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index c3e5019..f20bbec 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -93,13 +93,53 @@ class Dialog : Gtk.Dialog
        public bool sign_off { get; set; }
 
        [Notify]
-       public Ggit.Signature author { owned get; construct set; }
+       public Ggit.Signature author
+       {
+               owned get { return d_author; }
+
+               construct set
+               {
+                       d_author = value;
+                       load_author_info();
+               }
+       }
 
-       private Cancellable d_cancel_avatar;
+       private void load_author_info()
+       {
+               if (d_cancel_avatar != null)
+               {
+                       d_cancel_avatar.cancel();
+                       d_cancel_avatar = new Cancellable();
+               }
+
+               var name = d_author.get_name();
+               var email = d_author.get_email();
+
+               d_label_user.set_label(@"$name <$email>");
+               d_label_date.set_label((new Gitg.Date.for_date_time(d_author.get_time())).for_display());
+
+               var ac = Gitg.AvatarCache.default();
+               d_cancel_avatar = new Cancellable();
+
+               ac.load.begin(d_author.get_email(), d_cancel_avatar, (obj, res) => {
+                       var pixbuf = ac.load.end(res);
+
+                       if (pixbuf != null && !d_cancel_avatar.is_cancelled())
+                       {
+                               d_image_avatar.set_from_pixbuf(pixbuf);
+                       }
+               });
+       }
+
+       private Ggit.Signature d_author;
+       private Cancellable? d_cancel_avatar;
 
        ~Dialog()
        {
-               d_cancel_avatar.cancel();
+               if (d_cancel_avatar != null)
+               {
+                       d_cancel_avatar.cancel();
+               }
        }
 
        construct
@@ -136,24 +176,6 @@ class Dialog : Gtk.Dialog
                                     SettingsBindFlags.GET |
                                     SettingsBindFlags.SET);
 
-               var name = author.get_name();
-               var email = author.get_email();
-
-               d_label_user.set_label(@"$name <$email>");
-               d_label_date.set_label((new Gitg.Date.for_date_time(author.get_time())).for_display());
-
-               var ac = Gitg.AvatarCache.default();
-               d_cancel_avatar = new Cancellable();
-
-               ac.load.begin(author.get_email(), d_cancel_avatar, (obj, res) => {
-                       var pixbuf = ac.load.end(res);
-
-                       if (pixbuf != null && !d_cancel_avatar.is_cancelled())
-                       {
-                               d_image_avatar.set_from_pixbuf(pixbuf);
-                       }
-               });
-
                var message_settings = new Settings("org.gnome.gitg.preferences.commit.message");
 
                message_settings.bind("show-right-margin",
@@ -167,7 +189,6 @@ class Dialog : Gtk.Dialog
                                      "right-margin-position",
                                      SettingsBindFlags.GET |
                                      SettingsBindFlags.SET);
-
        }
 
        public Dialog(Ggit.Signature author)
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 3752791..d4f83b2 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -483,9 +483,9 @@ namespace GitgCommit
                        return true;
                }
 
-               private async string? get_head_message()
+               private async Gitg.Commit? get_head_commit()
                {
-                       string? retval = null;
+                       Gitg.Commit? retval = null;
 
                        yield Gitg.Async.thread(() => {
                                var repo = application.repository;
@@ -493,9 +493,7 @@ namespace GitgCommit
                                try
                                {
                                        var head = repo.get_head();
-                                       var commit = repo.lookup<Ggit.Commit>(head.get_target());
-
-                                       retval = commit.get_message();
+                                       retval = repo.lookup<Gitg.Commit>(head.get_target());
                                } catch {}
                        });
 
@@ -514,7 +512,7 @@ namespace GitgCommit
                        dlg.response.connect((d, id) => {
                                if (id == Gtk.ResponseType.OK)
                                {
-                                       do_commit(dlg, skip_hooks, author, committer);
+                                       do_commit(dlg, skip_hooks, dlg.author, committer);
                                }
                                else
                                {
@@ -523,14 +521,23 @@ namespace GitgCommit
                        });
 
                        dlg.notify["amend"].connect((obj, pspec) => {
-                               if (dlg.message.strip() == "")
+                               if (!dlg.amend)
                                {
-                                       get_head_message.begin((obj, res) => {
-                                               string? message = get_head_message.end(res);
+                                       dlg.author = author;
+                               }
+                               else
+                               {
+                                       get_head_commit.begin((obj, res) => {
+                                               var commit = get_head_commit.end(res);
 
-                                               if (message != null && dlg.message.strip() == "")
+                                               if (commit != null)
                                                {
-                                                       dlg.message = message;
+                                                       if (dlg.message.strip() == "")
+                                                       {
+                                                               dlg.message = commit.get_message();
+                                                       }
+
+                                                       dlg.author = commit.get_author();
                                                }
                                        });
                                }



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