GitMonitor.vala
[gitlive] / GitMonitor.vala
index f95ee7a..4c7dfde 100644 (file)
@@ -1,165 +1,5 @@
 
-
-public class GitMonitorQueue : MonitorNamePathDir {
-               // name = basename
-               // path = full path..
-               // dir = dir path
-       
-               public string gitpath;
-               public string vdir;  // relative path (within git)
-               public string vname;  // relative filename (within git)
-               public string message ; // for commit
-               public bool commit_all;
-                
-               public GitMonitorQueue(MonitorNamePathDir f) {
-
-                       base(f.name, f.path, f.dir);
-                       this.message = "";
-                       this.commit_all = false;
-                       
-                       var vpath_ar = this.dir.substring(GitMonitor.gitlive.length +1).split("/", 0);
-                       
-                       if (vpath_ar[0].length < 1) {
-
-                               this.gitpath = "";
-                               this.vdir = "";
-                               this.vname = "";
-                       }        
-
-
-                       this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0];
-                       
-                       string[]  vpath = {};
-                       for (var i = 1; i< vpath_ar.length; i++) {
-                               vpath += vpath_ar[i];
-                       }
-
-                       this.vdir =  string.joinv("/", vpath);
-
-                       this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
-                       
-                        
-/*
-                       stdout.printf(
-                                       "NEW GitMonitorQueue\nname: %s\npath: %s\ndir: %s\n" + 
-                                       "gitpath: %s\nvdir: %s\nvname: %s\n",
-                                       this.name, this.path, this.dir,
-                                       this.gitpath, this.vdir, this.vname
-                       );
-*/
-
-                       //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
-               
-               
-               }
-
-               public bool shouldIgnore()
-               {
-                       
-                
-                       // vim.. what a seriously brain dead program..
-                       if (this.name == "4913") {
-                               return true;
-                       }
-                       
-                       if (this.name[0] == '.') {
-                               // except!
-                               if (this.name == ".htaccess") {
-                                       return false;
-                               }
-                               if (this.name == ".gitignore") {
-                                       return false;
-                               }
-                               return true;
-                       }
-                       
-                       
-                       if (this.name[this.name.length -1] == '~') {
-                               return true;
-                       }
-                       // netbeans / android studio.. silly temp files..
-                       
-                       if (Regex.match_simple("___jb_old___$", this.name)) {
-                           return true;
-                       }
-                       if (Regex.match_simple("___jb_bak___$", this.name)) {
-                           return true;
-                       }
-                       //if (f.name.match(/^nbproject/)) {
-                       //    return true;
-                       //}
-                       // ignore anything in top level!!!!
-                       if (this.gitpath.length < 1) {
-                               return true;
-                       }
-                       
-                       return false;
-               }
-               
-               /** -- statics --*/
-               
-               public static int indexOfAdd( Array<GitMonitorQueue> add_files, string add)
-               {
-                       for(var i =0; i < add_files.length; i++) {
-                               if (add_files.index(i).vname == add) {
-                                       return i;
-                               }
-                       }
-                       return -1;
-               }
-               public static  int indexOfMessage(Array<GitMonitorQueue> messages, string message)  {
-                       for(var i =0; i < messages.length; i++) {
-                               if (messages.index(i).message == message) {
-                                       return i;
-                               }
-                       }
-                       return -1;
-               }
-               public static string messageToString(Array<GitMonitorQueue> messages ) {
-                       string[] ret = {};
-                       for(var i =0; i < messages.length; i++) {
-                               ret+= messages.index(i).message;
-                       }
-                       return string.joinv("\n",ret);
-               }
-               public static string queueArrayToString(Array<GitMonitorQueue> list) {
-                       var ret = "";
-                       for(var i =0; i < list.length; i++) {
-                               
-                               ret += (ret.length > 0 ? ", " : "") + list.index(i).vname;
-                       }
-                       return ret;
-                       
-               }
-               
-               public static bool  queueHas(Array<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
-                       for(var i =0; i < list.length; i++) {
-                               var test = list.index(i);
-                               if (list.index(i).gitpath != cmd_s.gitpath) {
-                                       continue;
-                               }
-                               if (list.index(i).vname != cmd_s.vname) {
-                                       continue;
-                               }
-                               if (list.index(i).action != action) {
-                                       continue;
-                               }
-                               return true;
-                       }
-                       return false;
-               }
-               public string fullpath()
-               {
-                       return this.gitpath + "/" + this.vname;
-               }
-               
-                       
-                       
-}
-
-
+  
 
 public class GitMonitor : Monitor
 {
@@ -178,13 +18,16 @@ public class GitMonitor : Monitor
        
        public DateTime lastAdd;
 
-       public GitMonitor () {
+
+       public GitMonitor ()
+       {
+       
                this.queue = new Array<GitMonitorQueue>();
                GitMonitor.gitmonitor = this;
-               
-               Timeout.add_full(Priority.LOW, 1000, () => {
-                       
-                       //print("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
+               Timeout.add_full(Priority.LOW, 500, () => {
+
+                       //GLib.debug("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
 
                        //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
                        if (this.queue.length < 1  || this.queueRunning) {
@@ -206,7 +49,6 @@ public class GitMonitor : Monitor
                        return true; //
                });
                
-               
        }
 
        public new void pauseError(string failure) 
@@ -222,7 +64,18 @@ public class GitMonitor : Monitor
                notification.set_timeout(60); // show errros for longer
                notification.show();
                
-               
+        Canberra.Context context;
+        Canberra.Proplist props;
+
+        Canberra.Context.create (out context);
+        Canberra.Proplist.create (out props);
+
+        props.sets (Canberra.PROP_EVENT_ID, "phone-outgoing-busy");
+        props.sets (Canberra.PROP_EVENT_DESCRIPTION, "Gitlive stopped on error");
+
+        context.play_full (0, props, null);
+
 
                        
        
@@ -299,7 +152,7 @@ public class GitMonitor : Monitor
                                notification.set_timeout(5);
                                notification.show();
                        } catch(Error e) {
-                               GLib.debug("Error sending notification to screen: %s\n",e.message);
+                               GLib.debug("Error sending notification to screen: %s",e.message);
                        }
                        return false; // do not keep doing this..
 
@@ -388,21 +241,29 @@ public class GitMonitor : Monitor
 
                this.paused = true;
 
-               GLib.debug("GitMonitor.runQueue - creating repos\n");
+               var leave_queued = new Gee.ArrayList<GitMonitorQueue>();
+               GLib.debug("GitMonitor.runQueue - creating repos");
                
                for(var i = 0; i < cmds.length; i++) {
                   
                        var cmd = cmds.index(i);
                
                        var gitpath = cmd.gitpath; 
-                       GLib.debug("GitMonitor.runQueue - finding %s\n", cmd.gitpath);
+                       
+                       var repo = GitRepo.get( gitpath );
+                       if ( !repo.is_wip_branch()) {
+                               leave_queued.add(cmd);
+                               continue;
+                       }
+                       
+                       GLib.debug("GitMonitor.runQueue - finding %s", cmd.gitpath);
                
-                       var ix  = GitRepo.indexOf(repo_list,  cmd.gitpath);
+                       var ix  = GitRepo.indexOf(repo_list,   gitpath);
                        if (ix < 0) {
-                               repo_list.append_val(new GitRepo( gitpath ));
+                               repo_list.append_val( GitRepo.get( gitpath ));
                                ix = GitRepo.indexOf(repo_list,  cmd.gitpath);
                        }
-                       GLib.debug("GitMonitor.runQueue - adding to repolist %d\n", ix);
+                       GLib.debug("GitMonitor.runQueue - adding to repolist %d", ix);
 
                        //if (typeof(repo_list[gitpath]) == 'undefined') {
                        //    repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
@@ -415,7 +276,7 @@ public class GitMonitor : Monitor
                this.paused = false;
                // build add, remove and commit message list..
 
-               GLib.debug("GitMonitor.runQueue - creating actions\n");
+               GLib.debug("GitMonitor.runQueue - creating actions");
                
                for(var i = 0;i < repo_list.length;i++) {
         
@@ -470,8 +331,11 @@ public class GitMonitor : Monitor
                                                break;
                                } 
                        }
-                       GLib.debug( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files));
-                       GLib.debug( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files));
+                       
+                       repo.cmds.clear();
+                       
+                       GLib.debug( "ADD : %s", GitMonitorQueue.queueArrayToString(add_files));
+                       GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files));
                        
                        //repo.debug = 1;
                        // these can fail... at present... as we wildcard stuff.
@@ -516,8 +380,8 @@ public class GitMonitor : Monitor
                                add_files_f.append_val(add_files.index(ii));
                        };
                        
-                       GLib.debug( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files_f));
-                       GLib.debug( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files_f));
+                       GLib.debug( "ADD : %s", GitMonitorQueue.queueArrayToString(add_files_f));
+                       GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files_f));
                    
                    if (add_files_f.length < 1 && remove_files_f.length < 1) {
                                continue;
@@ -545,7 +409,7 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               GLib.debug("Add failed:\n");
+                               GLib.debug("Add failed:");
                        }  
                        try {
                                 repo.remove(remove_files_f);
@@ -553,7 +417,7 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               GLib.debug("Remove failed:\n");
+                               GLib.debug("Remove failed:");
                        }  
 
 
@@ -569,7 +433,7 @@ public class GitMonitor : Monitor
                                // if the error is 'nothing to commit, working tree clean'
                                // then it's not an error, - just continue;
                                if (/nothing to commit, working tree clean/.match(e.message)) {
-                                       GLib.debug("%s\n",e.message);
+                                       GLib.debug("%s",e.message);
                                        success += e.message;
                                        this.paused = false; 
                                        continue;
@@ -651,15 +515,15 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               GLib.debug("GitMonitor.onChangedHint\n");                               
+               GLib.debug("GitMonitor.onChangedHint");                         
 
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
+                       GLib.debug("GitMonitor.onChangedHint - ignored");
                        return;
                }
                
-          
                //var add_it = false;
                /*
                if (this.is_just_created(cmd.path)) {
@@ -692,7 +556,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               GLib.debug("GitMonitor.onDeleted\n");                   
+               GLib.debug("GitMonitor.onDeleted");                     
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -716,7 +580,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               GLib.debug("GitMonitor.onCreated\n");                   
+               GLib.debug("GitMonitor.onCreated");                     
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -747,7 +611,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               GLib.debug("GitMonitor.onAttributeChanged\n");                  
+               GLib.debug("GitMonitor.onAttributeChanged %s", src.name);                       
                if (src.dir == GitMonitor.gitlive) {
                   return; // attribute on top level..
                }
@@ -772,7 +636,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               GLib.debug("GitMonitor.onMoved\n");                     
+               GLib.debug("GitMonitor.onMoved");                       
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd_s = new GitMonitorQueue(src);
 
@@ -802,13 +666,13 @@ public class GitMonitor : Monitor
                }
                
                
-               GLib.debug("RM: %s\n", cmd_s.vname);
+               GLib.debug("RM: %s", cmd_s.vname);
                cmd_s.action = "rm";
                this.queue.append_val(cmd_s);
 
                
                
-               GLib.debug("ADD: %s\n", cmd_d.vname);
+               GLib.debug("ADD: %s", cmd_d.vname);
                cmd_d.action = "add";
                this.queue.append_val(cmd_d);