From: Alan Knowles Date: Mon, 5 Nov 2018 06:27:34 +0000 (+0800) Subject: sync X-Git-Url: http://git.roojs.org/?p=gitlive;a=commitdiff_plain;h=03a18dbe03808a85cde3936fb5b477aa17b2cb9a sync --- diff --git a/GitMonitor.vala b/GitMonitor.vala index 92733e37..2ba96852 100644 --- a/GitMonitor.vala +++ b/GitMonitor.vala @@ -13,7 +13,7 @@ public class GitMonitor : Monitor public static string gitlive; - public Array queue ; + private Gee.ArrayList queue ; public bool queueRunning = false; public DateTime lastAdd; @@ -23,14 +23,14 @@ public class GitMonitor : Monitor public GitMonitor () { - this.queue = new Array(); + this.queue = new Gee.ArrayList(); GitMonitor.gitmonitor = this; 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) { + if (this.queue.size < 1 || this.queueRunning) { return true; } @@ -82,7 +82,7 @@ public class GitMonitor : Monitor this.paused = true; this.queueRunning = false; // what does this do to the old one... - this.queue = new Array (); + //this.queue = new Gee.ArrayList (); this.stop(); StatusIconA.statusicon.pauseError(); @@ -103,7 +103,7 @@ public class GitMonitor : Monitor public new void pause() { this.paused = true; // what does this do to the old one... - this.queue = new Array (); + //this.queue = new Gee.ArrayList (); StatusIconA.statusicon.pause(); } @@ -170,9 +170,10 @@ public class GitMonitor : Monitor } - public new void monitor (string path, int depth = 0) + 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; @@ -182,6 +183,13 @@ public class GitMonitor : Monitor } if (depth == 1) { + + if (!FileUtils.test(path + "/.git" , FileTest.IS_DIR)) { + return; // skip non-git directories.. + } + + GitRepo.get(path); + // FIXME - check if repo is flagged as not autocommit.. //var repo = imports.Scm.Repo.Repo.get(path); //if (!repo || !repo.autocommit()) { @@ -210,22 +218,21 @@ public class GitMonitor : Monitor public void runQueue() { - if (this.paused) { + if (this.paused || this.queue.size < 1 ) { return; } GLib.debug("GitMonitor.runQueue\n"); this.queueRunning = true; - var cmds = new Array(); + var cmds = new Gee.ArrayList(); - for(var i = 0; i < this.queue.length; i++) { - cmds.append_val(this.queue.index(i)); + for(var i = 0; i < this.queue.size; i++) { + cmds.add(this.queue.get(i)); } - this.queue = new Array();// empty queue! - - + this.queue = new Gee.ArrayList();// empty queue! + string[] success = {}; string[] failure = {}; //var repos = new Array(); //?? @@ -244,9 +251,9 @@ public class GitMonitor : Monitor var leave_queued = new Gee.ArrayList(); GLib.debug("GitMonitor.runQueue - creating repos"); - for(var i = 0; i < cmds.length; i++) { + for(var i = 0; i < cmds.size; i++) { - var cmd = cmds.index(i); + var cmd = cmds.get(i); var gitpath = cmd.gitpath; @@ -270,9 +277,11 @@ public class GitMonitor : Monitor // repo_list[gitpath].cmds = []; // repo_list[gitpath].pull(); //} - repo_list.index(ix).cmds.append_val(cmd); + repo_list.index(ix).cmds.add(cmd); } + this.queue = leave_queued; + this.paused = false; // build add, remove and commit message list.. @@ -282,14 +291,14 @@ public class GitMonitor : Monitor var repo = repo_list.index(i); - var add_files = new Array(); - var add_files_f = new Array(); - var remove_files = new Array(); - var messages = new Array(); + var add_files = new Gee.ArrayList(); + var add_files_f = new Gee.ArrayList(); + var remove_files = new Gee.ArrayList(); + var messages = new Gee.ArrayList(); //print(JSON.stringify(repo.cmds,null,4)); - for(var ii = 0;ii < repo.cmds.length;ii++) { - var cmd = repo.cmds.index(ii); + for(var ii = 0;ii < repo.cmds.size;ii++) { + var cmd = repo.cmds.get(ii); if (repo.is_ignore(cmd.vname)) { continue; @@ -303,7 +312,7 @@ public class GitMonitor : Monitor break; } - add_files.append_val(cmd); + add_files.add(cmd); break; case "rm": @@ -316,14 +325,14 @@ public class GitMonitor : Monitor break; } - remove_files.append_val(cmd); + remove_files.add(cmd); break; case "commit" : if (GitMonitorQueue.indexOfMessage(messages, cmd.message) > -1 ) { break; } - messages.append_val(cmd); + messages.add(cmd); break; default: @@ -353,37 +362,35 @@ public class GitMonitor : Monitor */ // if file was added, then removed, - var remove_files_f = new Array(); - for(var ii = 0;ii < remove_files.length;ii++) { + var remove_files_f = new Gee.ArrayList(); + for(var ii = 0;ii < remove_files.size;ii++) { - if (GitMonitorQueue.indexOfAdd(add_files, remove_files.index(ii).vname) > -1 ) { + if (GitMonitorQueue.indexOfAdd(add_files, remove_files.get(ii).vname) > -1 ) { // in add and remove - do not remvove continue; } - remove_files_f.append_val(remove_files.index(ii)); + remove_files_f.add(remove_files.get(ii)); }; - for(var ii = 0;ii < add_files.length;ii++) { - if (GitMonitorQueue.indexOfAdd(remove_files, add_files.index(ii).vname) > -1 ) { + for(var ii = 0;ii < add_files.size;ii++) { + if (GitMonitorQueue.indexOfAdd(remove_files, add_files.get(ii).vname) > -1 ) { // the add file is in the remove list, and it does not exist - do not add it.. - print("check exists ? %s\n",add_files.index(ii).fullpath()); + print("check exists ? %s\n",add_files.get(ii).fullpath()); - if (!FileUtils.test(add_files.index(ii).fullpath(), FileTest.EXISTS)) { + if (!FileUtils.test(add_files.get(ii).fullpath(), FileTest.EXISTS)) { continue; } - } - - + } - add_files_f.append_val(add_files.index(ii)); + add_files_f.add(add_files.get(ii)); }; 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) { + if (add_files_f.size < 1 && remove_files_f.size < 1) { continue; } @@ -419,8 +426,7 @@ public class GitMonitor : Monitor failure += e.message; GLib.debug("Remove failed:"); } - - + try { success += repo.commit( GitMonitorQueue.messageToString(messages), @@ -428,6 +434,7 @@ public class GitMonitor : Monitor ); success += repo.push(); + } catch(Error e) { // if the error is 'nothing to commit, working tree clean' @@ -541,12 +548,17 @@ public class GitMonitor : Monitor } */ cmd.action = "add"; - this.queue.append_val(cmd); + this.queue.add(cmd); cmd = new GitMonitorQueue(src); cmd.action = "commit"; cmd.message = cmd.vname; - this.queue.append_val(cmd); + this.queue.add(cmd); + + + if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) { + NewBranch.singleton().show(cmd.repo); + } } @@ -565,14 +577,19 @@ public class GitMonitor : Monitor // should check if monitor needs removing.. // it should also check if it was a directory.. - so we dont have to commit all.. cmd.action = "rm"; - this.queue.append_val(cmd); + this.queue.add(cmd); cmd = new GitMonitorQueue(src); cmd.action = "commit"; cmd.message = cmd.vname; cmd.commit_all = true; - this.queue.append_val(cmd); + this.queue.add(cmd); + + if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) { + NewBranch.singleton().show(cmd.repo); + } + } public override void onCreated(MonitorNamePathDir src) { @@ -606,7 +623,8 @@ public class GitMonitor : Monitor } - public override void onAttributeChanged(MonitorNamePathDir src) { + public override void onAttributeChanged(MonitorNamePathDir src) + { if (this.paused) { return; @@ -622,12 +640,16 @@ public class GitMonitor : Monitor return; } cmd.action = "add"; - this.queue.append_val(cmd); + this.queue.add(cmd); cmd = new GitMonitorQueue(src); cmd.action = "commit"; cmd.message = "Attribute changed " + cmd.vname; - this.queue.append_val(cmd); + this.queue.add(cmd); + + if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) { + NewBranch.singleton().show(cmd.repo); + } } public override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) @@ -668,13 +690,13 @@ public class GitMonitor : Monitor GLib.debug("RM: %s", cmd_s.vname); cmd_s.action = "rm"; - this.queue.append_val(cmd_s); + this.queue.add(cmd_s); GLib.debug("ADD: %s", cmd_d.vname); cmd_d.action = "add"; - this.queue.append_val(cmd_d); + this.queue.add(cmd_d); var cmd = new GitMonitorQueue(dest); @@ -684,9 +706,17 @@ public class GitMonitor : Monitor cmd.message = cmd_d.vname; } - this.queue.append_val(cmd); - + + this.queue.add(cmd); + if (!cmd.shouldIgnore() && !cmd.repo.is_wip_branch()) { + NewBranch.singleton().show(cmd.repo); + } + // this is where it get's complicated... + // as we might be moving across repo's... + + + } diff --git a/GitMonitorQueue.vala b/GitMonitorQueue.vala index 6ed40e7f..15683df5 100644 --- a/GitMonitorQueue.vala +++ b/GitMonitorQueue.vala @@ -28,7 +28,7 @@ public class GitMonitorQueue : MonitorNamePathDir { this.vname = ""; return; } - + this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0]; @@ -102,50 +102,50 @@ public class GitMonitorQueue : MonitorNamePathDir { /** -- statics --*/ - public static int indexOfAdd( Array add_files, string add) + public static int indexOfAdd( Gee.ArrayList add_files, string add) { - for(var i =0; i < add_files.length; i++) { - if (add_files.index(i).vname == add) { + for(var i =0; i < add_files.size; i++) { + if (add_files.get(i).vname == add) { return i; } } return -1; } - public static int indexOfMessage(Array messages, string message) { - for(var i =0; i < messages.length; i++) { - if (messages.index(i).message == message) { + public static int indexOfMessage(Gee.ArrayList messages, string message) { + for(var i =0; i < messages.size; i++) { + if (messages.get(i).message == message) { return i; } } return -1; } - public static string messageToString(Array messages ) { + public static string messageToString(Gee.ArrayList messages ) { string[] ret = {}; - for(var i =0; i < messages.length; i++) { - ret+= messages.index(i).message; + for(var i =0; i < messages.size; i++) { + ret+= messages.get(i).message; } return string.joinv("\n",ret); } - public static string queueArrayToString(Array list) { + public static string queueArrayToString(Gee.ArrayList list) { var ret = ""; - for(var i =0; i < list.length; i++) { + for(var i =0; i < list.size; i++) { - ret += (ret.length > 0 ? ", " : "") + list.index(i).vname; + ret += (ret.length > 0 ? ", " : "") + list.get(i).vname; } return ret; } - public static bool queueHas(Array 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) { + public static bool queueHas(Gee.ArrayList list , GitMonitorQueue cmd_s, string action) { + for(var i =0; i < list.size; i++) { + var test = list.get(i); + if (list.get(i).gitpath != cmd_s.gitpath) { continue; } - if (list.index(i).vname != cmd_s.vname) { + if (list.get(i).vname != cmd_s.vname) { continue; } - if (list.index(i).action != action) { + if (list.get(i).action != action) { continue; } return true; diff --git a/GitRepo.vala b/GitRepo.vala index 2df125a2..6374b4ff 100644 --- a/GitRepo.vala +++ b/GitRepo.vala @@ -12,7 +12,7 @@ static GitRepo _GitRepo; public class GitRepo : Object { - public Array cmds; + public Gee.ArrayList cmds; public string name; public string gitdir; @@ -171,7 +171,7 @@ public class GitRepo : Object public bool is_wip_branch() { - return this.currentBranch.name.has_prefix("wip_") + return this.currentBranch.name.has_prefix("wip_"); } @@ -225,9 +225,118 @@ public class GitRepo : Object return ret; } - RooTicket? ticket = null; + public static void doMerges(string action, string ticket_id, string commit_message) + { + GitMonitor.gitmonitor.stop(); + + var commitrevs = ""; + var sucess = true; + foreach(var repo in GitRepo.singleton().cache.values) { + if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) { + var res = repo.doMerge(action,ticket_id, commit_message); + if (!res) { + sucess = false; + continue; + } + commitrevs += commitrevs.length > 0 ? " " : ""; + commitrevs += repo.currentBranch.lastrev; + } + } + if (sucess && action == "CLOSE") { + RooTicket.singleton().getById(ticket_id).close(commitrevs); + } + GitMonitor.gitmonitor.start(); + } + + + + + public bool doMerge(string action, string ticket_id, string commit_message) + { + // in theory we should check to see if other repo's have got the same branch and merge all them at the same time. + // also need to decide which branch we will merge into? + var ret = ""; + if (action == "CLOSE" || action == "LEAVE") { + + + try { + var oldbranch = this.currentBranch.name; + this.setActiveTicket(null, "master"); + string [] cmd = { "merge", "--squash", oldbranch }; + this.git( cmd ); + cmd = { "commit", "--m", commit_message }; + this.git( cmd ); + this.loadBranches(); // updates lastrev.. + + var notification = new Notify.Notification( + "Merged branch %s to master".printf(oldbranch), + "", + "dialog-information" + + ); + + notification.set_timeout(5); + notification.show(); + + // close ticket.. + return true; + + } catch (Error e) { + + GitMonitor.gitmonitor.pauseError(e.message); + return false; + } + // error~?? -- show the error dialog... + return false; + } + if (action == "MASTER") { + // merge master into ours.. + try { + string[] cmd = { "merge", "master" }; + this.git( cmd ); + var notification = new Notify.Notification( + "Merged code from master to %s".printf(this.currentBranch.name), + "", + "dialog-information" + + ); + notification.set_timeout(5); + notification.show(); + + return true; + } catch (Error e) { + GitMonitor.gitmonitor.pauseError(e.message); + return false; + } + } + if (action == "EXIT") { + try { + var oldbranch = this.currentBranch.name; + this.setActiveTicket(null, "master"); + this.loadBranches(); + var notification = new Notify.Notification( + "Left branch %s".printf(oldbranch), + "", + "dialog-information" + + ); + notification.set_timeout(5); + notification.show(); + + return true; + } catch (Error e) { + GitMonitor.gitmonitor.pauseError(e.message); + + return false; + } + // error~?? -- show the error dialog... + + } + return false; + } - public void setActiveTicket(RooTicket ticket, string branchname) + + public void setActiveTicket(RooTicket ticket, string branchname) { this.createBranchNamed(branchname); FileUtils.set_contents(this.gitdir + "/.gitlive-active-ticket" , ticket.id); @@ -236,8 +345,13 @@ public class GitRepo : Object public void createBranchNamed(string branchname) { - string[] cmd = { "checkout", "-b" , branchname }; - this.git(cmd); + if (this.branches.has_key(branchname)) { + string[] cmd = { "checkout", branchname }; + this.git(cmd); + } else { + string[] cmd = { "checkout", "-b" , branchname }; + this.git(cmd); + } this.loadBranches(); // update branch list... GitMonitor.gitmonitor.runQueue(); // commit any outstanding... } @@ -249,14 +363,14 @@ public class GitRepo : Object * * @argument {Array} files the files to add. */ - public string add ( Array files ) throws Error, SpawnError + public string add ( Gee.ArrayList files ) throws Error, SpawnError { // should really find out if these are untracked files each.. // we run multiple versions to make sure that if one failes, it does not ignore the whole lot.. // not sure if that is how git works.. but just be certian. var ret = ""; - for (var i = 0; i < files.length;i++) { - var f = files.index(i).vname; + for (var i = 0; i < files.size;i++) { + var f = files.get(i).vname; try { string[] cmd = { "add", f }; this.git( cmd ); @@ -333,7 +447,7 @@ public class GitRepo : Object * */ - public string commit ( string message, Array files ) throws Error, SpawnError + public string commit ( string message, Gee.ArrayList files ) throws Error, SpawnError { @@ -357,8 +471,8 @@ public class GitRepo : Object */ string[] args = { "commit", "-m" }; args += (message.length > 0 ? message : "Changed" ); - for (var i = 0; i< files.length ; i++ ) { - args += files.index(i).vname; // full path? + for (var i = 0; i< files.size ; i++ ) { + args += files.get(i).vname; // full path? } return this.git(args); diff --git a/NewBranch.bjs b/NewBranch.bjs index 1656fe70..6d1ba951 100644 --- a/NewBranch.bjs +++ b/NewBranch.bjs @@ -10,7 +10,7 @@ { "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\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\n\t\t this.running = false; \n\n\t \n\t \n\t \n\n\t \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\t\tGitMonitor.gitmonitor.start();\t \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\tGitMonitor.gitmonitor.start();\n\t\t this.running = false; \n\n\t \n\t \n\t \n\n\t \n}", "show" : "(self) => {\n \n\n //test\n}" }, "default_width" : 500, @@ -18,7 +18,7 @@ "title" : "Create a working branch ", "xtype" : "Dialog", "# GitRepo? repo" : "null", - "| void show" : "( GitRepo repo ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) {\n \treturn;\n\t}\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\n}", + "| void show" : "( GitRepo repo ) \n{\n // this.el.set_gravity(Gdk.Gravity.NORTH);\n if (this.running) {\n \treturn;\n\t}\n\t\tGitMonitor.gitmonitor.stop();\n\t\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\n}", "default_height" : 200, "$ xns" : "Gtk", "# bool running" : false, @@ -31,8 +31,8 @@ "items" : [ { "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", @@ -63,14 +63,14 @@ "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();\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\n \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 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 \n //if (data.get(i) == cur) {\n // _this.build_module.el.set_active_iter(iter);\n // }\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, @@ -100,15 +100,15 @@ }, { "label" : "Do not create Branch", - "xtype" : "Button", "* pack" : "add_action_widget,0", + "xtype" : "Button", "Gtk.ReliefStyle relief" : "Gtk.ReliefStyle.NONE", "$ xns" : "Gtk" }, { "label" : "Create Branch", - "xtype" : "Button", "* pack" : "add_action_widget,1", + "xtype" : "Button", "$ xns" : "Gtk" } ] diff --git a/NewBranch.vala b/NewBranch.vala index 583cb0eb..6a48613f 100644 --- a/NewBranch.vala +++ b/NewBranch.vala @@ -59,6 +59,7 @@ public class NewBranch : Object if (response_id == 0) { _this.el.hide(); this.running = false; + GitMonitor.gitmonitor.start(); return; } @@ -79,7 +80,7 @@ public class NewBranch : Object this.repo.createBranchNamed(bn); } } - + GitMonitor.gitmonitor.start(); this.running = false; @@ -102,6 +103,8 @@ public class NewBranch : Object if (this.running) { return; } + GitMonitor.gitmonitor.stop(); + this.repo = repo; this.el.move((Gdk.Screen.width() / 2)- 250 ,0);