3 public GitMontitorQueue : MonitorNamePathDir {
6 public string message ; // for commit
8 public GitMontitorQueue(MonitorNamePathDir f, string gitlive) {
13 this.commit_all = false;
16 var vpath_ar = this.path.substring(gitlive.length +1).split('/', 0);
18 this.gitpath = gitlive + '/' + vpath_ar[0];
21 for (var i = 1; i< vpath_ar.length; i++) {
24 this.vpath = string.joinv("/", vpath);
25 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
30 public bool shouldIgnore(GitMonitor gm)
35 // vim.. what a seriously brain dead program..
36 if (this.name == '4913') {
40 if (this.name[0] == '.') {
42 if (this.name == '.htaccess') {
48 //if (f.name.match(/~$/)) {
51 //if (f.name.match(/^nbproject/)) {
54 // ignore anything in top level!!!!
55 if (!this.vpath.length) {
64 public static int indexOfAdd( Array<GtkMonitorQueuequeue> add_files, string add) {
65 for(var i =0; i < add_files.length; i++) {
66 if (addfiles.index(i).add == add) {
72 public static int indexOfMessage(Array<GtkMonitorQueuequeue> messages, message) {
73 for(var i =0; i < messages.length; i++) {
74 if (messages.index(i).message == message) {
80 public static string messageToString(Array<GtkMonitorQueuequeue> messages ) {
82 for(var i =0; i < messages.length; i++) {
83 ret+= messages.index(i).message;
85 return string.joinv(ret,"\n");
92 public class GitMonitor : Monitor
97 * @property {String} the "gitlive" directory, normally ~/gitlive
98 * dset by OWNER... - we should do this as a CTOR.
101 public string gitlive = '';
104 public Array<GtkMonitorQueuequeue>;
105 public bool queueRunning = false;
107 public DateTime lastAdd;
110 public void pause() {
112 // what does this do to the old one...
113 this.queue = new Array<FileMonitor> ();
114 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
118 public void resume () {
120 this.queue = new Array<FileMonitor> ();
121 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
126 * Start the monitoring
127 * and run the queue every 500 milliseconds..
130 public void start() {
131 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
134 this.lastAdd = new DateTime.now();
136 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
138 // call this.monitor on each of 'top'
139 for(int i = 0; i < this.top.length ; i++) {
140 this.monitor(this.top.index(i) );
142 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
147 var notification = new Notify.Notification({
149 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
153 notification.set_timeout(5);
161 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
162 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
163 if (!_this.queue.length || _this.queueRunning) {
167 var last = this.lastAdd.difference(new DateTime.now());
170 //print("LAST RUN?" + last);
172 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
175 //_this.lastAdd = new Date();
187 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
192 public void monitor (string path, int depth = 0)
195 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
198 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
199 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
204 // FIXME - check if repo is flagged as not autocommit..
205 //var repo = imports.Scm.Repo.Repo.get(path);
206 //if (!repo || !repo.autocommit()) {
212 // check if the repo is to be monitored.
213 //print("PATH : " + path);
216 base.monitor(path, depth);
223 * - pulls the items off the queue
224 * (as commands run concurrently and new items may get added while it's running)
225 * - runs the queue items
229 public void runQueue()
235 this.queueRunning = true;
237 var cmds = new Array<GitMontitorQueue>();
238 for(var i = 0; i < this.queue.length; i++) {
239 cmds.append_val(this.queue.item(i));
242 this.queue = new Array<GitMontitorQueue>();// empty queue!
245 var success = new Array<String>();
246 var failure = new Array<GitMontitorQueue>();
247 var repos = new Array<GitRepo>(); //??
248 var done = new Array<GitMontitorQueue>();
250 // first build a array of repo's to work with
251 var repo_list = new Array<GitRepo>();
255 //print(JSON.stringify(cmds));
258 for(var i = 0; i < cmds.length; i++) {
261 var gitpath = cmd.gitpath;
262 var ix = GitRepo.indexOf(this.repos, cmd.gitpath);
264 repo_list.append_val(new GitRepo( gitpath ));
265 ix = GitRepo.indexOf(this.repos, cmd.gitpath);
269 //if (typeof(repo_list[gitpath]) == 'undefined') {
270 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
271 // repo_list[gitpath].cmds = [];
272 // repo_list[gitpath].pull();
274 repo_list.item(ix).cmds.append_val(cmd);
278 // build add, remove and commit message list..
280 for(var i = 0;i < repo_list.length;i++) {
283 var repo = repo_list.item(i);
285 var add_files = new Array<GitMontitorQueue>();
286 var remove_files = new Array<GitMontitorQueue>();
287 var messages = new Array<GitMontitorQueue>();
288 //print(JSON.stringify(repo.cmds,null,4));
290 for(var ii = 0;ii < repo.cmds.length;ii++) {
291 var cmd = repo.cmds.item(ii);
297 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
302 add_files.append_val(cmd);
306 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
310 // if file exists, do not try and delete it.
311 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
315 remove_files.append_val(cmd);
319 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
323 messages.append_val(cmd);
330 // these can fail... at present... as we wildcard stuff.
331 stdout.printf("ADD : %d files" , add_files.length);
333 // make sure added files do not get removed..
335 var remove_files_f = new Array<GitMontitorQueue>();
336 for(var ii = 0;ii < remove_files.length;ii++) {
337 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
340 remove_files_f.append_val(remove_files.item(ii));
342 stdout.printf("REMOVE : %d files" , remove_files.length);
344 // make sure monitoring is paused so it does not recursively pick up
350 repo.remove(remove_files);
355 success.append_val(repo.commit(
356 GitMontitorQueue.messageToString(messages)
359 success.push(repo.push());
362 failure.append_val(e.message);
367 // finally merge all the commit messages.
370 // catch notification failures.. so we can carry on..
371 if (success.length) {
372 var success_str = "";
373 for(var ii = 0;ii < success.length;ii++) {
374 success_str+= success.item(ii) + "\n";
377 var notification = new Notify.Notification(
384 notification.set_timeout(5);
388 if (failure.length) {
389 var failure_str = "";
390 for(var ii = 0;ii < failure.length;ii++) {
391 failure_str+= failure.item(ii) + "\n";
393 var notification = new Notify.Notification({
394 summary: "Git Live ERROR!!",
400 notification.set_timeout(5); // show errros for longer
407 this.queueRunning = false;
414 //string[] just_created;
423 public void onChanged(MonitorNamePathDir src) { }
425 return; // always ignore this..?
426 //this.parsePath(src);
432 * results in git add + git commit..
435 public void onChangesDoneHint(MonitorNamePathDir src) { }
443 this.lastAdd = new DateTime.now();
444 var cmd = new GitMontitorQueue(src, this.gitlive);
445 if (cmd.shouldIgnore()) {
452 if (this.is_just_created(cmd.path)) {
454 if (typeof(this.just_created[src.path]) !='undefined') {
455 delete this.just_created[src.path];
458 [ src.gitpath, 'add', src.vpath ],
459 [ src.gitpath, 'commit', { message: src.vpath} ]
467 this.queue.append_val(cmd);
469 var cmd = new GitMontitorQueue(src, this.gitlive);
470 cmd.action = "commit";
471 cmd.message = src.vpath;
472 this.queue.append_val(cmd);
476 public void onDeleted(MonitorNamePathDir src)
481 this.lastAdd = new DateTime.now();
482 var cmd = new GitMontitorQueue(src, this.gitlive);
483 if (cmd.shouldIgnore()) {
486 // should check if monitor needs removing..
487 // it should also check if it was a directory.. - so we dont have to commit all..
490 this.queue.append_val(cmd);
492 var cmd = new GitMontitorQueue(src, this.gitlive);
493 cmd.action = "commit";
494 cmd.message = src.vpath;
495 cmd.commit_all = true;
497 this.queue.append_val(cmd);
500 public void onCreated(MonitorNamePathDir src) {
505 this.lastAdd = new DateTime.now();
506 var cmd = new GitMontitorQueue(src, this.gitlive);
507 if (cmd.shouldIgnore()) {
511 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
512 // this.just_created[src.path] = true;
513 return; // we do not handle file create flags... - use done hint.
515 // directory has bee created
516 this.monitor(src.path);
517 this.top.append_val(src.path);
518 this.monitor(src.path );
521 // -- no point in adding a dir.. as git does not handle them...
523 // [ src.gitpath, 'add' , src.vpath, { all: true } ],
524 // [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
530 public void onAttributeChanged(MonitorNamePathDir src) { }
535 this.lastAdd = new DateTime.now();
536 var cmd = new GitMontitorQueue(src, this.gitlive);
537 if (cmd.shouldIgnore()) {
542 this.queue.append_val(cmd);
544 var cmd = new GitMontitorQueue(src, this.gitlive);
545 cmd.action = "commit";
546 cmd.message = "Attribute changed " + cmd.vpath;
547 this.queue.append_val(cmd);
551 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
553 this.lastAdd = new DateTime.now();
554 var cmd_s = new GitMontitorQueue(src, this.gitlive);
556 var cmd_d = new GitMontitorQueue(src, this.gitlive);
559 if (cmd_d.gitpath != cmd_s.gitpath) {
561 this.onCreated(dest);
562 this.onChangedDoneHint(dest);
565 // needs to handle move to/from unsupported types..
567 if (this.shouldIgnore(src)) {
568 this.onCreated(dest);
569 this.onChangedDoneHint(dest);
573 if (this.shouldIgnore(dest)) {
582 cmd_s.rm = src.vpath;
583 this.queue.append_val(cmd_s);
588 cmd_d.action = "add";
589 cmd_d.add = src.vpath;
590 this.queue.append_val(cmd_d);
593 var cmd = new GitMontitorQueue(dest, this.gitlive);
594 cmd.action = "commit";
595 cmd.message = "MOVED " + cmd_s.vpath + " to " + cmd_d.vpath;
596 this.queue.append_val(cmd);