Uncommited changes synced
authorAlan Knowles <alan@roojs.com>
Fri, 28 Dec 2018 06:51:24 +0000 (14:51 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 28 Dec 2018 06:51:24 +0000 (14:51 +0800)
1  2 
GitRepo.vala
MergeBranch.bjs

diff --combined GitRepo.vala
@@@ -19,6 -19,7 +19,7 @@@ public class GitRepo : Objec
      public string git_working_dir;
      public bool debug = false;
      public bool has_local_changes = false;
+     public string host = "";
      public string git_status;    
      public string git_diff;        
      public string ahead_or_behind = "";
@@@ -28,6 -29,7 +29,7 @@@
      public Gee.HashMap<string,GitBranch> branches; // accessed in GitBranch..
        public RooTicket? activeTicket;
      public  Gee.HashMap<string,GitRepo> cache;
+     public  Gee.HashMap<string,string> config_cache;
      
      
      
       *
       */
       
-     private GitRepo(string path) {
+     private GitRepo(string path) 
+     {
          // cal parent?
          this.name =   File.new_for_path(path).get_basename();
          this.ignore_files = new Gee.HashMap<string,bool>();
                if ( !cache.has_key(path) ) {
                        cache.set( path, this);
        }
+       
+       var r = this.git({ "remote" , "get-url" , "--push" , "origin"});
+       var uri = new Soup.URI(r);      
+       this.host = uri.get_host();
+               this.init_config();
+       
        this.loadBranches();
        this.loadActiveTicket();
        this.loadStatus();
      } 
      
-     public bool is_wip_branch()
+     public bool is_master_branch()
      {
-       return this.currentBranch.name.has_prefix("wip_");
+       // special branches that do not allow autopushing now...
+       return this.currentBranch.name == "master" || this.currentBranch.name == "roojs";
                
      }
-     
-     public bool is_managed()
+     public void init_config()
      {
-       // is it a roojs origin?
-       var r = this.git({ "remote" , "get-url" , "--push" , "origin"});
-       var uri = new Soup.URI(r);
-       if (uri.get_host() != "git.roojs.com") { // we can only push to this url. -- unless we have forced it to be managed.
-               return FileUtils.test(this.gitdir + "/.gitlive-managed" , FileTest.EXISTS);
+       this.config_cache = new Gee.HashMap<string,string>();
+       // managed = 
+       if (this.get_config("managed") == "") {
+               this.set_config("managed", this.host == "git.roojs.com" ? "1" : "0");
+               }
+       if (this.get_config("autocommit") == "") {
+               this.set_config("autocommit", this.host == "git.roojs.com" ? "1" : "0");
+               }
+       if (this.get_config("autopush") == "") {
+               this.set_config("autopush", this.host == "git.roojs.com" ? "1" : "0");
+               }
+               
+     }
+     
+     
+     
+     public string get_config(string key) {
+     
+       if (this.config_cache.has_key(key)) {
+               //GLib.debug("get_config %s = '%s'", key, this.config_cache.get(key));
+               return this.config_cache.get(key);
+               }
+       try {
+               var ret =   this.git({ "config" , "gitlive." + key }).strip();
+               this.config_cache.set(key, ret);
+               //GLib.debug("get_config %s = '%s'", key, ret);
+               return ret;
+       } catch (Error e) {
+               this.config_cache.set(key, "");
+               //GLib.debug("get_config (fail) %s = '%s'", key, "");
+               return ""; // happens when there is nothing set...
        }
-       // otherwise see if unmanaged is set to disable it..
-       return !FileUtils.test(this.gitdir + "/.gitlive-unmanaged" , FileTest.EXISTS);  
  
+       }
+     public void set_config(string key, string value) {
+       this.git({ "config" , "gitlive." + key, value });
+       this.config_cache.set(key,value);
+       }
+     
+     public bool is_managed()
+     {
+       return this.get_config("managed") == "1";
      }
      
      
      public bool is_autocommit ()
-     {
-       return !FileUtils.test(this.gitdir + "/.gitlive-disable-autocommit" , FileTest.EXISTS);
+     {         
+       return this.get_config("autocommit") == "1";            
      }
+     
      public void set_autocommit(bool val)
      {
-               var cur = this.is_autocommit();
-               GLib.debug("SET auto commit : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
-               if (cur == val) {
-                       return; // no change..
-               }
-               if (!val) {
-                       FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autocommit" , "x");
-               } else {
-                       // it exists...
-                       FileUtils.remove(this.gitdir + "/.gitlive-disable-autocommit" ); 
-               }
+               this.set_config("autocommit", val ? "1" : "0");
      
      }
      
      public bool is_auto_branch ()
      {
-       return FileUtils.test(this.gitdir + "/.gitlive-enable-auto-branch" , FileTest.EXISTS);
+       if (this.name == "gitlog") {
+               return false;
+               }
+               // check remote...
+       if (this.is_managed()) {
+               return true;
+               }
+       return false;
+       
+  
      }
      
      public void set_auto_branch(bool val)
      {
-               var cur = this.is_auto_branch();
-               GLib.debug("SET auto branch : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
-               
-               if (cur == val) {
-                       return; // no change..
-               }
-               if (val) {
-                       FileUtils.set_contents(this.gitdir + "/.gitlive-enable-auto-branch" , "x");
-               } else {
-                       // it exists...
-                       FileUtils.remove(this.gitdir + "/.gitlive-enable-auto-branch" ); 
+               if (this.name == "gitlog") {
+               return;
                }
+               this.set_config("managed", val ? "1" : "0");
      
      }
      public bool is_autopush ()
      {
-       return !FileUtils.test(this.gitdir + "/.gitlive-disable-autopush" , FileTest.EXISTS);
+       return this.get_config("autopush") == "1";
      }
      public void set_autopush(bool val)
      {
-               var cur = this.is_autopush();
-               GLib.debug("SET auto push : %s <= %s", val ? "ON" : "OFF",  cur  ? "ON" : "OFF");
-               if (cur == val) {
-                       return; // no change..
-               }
-               if (!val) {
-                       FileUtils.set_contents(this.gitdir + "/.gitlive-disable-autopush" , "");
-               } else {
-                       // it exists...
-                       FileUtils.remove(this.gitdir + "/.gitlive-disable-autopush" ); 
-               }
-     
+               this.set_config("autopush", val ? "1" : "0");
      }
      
      
      public void loadActiveTicket()
      {
        this.activeTicket = null;
-       if (!FileUtils.test(this.gitdir + "/.gitlive-active-ticket" , FileTest.EXISTS)) {
-               return;
-       }
-       string ticket_id;
-       FileUtils.get_contents(this.gitdir + "/.gitlive-active-ticket" , out ticket_id);  
+               var ticket_id = this.get_config("ticket");
+       
        if (ticket_id.length < 1) {
                return;
                }
      
      public bool setActiveTicket(RooTicket? ticket, string branchname)
      {
+       this.set_config("ticket", "");
        if (!this.createBranchNamed(branchname)) {
                return false;
                }
-               if (ticket != null) {
-               FileUtils.set_contents(this.gitdir + "/.gitlive-active-ticket" , ticket.id);
-       } else {
-               FileUtils.remove(this.gitdir + "/.gitlive-active-ticket" );
-       }
+               this.set_config("ticket", ticket == null ? "": ticket.id);
        this.activeTicket = ticket;
        return true;
      }
                        return true;
       
       }
 +     
 +     public string previewMerge()
 +     {
 +       try {                                  
 +                      var lines = this.git({"log", "master...",  "--pretty=format:\"%H %P\"" }).split("\n");;
 +                      var head = this.git({"log", "-1",  "--pretty=format:\"%H %P\"" });
 +                      var last = lines[lines.length-1];
 +                      var start = head.split(" ")[0];
 +                      var end = last.split(" ")[1];
 +                      return this.git({ "diff" , start+".."+end, "--no-color" });
 +              }  catch(Error ee) {
 +                      GitMonitor.gitmonitor.pauseError(ee.message);
 +                      return "Error getting diff";            
 +              }
 +       
 +     
 +     }
      
      
      
         // may throw error...
          var sp = new Spawn(cfg);
        
+            //GLib.debug( "GOT result: %d" , sp.result);
+       
                // diff output is a bit big..
                if (args_in[0] != "diff") {
                GLib.debug( "GOT: %s" , sp.output);
                        }
             repo.update_async(updateAllCallback); 
          } 
+               GLib.debug("calls total = %d", (int) update_all_total);
      }
      public static void  updateAllCallback(GitRepo repo, int err, string res)
      {
        repo.loadStatus();
        
        update_all_total--;
+               GLib.debug("calls remaining = %d", (int)update_all_total);      
        if (update_all_total > 0 ) {
                return;
                }
+               GLib.debug("call after load = %s", update_all_after);    
+               
                switch (update_all_after) {
                        case "show_clones":
                                Clones.singleton().show();
                                break;
                        default:
+                               GLib.debug("Unkown call after load = %s", update_all_after);            
                                break;
                }
                return;
diff --combined MergeBranch.bjs
    {
     "listeners" : {
      "delete_event" : "(self, event) => {\n    this.el.hide();\n    return true; \n    //test  \n}\n ",
-     "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id == 0) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n    \tGitMonitor.gitmonitor.start();\n\t \treturn;\n\t}\n\t /*\n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n    }\n\t*/\n\t\n\tif (this.repo != null) {\n\t\trepo.doMerge(\n\t\t\t_this.actionsel.selectedAction(), \n\t\t\t_this.ticketsel.selectedTicketId(),\n\t\t\t_this.name.el.get_text()\n\t\t);\n\t\n\t} else {\n\t\tGitRepo.doMerges(\n\t\t\t_this.actionsel.selectedAction(), \n\t\t\t_this.ticketsel.selectedTicketId(),\n\t\t\t_this.name.el.get_text()\n\t\t);\n\t}\n\tthis.running = false; \n\n\t \n\t_this.el.hide();\t\n \tGitMonitor.gitmonitor.start();\n\n\t \n}",
-     "show" : "(self)  => {\n \n\n  //test\n}"
+     "response" : " (self, response_id) =>  { \n  \n\tGLib.debug(\"got %d\", (int) response_id);\n\tif (response_id < 1) {\n\t    _this.el.hide();\t\n\t    this.running = false; \n    \tGitMonitor.gitmonitor.start();\n\t \treturn;\n\t}\n\t /*\n\t// have they selected a ticket..\n\t// make that the current active ticket?\n\t// we really need to store locally what ticket is being worked on..\n\t// in theory we could be working on multiple project and not merging..\n\t// -- each repo would have their active ticket (only one per repo)\n\t// -- so we could just store that in there\n\t// -- initial load can check the contents of the ticket files on first scan.\n\tvar ticket_id = _this.ticketsel.selectedTicketId();\n\t\n    if (this.repo != null) {\n    \tvar bn = _this.name.el.get_text();\n    \tif (ticket_id != \"\" ) {\n\t\t\tthis.repo.setActiveTicket( RooTicket.singleton().getById(ticket_id), bn);\n\t\t} else {\n\t\t\tthis.repo.createBranchNamed(bn);\n\t\t}\n    }\n\t*/\n\t\n\tif (this.repo != null) {\n\t\trepo.doMerge(\n\t\t\t_this.actionsel.selectedAction(), \n\t\t\t_this.ticketsel.selectedTicketId(),\n\t\t\t_this.name.el.get_text()\n\t\t);\n\t\n\t} else {\n\t\tGitRepo.doMerges(\n\t\t\t_this.actionsel.selectedAction(), \n\t\t\t_this.ticketsel.selectedTicketId(),\n\t\t\t_this.name.el.get_text()\n\t\t);\n\t}\n\tthis.running = false; \n\n\t \n\t_this.el.hide();\t\n \tGitMonitor.gitmonitor.start();\n\n\t \n}"
     },
     "default_width" : 500,
 -   "# GitRepo repo" : "",
     "$ deletable" : true,
 +   "# GitRepo repo" : "",
     "title" : "Merge Branch",
     "xtype" : "Dialog",
-    "|   void show" : "(  RooTicket ticket, GitRepo? repo ) \n{\n     // this.el.set_gravity(Gdk.Gravity.NORTH);\n    if (this.running) {\n    \treturn;\n\t}\n\tGitMonitor.gitmonitor.stop();\n\t\n    this.ticket = ticket;\n    this.repo = repo;\n    \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n       \tGLib.debug(\"Loading tickets\"); \n\n\n    this.el.show_all();\n \t_this.dbmodel.loadTickets();\n \t_this.actionmodel.loadActions();\n\n\n}",
+    "|   void show" : "(  RooTicket ticket, GitRepo? repo ) \n{\n     // this.el.set_gravity(Gdk.Gravity.NORTH);\n    if (this.running) {\n    \treturn;\n\t}\n\tGitMonitor.gitmonitor.stop();\n\t\n\t_this.el.show_all();\n\t\n\t_this.table.el.hide();\n\t_this.scrolled_window.el.hide();\n\t_this.spinner.el.show();\n\t_this.spinner.el.start();\t\n\tthis.el.set_keep_above(true);    \n\tthis.el.move((Gdk.Screen.width() / 2)- 250 ,0);\n       \tGLib.debug(\"Loading tickets\"); \n\n\n\t\n\t\n    this.ticket = ticket;\n    this.repo = repo;\n    \n\t\n\tTimeout.add_seconds(1, () => {\n\t\t\n\t\t// if we are not working on a ticket, then we should be able to pick one?\n\t \t_this.dbmodel.loadTickets();\n\t \t_this.actionmodel.loadActions();\n\t\t_this.view.loadTicket(ticket.id);\n\t\t_this.spinner.el.stop();\n\t\t_this.spinner.el.hide();\t\n\n\t\tthis.table.el.show();\n\t\treturn false;\n\t});\n\t\n\tthis.el.run();\n\t \n}",
     "default_height" : 200,
     "# RooTicket? ticket" : "null",
     "$ xns" : "Gtk",
     "bool modal" : true,
     "items" : [
      {
-      "xtype" : "VBox",
+      "xtype" : "Box",
       "$ pack" : "get_content_area().add",
       "$ xns" : "Gtk",
+      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
       "items" : [
        {
+        "id" : "table",
         "bool homogeneous" : false,
 -       "* pack" : "pack_start,false,false,0",
         "xtype" : "Table",
 +       "* pack" : "pack_start,false,false,0",
         "uint column_spacing" : 2,
         "n_columns" : 2,
         "$ xns" : "Gtk",
         "n_rows" : 2,
+        "bool vexpand" : false,
         "int margin" : 2,
         "items" : [
          {
           "items" : [
            {
             "id" : "actioncellrenderer",
 -           "* pack" : "pack_start,true",
             "xtype" : "CellRendererText",
 +           "* pack" : "pack_start,true",
             "$ xns" : "Gtk"
            },
            {
             "id" : "actionmodel",
 -           "* pack" : "set_model",
             "xtype" : "ListStore",
 +           "* pack" : "set_model",
             "$ columns" : "typeof(string),typeof(string)",
             "n_columns" : 2,
             "$ xns" : "Gtk",
          },
          {
           "listeners" : {
-           "changed" : "() => {\n\tif (this.loading) {\n\t\treturn;\n\t}\n\t\n\t \n  \t_this.name.updateText();\n\t//_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\t\n\t//GLib.debug (//\"Selection: %s, %s\\n\", (string) val1, (string) val2);\n}"
+           "changed" : "() => {\n\tif (this.loading) {\n\t\treturn;\n\t}\n\t_this.view.loadTicket(this.selectedTicketId());\n\t \n  \t_this.name.updateText();\n\t//_this.name.el.set_text(\"wip_%s_T%s_%s\".printf(name,ticket.id, ticket.summaryToBranchName()));\n\t\n\t//GLib.debug (//\"Selection: %s, %s\\n\", (string) val1, (string) val2);\n}"
           },
           "id" : "ticketsel",
           "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
           "* pack" : "attach_defaults,1,2,1,2",
           "xtype" : "ComboBox",
-          "# bool loading" : false,
+          "# bool loading" : true,
           "$ xns" : "Gtk",
           "| string selectedTicketId" : "() {\nGtk.TreeIter iter;\n\tValue val1;\n \n \n\tthis.el.get_active_iter (out iter);\n\t_this.dbmodel.el.get_value (iter, 0, out val1);\n \n\n\treturn  (string) val1;\n\t\n\t\n\t\n\t\n}\n",
           "items" : [
            {
             "id" : "dbcellrenderer",
 -           "xtype" : "CellRendererText",
             "* pack" : "pack_start,true",
 +           "xtype" : "CellRendererText",
             "$ xns" : "Gtk"
            },
            {
             "id" : "dbmodel",
 -           "xtype" : "ListStore",
             "* pack" : "set_model",
-            "xtype" : "ListStore",
             "| void loadTickets" : "  () {\n\n    RooTicket.singleton().loadTickets(\"\",RooTicket.Who.ME, RooTicket.Status.ACTIVE);\n    \n    _this.ticketsel.loading = true;\n\n    this.el.clear();                                    \n    Gtk.TreeIter iter;\n    var el = this.el;\n    \n    el.append(out iter);\n    el.set_value(iter, 0, \"\");\n    el.set_value(iter, 1, \"-- select a ticket --\");\n    \n    _this.ticketsel.el.set_active_iter(iter);\n    \n    if (_this.ticket != null &&  _this.ticket.id == \"-1\") {\n\t\tel.append(out iter);\n\t\tel.set_value(iter, 0, \"-1\");\n\t\tel.set_value(iter, 1, \"Temporary Branch - No ticket specified/relivant\");\n        _this.ticketsel.el.set_active_iter(iter);\t\n    }\n    \n    \n    \n    \n    var tickets = RooTicket.singleton().tickets;\n    foreach(var ticket in tickets) {\n    \n        el.append(out iter);\n\n        el.set_value(iter, 0, ticket.id);\n        el.set_value(iter, 1, \"#%s [%s] %s\".printf( ticket.id, ticket.project_id_name , ticket.summary));\n\t\tif (_this.ticket != null && _this.ticket.id == ticket.id) {\n\t\t    _this.ticketsel.el.set_active_iter(iter);\n\t    }\n        \n    }\n    \n    _this.ticketsel.loading = false;\n     //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          \n                                     \n}\n",
             "$ columns" : "typeof(string),typeof(string)",
             "n_columns" : 2,
           "$ xns" : "Gtk"
          }
         ]
+       },
+       {
+        "int height_request" : 500,
+        "id" : "scrolled_window",
+        "* init" : "{\n\tthis.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n}\n",
+        "* pack" : "add",
+        "xtype" : "ScrolledWindow",
+        "$ xns" : "Gtk",
+        "bool vexpand" : true,
+        "items" : [
+         {
+          "id" : "view",
+          "xtype" : "WebView",
+          "* pack" : "add",
+          "$ xns" : "WebKit",
+          "| void loadTicket" : "(string tid) {\n\tint h,w;\n\t_this.el.get_size(out w, out h);\n\t\n\tif (tid == \"\") {\n\t\t_this.scrolled_window.el.hide();\n\t\t_this.el.resize(w, 150);\n\t} else {\n\t\t_this.scrolled_window.el.show();\n\t\t_this.el.resize(w, 800);\n\t}\n\t\n\tvar rs =  RooTicket.singleton();\t\t\n\tvar uri = new WebKit.URIRequest(\"https://roojs.com/admin.php/MTrack/View/\" + tid);\n\tvar hd = uri.get_http_headers();\n\tvar authCode = Base64.encode (\"%s:%s\".printf(rs.username, rs.password).data);\n\thd.append(\"Authorization\", \"Basic %s\".printf(authCode));\n\t\n\t this.el.load_request(uri);\n}\n"
+         }
+        ]
+       },
+       {
+        "id" : "spinner",
+        "bool hexpand" : true,
+        "* pack" : "add",
+        "xtype" : "Spinner",
+        "$ xns" : "Gtk",
+        "bool vexpand" : true
        }
       ]
      },
      {
       "label" : "Cancel",
 -     "xtype" : "Button",
       "* pack" : "add_action_widget,0",
 +     "xtype" : "Button",
       "Gtk.ReliefStyle relief" : "Gtk.ReliefStyle.NONE",
       "$ xns" : "Gtk"
      },
      {
       "label" : "Do Merge",
+      "* init" : "{\n   this.el.get_style_context().add_class(\"suggested-action\");\n}\n",
+      "xtype" : "Button",
       "* pack" : "add_action_widget,1",
 +     "xtype" : "Button",
       "$ xns" : "Gtk"
      }
     ]