[gitg/wip/clone] dash: clone repository in another thread to not block UI



commit 608af0f9406f80173cd8e40a832d2f14e591a632
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Mar 21 20:36:06 2013 +0100

    dash: clone repository in another thread to not block UI

 libgitg-gtk/gitg-gtk-dash-view.vala |   55 +++++++++++++++++++++++++++-------
 1 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/libgitg-gtk/gitg-gtk-dash-view.vala b/libgitg-gtk/gitg-gtk-dash-view.vala
index dda384a..d291b20 100644
--- a/libgitg-gtk/gitg-gtk-dash-view.vala
+++ b/libgitg-gtk/gitg-gtk-dash-view.vala
@@ -203,7 +203,7 @@ namespace GitgGtk
                        {
                                data.arrow.hide();
                                data.spinner = new Spinner();
-                               data.grid.attach(data.arrow, 2, 0, 1, 2);
+                               data.grid.attach(data.spinner, 3, 0, 1, 2);
                                data.spinner.show();
                                data.spinner.start();
                        }
@@ -255,24 +255,55 @@ namespace GitgGtk
                        add_repository_to_recent_manager(uri);
                }
 
-               public void clone_repository(string url, File location)
+               private async Gitg.Repository? clone(string url, File location)
                {
+                       SourceFunc callback = clone.callback;
                        Gitg.Repository? repository = null;
 
-                       try
-                       {
-                               repository = Ggit.Repository.clone(url, location, null) as Gitg.Repository;
-                               add_repository(repository);
+                       ThreadFunc<void*> run = () => {
+                               try
+                               {
+                                       repository = Ggit.Repository.clone(url, location, null) as 
Gitg.Repository;
+                               }
+                               catch {}
 
-                               RepositoryData? data = get_data_for_repository(repository);
-                               data.arrow.hide();
+                               Idle.add((owned) callback);
+                               return null;
+                       };
 
-                               data.spinner = new Spinner();
-                               data.grid.attach(data.spinner, 2, 0, 1, 2);
-                               data.spinner.show();
-                               data.spinner.start();
+                       try
+                       {
+                               new Thread<void*>.try("gitg-clone-thread", run);
+                               yield;
                        }
                        catch {}
+
+                       return repository;
+               }
+
+               public void clone_repository(string url, File location)
+               {
+                       RepositoryData? data = create_repository_data(location.get_path(), "Cloning...", 
true);
+
+                       clone.begin(url, location, (obj, res) => {
+                               Gitg.Repository? repository = clone.end(res);
+
+                               Gitg.Ref? head = null;
+                               string branch_name = "";
+
+                               try
+                               {
+                                       head = repository.get_head();
+                                       branch_name = head.parsed_name.shortname;
+                               }
+                               catch {}
+
+                               data.repository = repository;
+                               data.branch_label.set_markup("<small>%s</small>".printf(branch_name));
+                               data.spinner.stop();
+                               data.spinner.hide();
+                               data.arrow.show();
+                       });
                }
 
                public void filter_text(string? text)


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