3 public GitMontitorQueue : MonitorNamePathDir {
6 public GitMontitorQueue(MonitorNamePathDir f, string gitlive) {
13 var vpath_ar = this.path.substring(gitlive.length +1).split('/', 0);
15 this.gitpath = gitlive + '/' + vpath_ar[0];
18 for (var i = 1; i< vpath_ar.length; i++) {
21 this.vpath = string.joinv("/", vpath);
22 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
32 public class GitMonitor : Monitor
37 * @property {String} the "gitlive" directory, normally ~/gitlive
38 * dset by OWNER... - we should do this as a CTOR.
41 public string gitlive = '';
44 public Array<GtkMonitorQueuequeue>;
45 public bool queueRunning = false;
47 public DateTime lastAdd;
52 // what does this do to the old one...
53 this.queue = new Array<FileMonitor> ();
54 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
58 public void resume () {
60 this.queue = new Array<FileMonitor> ();
61 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
66 * Start the monitoring
67 * and run the queue every 500 milliseconds..
71 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
74 this.lastAdd = new DateTime.now();
76 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
78 // call this.monitor on each of 'top'
79 for(int i = 0; i < this.top.length ; i++) {
80 this.monitor(this.top.index(i), ( fm, f_orig, of_orig, event_type) => {
81 this.onEvent (fm, f_orig, of_orig, event_type ) ;
84 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
89 var notification = new Notify.Notification({
91 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
95 notification.set_timeout(5);
103 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
104 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
105 if (!_this.queue.length || _this.queueRunning) {
109 var last = this.lastAdd.difference(new DateTime.now());
112 //print("LAST RUN?" + last);
114 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
117 //_this.lastAdd = new Date();
129 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
134 public void monitor (string path, onEventHander fn , int depth = 0)
137 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
140 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
141 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
146 // FIXME - check if repo is flagged as not autocommit..
147 //var repo = imports.Scm.Repo.Repo.get(path);
148 //if (!repo || !repo.autocommit()) {
154 // check if the repo is to be monitored.
155 //print("PATH : " + path);
158 base.monitor(path,fn, depth);
165 * - pulls the items off the queue
166 * (as commands run concurrently and new items may get added while it's running)
167 * - runs the queue items
171 public void runQueue()
177 this.queueRunning = true;
179 var cmds = new Array<GitMontitorQueue>();
180 for(var i = 0; i < this.queue.length; i++) {
181 cmds.append_val(this.queue.item(i));
184 this.queue = new Array<GitMontitorQueue>();// empty queue!
187 var success = new Array<String>();
188 var failure = new Array<GitMontitorQueue>();
189 var repos = new Array<GitMontitorQueue>(); //??
190 var done = new Array<GitMontitorQueue>();
192 // first build a array of repo's to work with
193 var repo_list = new Array<GitMontitorRepo>();
197 //print(JSON.stringify(cmds));
200 for(var i = 0; i < cmds.length; i++) {
203 var gitpath = cmd.gitpath;
204 var ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
206 repo_list.append_val(new GitMontitorRepo( gitpath ));
207 ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
211 //if (typeof(repo_list[gitpath]) == 'undefined') {
212 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
213 // repo_list[gitpath].cmds = [];
214 // repo_list[gitpath].pull();
216 repo_list.item(ix).append_val(cmd);
220 // build add, remove and commit message list..
222 for(var i = 0;i < repo_list.length;i++) {
225 var repo = repo_list.item(i);
227 var add_files = new Array<GitMontitorQueue>();
228 var remove_files = new Array<GitMontitorQueue>();
229 var messages = new Array<GitMontitorQueue>();
230 //print(JSON.stringify(repo.cmds,null,4));
232 for(var ii = 0;ii < repo.length;ii++) {
233 var cmd = repo.item(ii);
239 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
244 add_files.append_val(cmd);
248 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
252 // if file exists, do not try and delete it.
253 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
257 remove_files.append_val(cmd);
261 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
265 messages.append_val(cmd);
272 // these can fail... at present... as we wildcard stuff.
273 stdout.printf("ADD : %d files" , add_files.length);
275 // make sure added files do not get removed..
277 var remove_files_f = new Array<GitMontitorQueue>();
278 for(var ii = 0;ii < remove_files.length;ii++) {
279 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
282 remove_files_f.append_val(remove_files.item(ii));
284 stdout.printf("REMOVE : %d files" , remove_files.length);
286 // make sure monitoring is paused so it does not recursively pick up
292 repo.remove(remove_files);
297 success.append_val(repo.commit(
298 GitMontitorQueue.messageToString(messages)
301 success.push(repo.push());
304 failure.append_val(e.message);
309 // finally merge all the commit messages.
312 // catch notification failures.. so we can carry on..
313 if (success.length) {
314 var success_str = "";
315 for(var ii = 0;ii < success.length;ii++) {
316 success_str+= success.item(ii) + "\n";
319 var notification = new Notify.Notification(
326 notification.set_timeout(5);
330 if (failure.length) {
331 var failure_str = "";
332 for(var ii = 0;ii < failure.length;ii++) {
333 failure_str+= failure.item(ii) + "\n";
335 var notification = new Notify.Notification({
336 summary: "Git Live ERROR!!",
342 notification.set_timeout(5); // show errros for longer
349 this.queueRunning = false;
354 public bool shouldIgnore(GitMontitorQueue f)
362 // vim.. what a seriously brain dead program..
363 if (f.name == '4913') {
367 if (f.name[0] == '.') {
369 if (f.name == '.htaccess') {
375 //if (f.name.match(/~$/)) {
378 //if (f.name.match(/^nbproject/)) {
381 // ignore anything in top level!!!!
382 if (!f.vpath.length) {
391 * Fill in gitlive, vpath and repo
394 parsePath: function(GitMontitorQueue f)
397 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/', 0);
399 f.gitpath = this.gitlive + '/' + vpath_ar[0];
402 for (var i = 1; i< vpath_ar.length; i++) {
403 vpath += vpath_ar[i];
405 f.vpath = string.joinv("/", vpath);
406 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
411 string[] just_created;
413 public void initRepo(MonitorNamePathDir src) { } // called on startup at the top level repo dir.
414 public void onChanged(MonitorNamePathDir src) { }
415 public void onChangesDoneHint(MonitorNamePathDir src) { }
416 public void onDeleted(MonitorNamePathDir src) { }
417 public void onCreated(MonitorNamePathDir src) { }
418 public void onAttributeChanged(MonitorNamePathDir src) { }
419 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
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) { }
437 this.lastAdd = new Date();
439 if (this.shouldIgnore(src)) {
445 if (typeof(this.just_created[src.path]) !='undefined') {
446 delete this.just_created[src.path];
449 [ src.gitpath, 'add', src.vpath ],
450 [ src.gitpath, 'commit', { message: src.vpath} ]
458 [ src.gitpath, 'add', src.vpath ],
459 [ src.gitpath, 'commit', { message: src.vpath} ]