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) {
61 public int GitMontitorQueue.indexOfAdd( Array<GtkMonitorQueuequeue> add_files, string add) {
62 for(var i =0; i < add_files.length; i++) {
63 if (addfiles.index(i).add == add) {
69 public int GitMontitorQueue.indexOfMessage(Array<GtkMonitorQueuequeue> messages, message) {
70 for(var i =0; i < messages.length; i++) {
71 if (messages.index(i).message == message) {
77 public string GitMontitorQueue.messageToString(Array<GtkMonitorQueuequeue> messages ) {
79 for(var i =0; i < messages.length; i++) {
80 ret+= messages.index(i).message;
82 return string.joinv(ret,"\n");
89 public class GitMonitor : Monitor
94 * @property {String} the "gitlive" directory, normally ~/gitlive
95 * dset by OWNER... - we should do this as a CTOR.
98 public string gitlive = '';
101 public Array<GtkMonitorQueuequeue>;
102 public bool queueRunning = false;
104 public DateTime lastAdd;
107 public void pause() {
109 // what does this do to the old one...
110 this.queue = new Array<FileMonitor> ();
111 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
115 public void resume () {
117 this.queue = new Array<FileMonitor> ();
118 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
123 * Start the monitoring
124 * and run the queue every 500 milliseconds..
127 public void start() {
128 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
131 this.lastAdd = new DateTime.now();
133 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
135 // call this.monitor on each of 'top'
136 for(int i = 0; i < this.top.length ; i++) {
137 this.monitor(this.top.index(i) );
139 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
144 var notification = new Notify.Notification({
146 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
150 notification.set_timeout(5);
158 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
159 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
160 if (!_this.queue.length || _this.queueRunning) {
164 var last = this.lastAdd.difference(new DateTime.now());
167 //print("LAST RUN?" + last);
169 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
172 //_this.lastAdd = new Date();
184 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
189 public void monitor (string path, int depth = 0)
192 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
195 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
196 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
201 // FIXME - check if repo is flagged as not autocommit..
202 //var repo = imports.Scm.Repo.Repo.get(path);
203 //if (!repo || !repo.autocommit()) {
209 // check if the repo is to be monitored.
210 //print("PATH : " + path);
213 base.monitor(path, depth);
220 * - pulls the items off the queue
221 * (as commands run concurrently and new items may get added while it's running)
222 * - runs the queue items
226 public void runQueue()
232 this.queueRunning = true;
234 var cmds = new Array<GitMontitorQueue>();
235 for(var i = 0; i < this.queue.length; i++) {
236 cmds.append_val(this.queue.item(i));
239 this.queue = new Array<GitMontitorQueue>();// empty queue!
242 var success = new Array<String>();
243 var failure = new Array<GitMontitorQueue>();
244 var repos = new Array<GitMontitorQueue>(); //??
245 var done = new Array<GitMontitorQueue>();
247 // first build a array of repo's to work with
248 var repo_list = new Array<GitMontitorRepo>();
252 //print(JSON.stringify(cmds));
255 for(var i = 0; i < cmds.length; i++) {
258 var gitpath = cmd.gitpath;
259 var ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
261 repo_list.append_val(new GitMontitorRepo( gitpath ));
262 ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
266 //if (typeof(repo_list[gitpath]) == 'undefined') {
267 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
268 // repo_list[gitpath].cmds = [];
269 // repo_list[gitpath].pull();
271 repo_list.item(ix).append_val(cmd);
275 // build add, remove and commit message list..
277 for(var i = 0;i < repo_list.length;i++) {
280 var repo = repo_list.item(i);
282 var add_files = new Array<GitMontitorQueue>();
283 var remove_files = new Array<GitMontitorQueue>();
284 var messages = new Array<GitMontitorQueue>();
285 //print(JSON.stringify(repo.cmds,null,4));
287 for(var ii = 0;ii < repo.length;ii++) {
288 var cmd = repo.item(ii);
294 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
299 add_files.append_val(cmd);
303 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
307 // if file exists, do not try and delete it.
308 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
312 remove_files.append_val(cmd);
316 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
320 messages.append_val(cmd);
327 // these can fail... at present... as we wildcard stuff.
328 stdout.printf("ADD : %d files" , add_files.length);
330 // make sure added files do not get removed..
332 var remove_files_f = new Array<GitMontitorQueue>();
333 for(var ii = 0;ii < remove_files.length;ii++) {
334 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
337 remove_files_f.append_val(remove_files.item(ii));
339 stdout.printf("REMOVE : %d files" , remove_files.length);
341 // make sure monitoring is paused so it does not recursively pick up
347 repo.remove(remove_files);
352 success.append_val(repo.commit(
353 GitMontitorQueue.messageToString(messages)
356 success.push(repo.push());
359 failure.append_val(e.message);
364 // finally merge all the commit messages.
367 // catch notification failures.. so we can carry on..
368 if (success.length) {
369 var success_str = "";
370 for(var ii = 0;ii < success.length;ii++) {
371 success_str+= success.item(ii) + "\n";
374 var notification = new Notify.Notification(
381 notification.set_timeout(5);
385 if (failure.length) {
386 var failure_str = "";
387 for(var ii = 0;ii < failure.length;ii++) {
388 failure_str+= failure.item(ii) + "\n";
390 var notification = new Notify.Notification({
391 summary: "Git Live ERROR!!",
397 notification.set_timeout(5); // show errros for longer
404 this.queueRunning = false;
411 //string[] just_created;
420 public void onChanged(MonitorNamePathDir src) { }
422 return; // always ignore this..?
423 //this.parsePath(src);
429 * results in git add + git commit..
432 public void onChangesDoneHint(MonitorNamePathDir src) { }
440 this.lastAdd = new DateTime.now();
441 var cmd = new GitMontitorQueue(src, this.gitlive);
442 if (cmd.shouldIgnore()) {
449 if (this.is_just_created(cmd.path)) {
451 if (typeof(this.just_created[src.path]) !='undefined') {
452 delete this.just_created[src.path];
455 [ src.gitpath, 'add', src.vpath ],
456 [ src.gitpath, 'commit', { message: src.vpath} ]
464 this.queue.append_val(cmd);
466 var cmd = new GitMontitorQueue(src, this.gitlive);
468 cmd.message = src.vpath;
469 this.queue.append_val(cmd);
473 public void onDeleted(MonitorNamePathDir src)
478 this.lastAdd = new DateTime.now();
479 var cmd = new GitMontitorQueue(src, this.gitlive);
480 if (cmd.shouldIgnore()) {
483 // should check if monitor needs removing..
484 // it should also check if it was a directory.. - so we dont have to commit all..
487 this.queue.append_val(cmd);
489 var cmd = new GitMontitorQueue(src, this.gitlive);
491 cmd.message = src.vpath;
492 cmd.commit_all = true;
494 this.queue.append_val(cmd);
497 public void onCreated(MonitorNamePathDir src) {
502 this.lastAdd = new DateTime.now();
503 var cmd = new GitMontitorQueue(src, this.gitlive);
504 if (cmd.shouldIgnore()) {
508 if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
509 // this.just_created[src.path] = true;
510 return; // we do not handle file create flags... - use done hint.
512 // directory has bee created
513 this.monitor(src.path);
514 this.top.append_val(src.path);
515 this.monitor(src.path );
518 // -- no point in adding a dir.. as git does not handle them...
520 // [ src.gitpath, 'add' , src.vpath, { all: true } ],
521 // [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
527 public void onAttributeChanged(MonitorNamePathDir src) { }
532 this.lastAdd = new DateTime.now();
533 var cmd = new GitMontitorQueue(src, this.gitlive);
534 if (cmd.shouldIgnore()) {
539 this.queue.append_val(cmd);
541 var cmd = new GitMontitorQueue(src, this.gitlive);
543 cmd.message = "Attribute changed " + cmd.vpath;
544 this.queue.append_val(cmd);
548 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
550 this.lastAdd = new DateTime.now();
551 var cmd_s = new GitMontitorQueue(src, this.gitlive);
553 var cmd_d = new GitMontitorQueue(src, this.gitlive);
556 if (cmd_d.gitpath != cmd_s.gitpath) {
558 this.onCreated(dest);
559 this.onChangedDoneHint(dest);
562 // needs to handle move to/from unsupported types..
564 if (this.shouldIgnore(src)) {
565 this.onCreated(dest);
566 this.onChangedDoneHint(dest);
570 if (this.shouldIgnore(dest)) {
579 cmd_s.rm = src.vpath;
580 this.queue.append_val(cmd_s);
586 cmd_d.add = src.vpath;
587 this.queue.append_val(cmd_d);
590 var cmd = new GitMontitorQueue(dest, this.gitlive);
592 cmd.message = "MOVED " + cmd_s.vpath + " to " + cmd_d.vpath;
593 this.queue.append_val(cmd);