3 public GitMontitorQueue : MonitorNamePathDir {
6 public GitMontitorQueue(MonitorNamePathDir f) {
15 public class GitMonitor : Monitor
20 * @property {String} the "gitlive" directory, normally ~/gitlive
21 * dset by OWNER... - we should do this as a CTOR.
24 public string gitlive = '';
27 public Array<GtkMonitorQueuequeue>;
28 public bool queueRunning = false;
30 public DateTime lastAdd;
35 // what does this do to the old one...
36 this.queue = new Array<FileMonitor> ();
37 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
41 public void resume () {
43 this.queue = new Array<FileMonitor> ();
44 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
49 * Start the monitoring
50 * and run the queue every 500 milliseconds..
54 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
57 this.lastAdd = new DateTime.now();
59 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
61 // call this.monitor on each of 'top'
62 for(int i = 0; i < this.top.length ; i++) {
63 this.monitor(this.top.index(i), ( fm, f_orig, of_orig, event_type) => {
64 this.onEvent (fm, f_orig, of_orig, event_type ) ;
67 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
72 var notification = new Notify.Notification({
74 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
78 notification.set_timeout(5);
86 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
87 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
88 if (!_this.queue.length || _this.queueRunning) {
92 var last = this.lastAdd.difference(new DateTime.now());
95 //print("LAST RUN?" + last);
97 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
100 //_this.lastAdd = new Date();
112 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
117 public void monitor (string path, onEventHander fn , int depth = 0)
120 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
123 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
124 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
129 // FIXME - check if repo is flagged as not autocommit..
130 //var repo = imports.Scm.Repo.Repo.get(path);
131 //if (!repo || !repo.autocommit()) {
137 // check if the repo is to be monitored.
138 //print("PATH : " + path);
141 base.monitor(path,fn, depth);
148 * - pulls the items off the queue
149 * (as commands run concurrently and new items may get added while it's running)
150 * - runs the queue items
154 public void runQueue()
160 this.queueRunning = true;
162 var cmds = new Array<GitMontitorQueue>();
163 for(var i = 0; i < this.queue.length; i++) {
164 cmds.append_val(this.queue.item(i));
167 this.queue = new Array<GitMontitorQueue>();// empty queue!
170 var success = new Array<String>();
171 var failure = new Array<GitMontitorQueue>();
172 var repos = new Array<GitMontitorQueue>(); //??
173 var done = new Array<GitMontitorQueue>();
175 // first build a array of repo's to work with
176 var repo_list = new Array<GitMontitorRepo>();
180 //print(JSON.stringify(cmds));
183 for(var i = 0; i < cmds.length; i++) {
186 var gitpath = cmd.gitpath;
187 var ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
189 repo_list.append_val(new GitMontitorRepo( gitpath ));
190 ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
194 //if (typeof(repo_list[gitpath]) == 'undefined') {
195 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
196 // repo_list[gitpath].cmds = [];
197 // repo_list[gitpath].pull();
199 repo_list.item(ix).append_val(cmd);
203 // build add, remove and commit message list..
205 for(var i = 0;i < repo_list.length;i++) {
208 var repo = repo_list.item(i);
210 var add_files = new Array<GitMontitorQueue>();
211 var remove_files = new Array<GitMontitorQueue>();
212 var messages = new Array<GitMontitorQueue>();
213 //print(JSON.stringify(repo.cmds,null,4));
215 for(var ii = 0;ii < repo.length;ii++) {
216 var cmd = repo.item(ii);
222 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
227 add_files.append_val(cmd);
231 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
235 // if file exists, do not try and delete it.
236 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
240 remove_files.append_val(cmd);
244 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
248 messages.append_val(cmd);
255 // these can fail... at present... as we wildcard stuff.
256 stdout.printf("ADD : %d files" , add_files.length);
258 // make sure added files do not get removed..
260 var remove_files_f = new Array<GitMontitorQueue>();
261 for(var ii = 0;ii < remove_files.length;ii++) {
262 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
265 remove_files_f.append_val(remove_files.item(ii));
267 stdout.printf("REMOVE : %d files" , remove_files.length);
269 // make sure monitoring is paused so it does not recursively pick up
275 repo.remove(remove_files);
280 success.append_val(repo.commit(
281 GitMontitorQueue.messageToString(messages)
284 success.push(repo.push());
287 failure.append_val(e.message);
292 // finally merge all the commit messages.
295 // catch notification failures.. so we can carry on..
296 if (success.length) {
297 var success_str = "";
298 for(var ii = 0;ii < success.length;ii++) {
299 success_str+= success.item(ii) + "\n";
302 var notification = new Notify.Notification(
309 notification.set_timeout(5);
313 if (failure.length) {
314 var failure_str = "";
315 for(var ii = 0;ii < failure.length;ii++) {
316 failure_str+= failure.item(ii) + "\n";
318 var notification = new Notify.Notification({
319 summary: "Git Live ERROR!!",
325 notification.set_timeout(5); // show errros for longer
332 this.queueRunning = false;
337 public bool shouldIgnore(GitMontitorQueue f)
345 // vim.. what a seriously brain dead program..
346 if (f.name == '4913') {
350 if (f.name[0] == '.') {
352 if (f.name == '.htaccess') {
358 //if (f.name.match(/~$/)) {
361 //if (f.name.match(/^nbproject/)) {
364 // ignore anything in top level!!!!
365 if (!f.vpath.length) {
374 * Fill in gitlive, vpath and repo
377 parsePath: function(GitMontitorQueue f)
380 var vpath_ar = f.path.substring(this.gitlive.length +1).split('/', 0);
382 f.gitpath = this.gitlive + '/' + vpath_ar[0];
385 for (var i = 1; i< vpath_ar.length; i++) {
386 vpath += vpath_ar[i];
388 f.vpath = string.joinv("/", vpath);
389 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
394 string[] just_created;
396 public void initRepo(MonitorNamePathDir src) { } // called on startup at the top level repo dir.
397 public void onChanged(MonitorNamePathDir src) { }
398 public void onChangesDoneHint(MonitorNamePathDir src) { }
399 public void onDeleted(MonitorNamePathDir src) { }
400 public void onCreated(MonitorNamePathDir src) { }
401 public void onAttributeChanged(MonitorNamePathDir src) { }
402 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
406 public void onChanged(MonitorNamePathDir src) { }
408 return; // always ignore this..?
409 //this.parsePath(src);
415 * results in git add + git commit..
418 public void onChangesDoneHint(MonitorNamePathDir src) { }
420 this.lastAdd = new Date();
422 if (this.shouldIgnore(src)) {
428 if (typeof(this.just_created[src.path]) !='undefined') {
429 delete this.just_created[src.path];
432 [ src.gitpath, 'add', src.vpath ],
433 [ src.gitpath, 'commit', { message: src.vpath} ]
441 [ src.gitpath, 'add', src.vpath ],
442 [ src.gitpath, 'commit', { message: src.vpath} ]