3 public GitMontitorQueue : MonitorNamePathDir {
6 public stirng message ; // for commit
7 public GitMontitorQueue(MonitorNamePathDir f, string gitlive) {
14 var vpath_ar = this.path.substring(gitlive.length +1).split('/', 0);
16 this.gitpath = gitlive + '/' + vpath_ar[0];
19 for (var i = 1; i< vpath_ar.length; i++) {
22 this.vpath = string.joinv("/", vpath);
23 //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
28 public bool shouldIgnore(GitMonitor gm)
33 // vim.. what a seriously brain dead program..
34 if (this.name == '4913') {
38 if (this.name[0] == '.') {
40 if (this.name == '.htaccess') {
46 //if (f.name.match(/~$/)) {
49 //if (f.name.match(/^nbproject/)) {
52 // ignore anything in top level!!!!
53 if (!this.vpath.length) {
64 public class GitMonitor : Monitor
69 * @property {String} the "gitlive" directory, normally ~/gitlive
70 * dset by OWNER... - we should do this as a CTOR.
73 public string gitlive = '';
76 public Array<GtkMonitorQueuequeue>;
77 public bool queueRunning = false;
79 public DateTime lastAdd;
84 // what does this do to the old one...
85 this.queue = new Array<FileMonitor> ();
86 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
90 public void resume () {
92 this.queue = new Array<FileMonitor> ();
93 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
98 * Start the monitoring
99 * and run the queue every 500 milliseconds..
102 public void start() {
103 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
106 this.lastAdd = new DateTime.now();
108 Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
110 // call this.monitor on each of 'top'
111 for(int i = 0; i < this.top.length ; i++) {
112 this.monitor(this.top.index(i), ( fm, f_orig, of_orig, event_type) => {
113 this.onEvent (fm, f_orig, of_orig, event_type ) ;
116 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
121 var notification = new Notify.Notification({
123 this.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
127 notification.set_timeout(5);
135 Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
136 //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
137 if (!_this.queue.length || _this.queueRunning) {
141 var last = this.lastAdd.difference(new DateTime.now());
144 //print("LAST RUN?" + last);
146 if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
149 //_this.lastAdd = new Date();
161 StatusIcon.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
166 public void monitor (string path, onEventHander fn , int depth = 0)
169 //var depth = typeof(depth) == 'number' ? depth *1 : 0;
172 // if we are not at top level.. and there is a .git directory (it's a submodule .. ignore)
173 if (depth > 1 && GLib.file_test(path + '/.git' , GLib.FileTest.IS_DIR)) {
178 // FIXME - check if repo is flagged as not autocommit..
179 //var repo = imports.Scm.Repo.Repo.get(path);
180 //if (!repo || !repo.autocommit()) {
186 // check if the repo is to be monitored.
187 //print("PATH : " + path);
190 base.monitor(path,fn, depth);
197 * - pulls the items off the queue
198 * (as commands run concurrently and new items may get added while it's running)
199 * - runs the queue items
203 public void runQueue()
209 this.queueRunning = true;
211 var cmds = new Array<GitMontitorQueue>();
212 for(var i = 0; i < this.queue.length; i++) {
213 cmds.append_val(this.queue.item(i));
216 this.queue = new Array<GitMontitorQueue>();// empty queue!
219 var success = new Array<String>();
220 var failure = new Array<GitMontitorQueue>();
221 var repos = new Array<GitMontitorQueue>(); //??
222 var done = new Array<GitMontitorQueue>();
224 // first build a array of repo's to work with
225 var repo_list = new Array<GitMontitorRepo>();
229 //print(JSON.stringify(cmds));
232 for(var i = 0; i < cmds.length; i++) {
235 var gitpath = cmd.gitpath;
236 var ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
238 repo_list.append_val(new GitMontitorRepo( gitpath ));
239 ix = GitMontitorRepo.indexOf(this.repos, cmd.gitpath);
243 //if (typeof(repo_list[gitpath]) == 'undefined') {
244 // repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
245 // repo_list[gitpath].cmds = [];
246 // repo_list[gitpath].pull();
248 repo_list.item(ix).append_val(cmd);
252 // build add, remove and commit message list..
254 for(var i = 0;i < repo_list.length;i++) {
257 var repo = repo_list.item(i);
259 var add_files = new Array<GitMontitorQueue>();
260 var remove_files = new Array<GitMontitorQueue>();
261 var messages = new Array<GitMontitorQueue>();
262 //print(JSON.stringify(repo.cmds,null,4));
264 for(var ii = 0;ii < repo.length;ii++) {
265 var cmd = repo.item(ii);
271 if (GitMontitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
276 add_files.append_val(cmd);
280 if (GitMontitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
284 // if file exists, do not try and delete it.
285 if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
289 remove_files.append_val(cmd);
293 if (GitMontitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
297 messages.append_val(cmd);
304 // these can fail... at present... as we wildcard stuff.
305 stdout.printf("ADD : %d files" , add_files.length);
307 // make sure added files do not get removed..
309 var remove_files_f = new Array<GitMontitorQueue>();
310 for(var ii = 0;ii < remove_files.length;ii++) {
311 if (GitMontitorQueue.indexOfAdd(add_files, remove_files.item(ii).rm) > -1 ) {
314 remove_files_f.append_val(remove_files.item(ii));
316 stdout.printf("REMOVE : %d files" , remove_files.length);
318 // make sure monitoring is paused so it does not recursively pick up
324 repo.remove(remove_files);
329 success.append_val(repo.commit(
330 GitMontitorQueue.messageToString(messages)
333 success.push(repo.push());
336 failure.append_val(e.message);
341 // finally merge all the commit messages.
344 // catch notification failures.. so we can carry on..
345 if (success.length) {
346 var success_str = "";
347 for(var ii = 0;ii < success.length;ii++) {
348 success_str+= success.item(ii) + "\n";
351 var notification = new Notify.Notification(
358 notification.set_timeout(5);
362 if (failure.length) {
363 var failure_str = "";
364 for(var ii = 0;ii < failure.length;ii++) {
365 failure_str+= failure.item(ii) + "\n";
367 var notification = new Notify.Notification({
368 summary: "Git Live ERROR!!",
374 notification.set_timeout(5); // show errros for longer
381 this.queueRunning = false;
388 string[] just_created;
390 public void initRepo(MonitorNamePathDir src) { } // called on startup at the top level repo dir.
391 public void onChanged(MonitorNamePathDir src) { }
392 public void onChangesDoneHint(MonitorNamePathDir src) { }
393 public void onDeleted(MonitorNamePathDir src) { }
394 public void onCreated(MonitorNamePathDir src) { }
395 public void onAttributeChanged(MonitorNamePathDir src) { }
396 public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { }
400 public void onChanged(MonitorNamePathDir src) { }
402 return; // always ignore this..?
403 //this.parsePath(src);
409 * results in git add + git commit..
412 public void onChangesDoneHint(MonitorNamePathDir src) { }
420 this.lastAdd = new DateTime.now();
421 var cmd = new GitMontitorQueue(src, this.gitlive);
422 if (cmd.shouldIgnore()) {
429 if (this.is_just_created(cmd.path)) {
431 if (typeof(this.just_created[src.path]) !='undefined') {
432 delete this.just_created[src.path];
435 [ src.gitpath, 'add', src.vpath ],
436 [ src.gitpath, 'commit', { message: src.vpath} ]
444 this.queue.append_val(cmd);
446 var cmd = new GitMontitorQueue(src, this.gitlive);
448 cmd.message = src.vpath;
449 this.queue.append_val(cmd);