sync
authorAlan Knowles <alan@roojs.com>
Wed, 20 Mar 2019 10:22:32 +0000 (18:22 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 20 Mar 2019 10:22:32 +0000 (18:22 +0800)
Clones.bjs
Clones.vala
Git.vala
GitBranch.vala
GitMonitor.vala
GitMonitorQueue.vala
GitRepo.vala
Gitlive.vala
StatusIcon.vala

index d1c1402..75f1f87 100644 (file)
@@ -69,7 +69,7 @@
        "items" : [
         {
          "listeners" : {
-          "row_activated" : "(path, col)  =>  {\n\n\tif (col.title == \"Auto Commit\" || col.title == \"Auto Push\" || col.title == \"Auto Branch\") {\n\t\treturn;\n\t}\n\t\n\t//\n\t\n\tGtk.TreeIter iter;\n\t_this.reposStore.el.get_iter(out iter, path);\n\tGLib.Value val;\n    _this.reposStore.el.get_value(iter, 6, out val);\n    var git_working_dir = (string)val;\n    \n    var repo = GitRepo.singleton().get(git_working_dir);\n    \n    Gdk.Rectangle rect;\n    _this.reposView.el.get_cell_area(path, col, out rect);\n    RepoStatusPopover.singleton().show(this.el, rect, repo);\n    \n     \n    \n}",
+          "row_activated" : "(path, col)  =>  {\n\n\tif (col.title == \"Auto Commit\" || col.title == \"Auto Push\" || col.title == \"Auto Branch\") {\n\t\treturn;\n\t}\n\t\n\t//\n\t\n\tGtk.TreeIter iter;\n\t_this.reposStore.el.get_iter(out iter, path);\n\tGLib.Value val;\n    _this.reposStore.el.get_value(iter, 6, out val);\n    var git_working_dir = (string)val;\n    \n    var repo = GitRepo.singleton().get_sync(git_working_dir);\n    \n    Gdk.Rectangle rect;\n    _this.reposView.el.get_cell_area(path, col, out rect);\n    RepoStatusPopover.singleton().show(this.el, rect, repo);\n    \n     \n    \n}",
           "cursor_changed" : "()  => {\n  // SEE SELECTION.CHANGED\n  /*\n  \n  return;\n  \n    if (this.el.get_selection().count_selected_rows() < 1) {\n        //nothing? - clea it?\n        return;\n    }\n        var ret = {};         \n    var model = this.get('/changedFilesStore');\n\n     var s = this.el.get_selection();\n     var files = [];\n    s.selected_foreach(function(model,p,iter) {\n    \n       files.push( model.get_value(iter, 0).value.get_string());\n     \n    });\n    this.get('/patchview').showDiff(files); \n    //var value = ''+ ret.model.get_value(ret.iter, 1).value.get_string();\n     //print(\"OUT?\" + value);// id..\n    // load the list in the right grid..\n     \n    return true;\n*/\n}"
          },
          "id" : "reposView",
            "items" : [
             {
              "listeners" : {
-              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 4, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 4, !bval);\n  \tGLib.debug(\"got repopath? %s\", repopath);\n  \t\n  \tvar repo = GitRepo.get(repopath);\n  \trepo.set_autocommit(!bval);\n  \t\n  \t\n  \t\n  \n}"
+              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 4, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 4, !bval);\n  \tGLib.debug(\"got repopath? %s\", repopath);\n  \t\n  \tvar repo = GitRepo.get_sync(repopath);\n  \trepo.set_autocommit(!bval);\n  \t \n  \n}"
              },
              "id" : "cr_autocommit",
              "* pack" : "pack_start,false",
            "items" : [
             {
              "listeners" : {
-              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 5, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 5, !bval);\n  \tvar repo = GitRepo.get(repopath);\n  \trepo.set_autopush(!bval);\n  \t\n  \t\n  \t\n  \n}"
+              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 5, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 5, !bval);\n  \tvar repo = GitRepo.get_sync(repopath);\n  \trepo.set_autopush(!bval);\n  \t\n  \t\n  \t\n  \n}"
              },
              "id" : "cr_autopush",
              "* pack" : "pack_start,false",
            "items" : [
             {
              "listeners" : {
-              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 8, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 8, !bval);\n  \tvar repo = GitRepo.get(repopath);\n  \trepo.set_auto_branch(!bval);\n  \t\n  \t\n  \t\n  \n}"
+              "toggled" : "  (self, path)  => {\n  \n  \tGtk.TreeIter iter;\n  \t_this.reposStore.el.get_iter_from_string(out iter, path);\n  \t\n  \tGLib.Value val;\n  \tGLib.Value rval;\n  \t_this.reposStore.el.get_value(iter, 8, out val);\n  \t_this.reposStore.el.get_value(iter, 6, out rval);\n  \t\n  \tvar repopath = (string)rval;\n  \tvar bval = (bool)val;\n  \t_this.reposStore.el.set_value(iter, 8, !bval);\n  \tvar repo = GitRepo.get_sync(repopath);\n  \trepo.set_auto_branch(!bval);\n  \t\n  \t\n  \t\n  \n}"
              },
              "id" : "cr_autobranch",
              "xtype" : "CellRendererToggle",
index 123d5ae..8e066fb 100644 (file)
@@ -361,7 +361,7 @@ public class Clones : Object
                 _this.reposStore.el.get_value(iter, 6, out val);
                 var git_working_dir = (string)val;
                 
-                var repo = GitRepo.singleton().get(git_working_dir);
+                var repo = GitRepo.singleton().get_sync(git_working_dir);
                 
                 Gdk.Rectangle rect;
                 _this.reposView.el.get_cell_area(path, col, out rect);
@@ -577,11 +577,9 @@ public class Clones : Object
                _this.reposStore.el.set_value(iter, 4, !bval);
                GLib.debug("got repopath? %s", repopath);
                
-               var repo = GitRepo.get(repopath);
+               var repo = GitRepo.get_sync(repopath);
                repo.set_autocommit(!bval);
-               
-               
-               
+                
               
             });
         }
@@ -656,7 +654,7 @@ public class Clones : Object
                var repopath = (string)rval;
                var bval = (bool)val;
                _this.reposStore.el.set_value(iter, 5, !bval);
-               var repo = GitRepo.get(repopath);
+               var repo = GitRepo.get_sync(repopath);
                repo.set_autopush(!bval);
                
                
@@ -735,7 +733,7 @@ public class Clones : Object
                var repopath = (string)rval;
                var bval = (bool)val;
                _this.reposStore.el.set_value(iter, 8, !bval);
-               var repo = GitRepo.get(repopath);
+               var repo = GitRepo.get_sync(repopath);
                repo.set_auto_branch(!bval);
                
                
index b62439e..66b4209 100644 (file)
--- a/Git.vala
+++ b/Git.vala
@@ -1,7 +1,6 @@
 
 // valac -o /tmp/ggit Git.vala --pkg libgit2-glib-1.0 --pkg libsoup-2.4 --pkg gee-0.8 -g
-
-
 
 void main()
 {
@@ -26,8 +25,8 @@ void main()
     }, GLib.Priority.HIGH);
        
        var loop = new MainLoop();
-       
-       var a = new GitLive.Repo("/home/alan/gitlive/gitlive");
+        
+       var a = new GitLive.Repo("/home/alan/gitlive/web.coba");
       GLib.debug("Starting");  
        a.loadRemoteHeads.begin(true, (obj,res) => {
                a.loadRemoteHeads.end(res);
@@ -104,19 +103,26 @@ namespace  GitLive {
                        var r = this.repo.enumerate_branches(Ggit.BranchType.LOCAL);
                        while (r.next()) {
                                var br = r.get() as Ggit.Branch;
+                               if (br == null) {
+                                       continue;
+                                       }
+                               
                                //var head = this.repo.revparse("refs/heads/" + br.get_name() ).get_id();
                                //var rhead = this.repo.revparse(br.get_upstream().get_name() ).get_id();
-                           GLib.debug("got branch: H=%s name = %s upstream = %s oid = %s ", 
-                                               br.is_head() ? "Y" : "n",
-                                               br.get_name(), 
-                                               br.get_upstream().get_name().substring(20), 
-                                           br.get_target().to_string());
-                               this.branches.add(br);
-                               if (br.is_head()) {
-                                       GLib.debug("HEAD= %s", br.get_name());
-                                       this.head = br;
+                               try {
+                                       GLib.debug("got branch: N=%s", br.get_name() );
+                                       GLib.debug("is_head %s", br.is_head() ? "Y" : "n");
+
+                                       GLib.debug("upstream = %s", br.get_upstream() == null ? "??" : br.get_upstream().get_name().substring(20));
+                                       GLib.debug("oid = %s",br.get_target().to_string());
+                                       this.branches.add(br);
+                                       if (br.is_head()) {
+                                               GLib.debug("HEAD= %s", br.get_name());
+                                               this.head = br;
+                                       }
+                               } catch (Error e) {
+                                       GLib.debug("Skip branch");
                                }
-                               
                        }
                        
                        
index 58da00f..20e36fd 100644 (file)
@@ -92,11 +92,18 @@ public class GitBranch : Object
                while (r.next()) {
                        var br = new GitBranch(repo);
                        var gbr = r.get() as Ggit.Branch;
-                       repo.branches.set(gbr.get_name(), br);
+
                        br.active = gbr.is_head();
                        br.name = gbr.get_name();
                        br.lastrev = gbr.get_target().to_string();
-                       var rname = gbr.get_upstream() != null ? gbr.get_upstream().get_name() : "";
+                       string rname ;
+                       try {
+                               rname = gbr.get_upstream() != null ? gbr.get_upstream().get_name() : "";
+                       } catch(Error e) {
+                               GLib.debug("Skip branch = got error");
+                               continue;
+                       }
+                       repo.branches.set(gbr.get_name(), br);                  
                        if (rname.has_prefix("refs/remotes/origin/")) {
                                rname = rname.substring(20);
                                if (remotes.has_key(rname)) {
@@ -119,6 +126,10 @@ public class GitBranch : Object
                                // age?
                                // behind or infront..
                        }
+                       if (br.active) {
+                               GLib.debug("repo: %s currentBranch = %s", repo.name, br.name);
+                               repo.currentBranch = br;
+                       }
                        
                }
                
@@ -140,6 +151,9 @@ public class GitBranch : Object
                        repo.branches.set(rn, br);
                        
                }
+               if (repo.currentBranch == null) {
+                       GLib.error("could not find active Branch for %s", repo.name);
+               }
                
                         
                
index 1b11558..4c79f5e 100644 (file)
@@ -171,24 +171,8 @@ public class GitMonitor : Monitor
 
                                this.monitor(this.top.index(i) );
                        }
-                       StatusIconA.statusicon.resume();
-                   this.paused = false;
-                  
                        
-                       try {
-
-                         
-                               var notification = new Notify.Notification(
-                                       "Git Live",
-                                       "%s\nMonitoring %u Directories".printf(GitMonitor.gitlive, this.monitors.length), 
-                                        "dialog-information"
-                               );
-               
-                               notification.set_timeout(5);
-                               notification.show();
-                       } catch(Error e) {
-                               GLib.debug("Error sending notification to screen: %s",e.message);
-                       }
+                       
                        return false; // do not keep doing this..
 
                });
@@ -197,7 +181,29 @@ public class GitMonitor : Monitor
                
                 
        }
+       int scanning = 0;
+       int scancomplete = 0;
+       public void updateMonitorsComplete()
+       {
+               StatusIconA.statusicon.resume();
+           this.paused = false;
+          
+               
+               try {
 
+                 
+                       var notification = new Notify.Notification(
+                               "Git Live",
+                               "%s\nMonitoring %u Directories".printf(GitMonitor.gitlive, this.monitors.length), 
+                                "dialog-information"
+                       );
+       
+                       notification.set_timeout(5);
+                       notification.show();
+               } catch(Error e) {
+                       GLib.debug("Error sending notification to screen: %s",e.message);
+               }
+       }
 
        public new void stop() {
                StatusIconA.statusicon.pause();
@@ -205,12 +211,18 @@ public class GitMonitor : Monitor
        }
        
        
+       // this is called recursively until we end..
+       
        public override void monitor (string path,  int depth = 0)
        {
                
                //GLib.debug("GitMonitor : monitor %d %s", depth, path);
                //var depth = typeof(depth) == 'number'  ? depth *1 : 0;
                
+               if (depth == 0) {
+                       this.scancomplete = 0;  
+                       this.scanning = 0;      
+               }
                 
                // if we are not at top level.. and there is a .git directory  (it's a submodule .. ignore) 
                if (depth > 1 && FileUtils.test(path + "/.git" , FileTest.IS_DIR)) {
@@ -222,9 +234,17 @@ public class GitMonitor : Monitor
                        if (!FileUtils.test(path + "/.git" , FileTest.IS_DIR)) {
                                return; // skip non-git directories..
                        }
-               
-                       GitRepo.get(path);
-               
+                       this.scanning++;
+                       GitRepo.get.begin(path, (ojb,res) => {
+                               
+                               GitRepo.get.end(res);
+                               base.monitor(path, depth);
+                               this.scanning--;
+                               if (this.scanning == 0 && this.scancomplete == 1) {
+                                       this.updateMonitorsComplete();
+                               }
+                       });
+                       return;
                        // FIXME - check if repo is flagged as not autocommit..
                        //var repo = imports.Scm.Repo.Repo.get(path);
                        //if (!repo || !repo.autocommit()) {
@@ -238,6 +258,11 @@ public class GitMonitor : Monitor
                
                
                base.monitor(path, depth);
+               if (depth == 0) {
+                       this.scancomplete = 1;          
+               }
+               
+               
        }
 
        
@@ -306,7 +331,7 @@ public class GitMonitor : Monitor
                
                        var gitpath = cmd.gitpath; 
                        
-                       var repo = GitRepo.get( gitpath );
+                       var repo = GitRepo.get_sync( gitpath );
                        if ( repo.is_master_branch() && repo.is_auto_branch()) {
                                leave_queued.add(cmd);
                                continue;
@@ -316,7 +341,7 @@ public class GitMonitor : Monitor
                
                        var ix  = GitRepo.indexOf(repo_list,   gitpath);
                        if (ix < 0) {
-                               repo_list.append_val( GitRepo.get( gitpath ));
+                               repo_list.append_val( GitRepo.get_sync( gitpath ));
                                ix = GitRepo.indexOf(repo_list,  cmd.gitpath);
                        }
                        GLib.debug("GitMonitor.runQueue - adding to repolist %d", ix);
index 00ab465..ff3bd28 100644 (file)
@@ -41,7 +41,7 @@ public class GitMonitorQueue : MonitorNamePathDir {
 
                        this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
                        
-                       this.repo = GitRepo.get(this.gitpath);
+                       this.repo = GitRepo.get_sync(this.gitpath);
                        
                        // trigger the suggestion to start a new branch
                        
index e18872b..3c25835 100644 (file)
@@ -25,7 +25,9 @@ public class GitRepo : Object
     public string ahead_or_behind = "";
     
     public Gee.HashMap<string,bool> ignore_files;
-    public GitBranch currentBranch;
+     
+    public GitBranch  currentBranch;
+    
     public Gee.HashMap<string,GitBranch> branches; // accessed in GitBranch..
        public RooTicket? activeTicket;
     public Gee.HashMap<string,GitRepo> cache;
@@ -48,7 +50,7 @@ public class GitRepo : Object
     */
     public static int indexOf( Array<GitRepo> repos, string gitpath) {
         // make a fake object to compare against..
-        var test_repo = GitRepo.get(gitpath);
+        var test_repo = GitRepo.get_sync(gitpath);
         
         for(var i =0; i < repos.length; i++) {
             if (repos.index(i).gitdir == test_repo.gitdir) {
@@ -128,7 +130,7 @@ public class GitRepo : Object
                 continue;
             }
             
-               var rep =  GitRepo.get(  sp );
+               var rep =  GitRepo.get_sync(  sp );
                list_cache.append_val(rep);             
             
         }
@@ -137,13 +139,39 @@ public class GitRepo : Object
          
        }
        
-       public static GitRepo get(string path) 
+       public  static GitRepo get_sync(string path) 
        {
+               GitRepo ret;
                var cache = GitRepo.singleton().cache;
                if (cache.has_key(path)) {
-                       return cache.get(path);
+                       ret =  cache.get(path);
+               } else {
+                       ret =  new GitRepo(path);
                }
-               return new GitRepo(path);
+               return ret;
+       }
+        
+       public static  async  GitRepo? get(string path) 
+       {
+               
+               SourceFunc callback = GitRepo.get.callback;
+               GitRepo ret = null;
+               ThreadFunc<bool> run = () => {
+                       
+                       var cache = GitRepo.singleton().cache;
+                       if (cache.has_key(path)) {
+                               ret =  cache.get(path);
+                       } else {
+                               ret =  new GitRepo(path);
+                       }
+                       Idle.add((owned) callback);
+               return true;
+                       
+               };
+               new Thread<bool>("thread-new-gitrepo", run);
+               yield;
+               return ret;
+               
        }
        
     private GitRepo.single() {
@@ -927,7 +955,43 @@ public class GitRepo : Object
     
     }
     
+    
+    public void doUpdate()
+    {
+       // update the branches..
+       
+    
+    }
+    
+       
+       public static void updateAllAsync(string after)
+       {
+               var done = 0;
+               
+               var tr =  GitRepo.singleton().cache;
+         
+       var update_all_total = tr.size;
+       foreach(var repo  in tr.values) {
+                       repo.doUpdate.begin((obj, res) => {
+                               GitRepo.updateRepo.end(res);
+                               done++;
+                               if (update_all_total != done) {
+                                       return;
+                               }
+                               switch (after) {
+                                       case "show_clones":
+                                               Clones.singleton().show();
+                                               break;
+                                       default:
+                                               GLib.debug("Unkown call after load = %s", update_all_after);            
+                                               break;
+                               }
+                       }
+               }
+                
+       
+       }
+       
         
     
  
@@ -958,6 +1022,9 @@ public class GitRepo : Object
         } 
                GLib.debug("calls total = %d", (int) update_all_total);
     }
+    
+    
+    
     public static void  updateAllCallback(GitRepo repo, int err, string res)
     {
        repo.loadBranches();
index e3ded34..4c790f5 100644 (file)
@@ -38,7 +38,7 @@ static int main (string[] args) {
             }
          ); 
 
-
+       Ggit.init();
     Gtk.init (ref args);
     
     GitMonitor.gitlive =  Environment.get_home_dir() + "/gitlive";
index d6b34d1..4363d8d 100644 (file)
@@ -306,47 +306,7 @@ public class StatusIconA : StatusIcon {
                 this.activate.connect( () => {
                     
                     this.pullAll();
-                    /*
-                    GitMonitor.gitmonitor.stop();
-                    var tr = GitRepo.list();
-                    
-                    
-                    
-                    for (var i= 0; i< tr.length;i++) {
-                        statusicon.set_from_stock( 
-                               i%2 == 0 ?  Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
-                                
-                        var repo = tr.index(i);
-                        //if (!repo.autocommit()) {
-                            //??? should we ignore ones not on autocommit..
-                        //    continue;
-                        //}
-                        try {
-                            statusicon.set_tooltip_text("pull: " + repo.name);
-                            var str = repo.pull();
-                                    // do not care if it's already in sycn..
-                            if (Regex.match_simple ("Already up-to-date", str) ) {
-                                continue;
-                            }
-                            var notification = new Notify.Notification( 
-                                     "Updated " + repo.name,
-                                     str,
-                                       "dialog-information"
-                                   
-                            );
-                        
-                            notification.set_timeout(20);
-                            notification.show();
-                                     
-                        } catch(Error e) {
-                            print("notification or push errror- probably to many in queue..");
-                            statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
-                            print(e.message);
-                            
-                        }        
-
-                    } 
-                    */
+                   
                            
                            
                 });