3 public GitMontitorQueue : MonitorNamePathDir {
10 public string message ; // for commit
11 public bool commit_all
12 public GitMontitorQueue(MonitorNamePathDir f, string gitlive) {
17 this.commit_all = false;
20 var vpath_ar = this.path.substring(gitlive.length +1).split('/', 0);
22 this.gitpath = gitlive + '/' + vpath_ar[0];
25 for (var i = 1; i< vpath_ar.length; i++) {
28 this.vpath = string.joinv("/", vpath);
29 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
34 public bool shouldIgnore(GitMonitor gm)
39 // vim.. what a seriously brain dead program..
40 if (this.name == '4913') {
44 if (this.name[0] == '.') {
46 if (this.name == '.htaccess') {
52 //if (f.name.match(/~$/)) {
55 //if (f.name.match(/^nbproject/)) {
58 // ignore anything in top level!!!!
59 if (!this.vpath.length) {
68 public static int indexOfAdd( Array<GtkMonitorQueuequeue> add_files, string add) {
69 for(var i =0; i < add_files.length; i++) {
70 if (addfiles.index(i).add == add) {
76 public static int indexOfMessage(Array<GtkMonitorQueuequeue> messages, message) {
77 for(var i =0; i < messages.length; i++) {
78 if (messages.index(i).message == message) {
84 public static string messageToString(Array<GtkMonitorQueuequeue> messages ) {
86 for(var i =0; i < messages.length; i++) {
87 ret+= messages.index(i).message;
89 return string.joinv(ret,"\n");
96 public class GitMonitor : Monitor
101 * @property {String} the "gitlive" directory, normally ~/gitlive
102 * dset by OWNER... - we should do this as a CTOR.
105 public string gitlive = '';
108 public Array<GtkMonitorQueuequeue>;
109 public bool queueRunning = false;
111 public DateTime lastAdd;
114 public void pause() {
116 // what does this do to the old one...
117 this.queue = new Array<FileMonitor> ();
118 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
122 public void resume () {
124 this.queue = new Array<FileMonitor> ();
125 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
130 * Start the monitoring
131 * and run the queue every 500 milliseconds..
134 public void start() {
135 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
138 this.lastAdd = new DateTime.now();
140 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
142 // call this.monitor on each of 'top'
143 for(int i = 0; i < this.top.length ; i++) {
144 this.monitor(this.top.index(i) );
146 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
151 var notification = new Notify.Notification({
153 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
157 notification.set_timeout(5);
165 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
166 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
167 if (!_this.queue.length || _this.queueRunning) {
171 var last = this.lastAdd.difference(new DateTime.now());
174 //print("LAST RUN?" + last);
176 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
179 //_this.lastAdd = new Date();
191 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
196 public void monitor (string path, int depth = 0)
199 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
202 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
203 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
208 // FIXME - check if repo is flagged as not autocommit..
209 //var repo = imports.Scm.Repo.Repo.get(path);
210 //if (!repo || !repo.autocommit()) {
216 // check if the repo is to be monitored.
217 //print("PATH : " + path);
220 base.monitor(path, depth);
227 * - pulls the items off the queue
228 * (as commands run concurrently and new items may get added while it's running)
229 * - runs the queue items
233 public void runQueue()
239 this.queueRunning = true;
241 var cmds = new Array<GitMontitorQueue>();
242 for(var i = 0; i < this.queue.length; i++) {
243 cmds.append_val(this.queue.item(i));
246 this.queue = new Array<GitMontitorQueue>();// empty queue!
249 var success = new Array<String>();
250 var failure = new Array<GitMontitorQueue>();
251 var repos = new Array<GitRepo>(); //??
252 var done = new Array<GitMontitorQueue>();
254 // first build a array of repo's to work with
255 var repo_list = new Array<GitRepo>();
259 //print(JSON.stringify(cmds));
262 for(var i = 0; i < cmds.length; i++) {
265 var gitpath = cmd.gitpath;
266 var ix = GitRepo.indexOf(this.repos, cmd.gitpath);
268 repo_list.append_val(new GitRepo( gitpath ));
269 ix = GitRepo.indexOf(this.repos, cmd.gitpath);
273 //if (typeof(repo_list[gitpath]) == 'undefined') {
274 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
275 // repo_list[gitpath].cmds = [];
276 // repo_list[gitpath].pull();
278 repo_list.item(ix).cmds.append_val(cmd);
282 // build add, remove and commit message list..
284 for(var i = 0;i < repo_list.length;i++) {
287 var repo = repo_list.item(i);
289 var add_files = new Array<GitMontitorQueue>();
290 var remove_files = new Array<GitMontitorQueue>();
291 var messages = new Array<GitMontitorQueue>();
292 //print(JSON.stringify(repo.cmds,null,4));
294 for(var ii = 0;ii < repo.cmds.length;ii++) {
295 var cmd = repo.cmds.item(ii);
301 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
306 add_files.append_val(cmd);
310 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
314 // if file exists, do not try and delete it.
315 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
319 remove_files.append_val(cmd);
323 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
327 messages.append_val(cmd);
331 print("Opps unmatched action");
337 // these can fail... at present... as we wildcard stuff.
338 stdout.printf("ADD : %d files" , add_files.length);
340 // make sure added files do not get removed..
342 var remove_files_f = new Array<GitMontitorQueue>();
343 for(var ii = 0;ii < remove_files.length;ii++) {
344 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
347 remove_files_f.append_val(remove_files.item(ii));
349 stdout.printf("REMOVE : %d files" , remove_files.length);
351 // make sure monitoring is paused so it does not recursively pick up
357 repo.remove(remove_files);
362 success.append_val(repo.commit(
363 GitMontitorQueue.messageToString(messages)
366 success.push(repo.push());
369 failure.append_val(e.message);
374 // finally merge all the commit messages.
377 // catch notification failures.. so we can carry on..
378 if (success.length) {
379 var success_str = "";
380 for(var ii = 0;ii < success.length;ii++) {
381 success_str+= success.item(ii) + "\n";
384 var notification = new Notify.Notification(
391 notification.set_timeout(5);
395 if (failure.length) {
396 var failure_str = "";
397 for(var ii = 0;ii < failure.length;ii++) {
398 failure_str+= failure.item(ii) + "\n";
400 var notification = new Notify.Notification({
401 summary: "Git Live ERROR!!",
407 notification.set_timeout(5); // show errros for longer
414 this.queueRunning = false;
421 //string[] just_created;
430 public void onChanged(MonitorNamePathDir src) { }
432 return; // always ignore this..?
433 //this.parsePath(src);
439 * results in git add + git commit..
442 public void onChangesDoneHint(MonitorNamePathDir src) { }
450 this.lastAdd = new DateTime.now();
451 var cmd = new GitMontitorQueue(src, this.gitlive);
452 if (cmd.shouldIgnore()) {
459 if (this.is_just_created(cmd.path)) {
461 if (typeof(this.just_created[src.path]) !='undefined') {
462 delete this.just_created[src.path];
465 [ src.gitpath, 'add', src.vpath ],
466 [ src.gitpath, 'commit', { message: src.vpath} ]
474 this.queue.append_val(cmd);
476 var cmd = new GitMontitorQueue(src, this.gitlive);
477 cmd.action = "commit";
478 cmd.message = src.vpath;
479 this.queue.append_val(cmd);
483 public void onDeleted(MonitorNamePathDir src)
488 this.lastAdd = new DateTime.now();
489 var cmd = new GitMontitorQueue(src, this.gitlive);
490 if (cmd.shouldIgnore()) {
493 // should check if monitor needs removing..
494 // it should also check if it was a directory.. - so we dont have to commit all..
497 this.queue.append_val(cmd);
499 var cmd = new GitMontitorQueue(src, this.gitlive);
500 cmd.action = "commit";
501 cmd.message = src.vpath;
502 cmd.commit_all = true;
504 this.queue.append_val(cmd);
507 public void onCreated(MonitorNamePathDir src) {
512 this.lastAdd = new DateTime.now();
513 var cmd = new GitMontitorQueue(src, this.gitlive);
514 if (cmd.shouldIgnore()) {
518 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
519 // this.just_created[src.path] = true;
520 return; // we do not handle file create flags... - use done hint.
522 // directory has bee created
523 this.monitor(src.path);
524 this.top.append_val(src.path);
525 this.monitor(src.path );
528 // -- no point in adding a dir.. as git does not handle them...
530 // [ src.gitpath, 'add' , src.vpath, { all: true } ],
531 // [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
537 public void onAttributeChanged(MonitorNamePathDir src) { }
542 this.lastAdd = new DateTime.now();
543 var cmd = new GitMontitorQueue(src, this.gitlive);
544 if (cmd.shouldIgnore()) {
549 this.queue.append_val(cmd);
551 var cmd = new GitMontitorQueue(src, this.gitlive);
552 cmd.action = "commit";
553 cmd.message = "Attribute changed " + cmd.vpath;
554 this.queue.append_val(cmd);
558 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
560 this.lastAdd = new DateTime.now();
561 var cmd_s = new GitMontitorQueue(src, this.gitlive);
563 var cmd_d = new GitMontitorQueue(src, this.gitlive);
566 if (cmd_d.gitpath != cmd_s.gitpath) {
568 this.onCreated(dest);
569 this.onChangedDoneHint(dest);
572 // needs to handle move to/from unsupported types..
574 if (this.shouldIgnore(src)) {
575 this.onCreated(dest);
576 this.onChangedDoneHint(dest);
580 if (this.shouldIgnore(dest)) {
589 cmd_s.rm = src.vpath;
590 this.queue.append_val(cmd_s);
595 cmd_d.action = "add";
596 cmd_d.add = src.vpath;
597 this.queue.append_val(cmd_d);
600 var cmd = new GitMontitorQueue(dest, this.gitlive);
601 cmd.action = "commit";
602 cmd.message = "MOVED " + cmd_s.vpath + " to " + cmd_d.vpath;
603 this.queue.append_val(cmd);