RepoStatusPopover.bjs
[gitlive] / GitRepo.vala
1
2 /**
3  * @class Scm.Git.Repo
4  *
5  * @extends Scm.Repo
6  * 
7  *
8  *
9  */
10 static GitRepo  _GitRepo; 
11  
12 public class GitRepo : Object
13 {
14      
15     public Gee.ArrayList<GitMonitorQueue> cmds;
16
17     public string name;
18     public string gitdir;
19     public string git_working_dir;
20     public bool debug = false;
21     public bool has_local_changes = false;
22     public string host = "";
23     public string git_status;    
24     public string git_diff;        
25     public string ahead_or_behind = "";
26     
27     public Gee.HashMap<string,bool> ignore_files;
28     public GitBranch currentBranch;
29     public Gee.HashMap<string,GitBranch> branches; // accessed in GitBranch..
30         public RooTicket? activeTicket;
31     public  Gee.HashMap<string,GitRepo> cache;
32     public  Gee.HashMap<string,string> config_cache;
33     
34     
35     
36         public static GitRepo singleton()
37     {
38         if (_GitRepo == null) {
39             _GitRepo = new GitRepo.single();
40             _GitRepo.cache = new Gee.HashMap<string,GitRepo>();
41         }
42         return _GitRepo;
43     }
44  
45     /**
46     * index of.. matching gitpath..
47     */
48     public static int indexOf( Array<GitRepo> repos, string gitpath) {
49         // make a fake object to compare against..
50         var test_repo = GitRepo.get(gitpath);
51         
52         for(var i =0; i < repos.length; i++) {
53             if (repos.index(i).gitdir == test_repo.gitdir) {
54                 return i;
55             }
56         }
57         return -1;
58     
59     }
60     
61
62     
63     
64     
65     public static   Array<GitRepo> list()
66     {
67
68         //if (GitRepo.list_cache !=  null) {
69         //    unowned  Array<GitRepo>    ret = GitRepo.list_cache;
70          //   return ret;
71         //}
72         var cache = GitRepo.singleton().cache;
73         var list_cache = new Array<GitRepo>();
74         
75         var dir = Environment.get_home_dir() + "/gitlive";
76         
77         var f = File.new_for_path(dir);
78         FileEnumerator file_enum;
79         try {
80             file_enum = f.enumerate_children(
81                 FileAttribute.STANDARD_DISPLAY_NAME + ","+ 
82                 FileAttribute.STANDARD_TYPE,
83                 FileQueryInfoFlags.NONE,
84                 null);
85         } catch (Error e) {
86             
87             return list_cache;
88             
89         }
90         
91         FileInfo next_file; 
92         
93         while (true) {
94             
95             try {
96                 next_file = file_enum.next_file(null);
97                 if (next_file == null) {
98                     break;
99                 }
100                 
101             } catch (Error e) {
102                 GLib.debug("Error: %s",e.message);
103                 break;
104             }
105          
106             //print("got a file " + next_file.sudo () + '?=' + Gio.FileType.DIRECTORY);
107             
108             if (next_file.get_file_type() !=  FileType.DIRECTORY) {
109                 next_file = null;
110                 continue;
111             }
112             
113             if (next_file.get_file_type() ==  FileType.SYMBOLIC_LINK) {
114                 next_file = null;
115                 continue;
116             }
117             
118             if (next_file.get_display_name()[0] == '.') {
119                 next_file = null;
120                 continue;
121             }
122             var sp = dir+"/"+next_file.get_display_name();
123            
124             var gitdir = dir + "/" + next_file.get_display_name() + "/.git";
125             
126             if (!FileUtils.test(gitdir, FileTest.IS_DIR)) {
127                 continue;
128             }
129             
130                 var rep =  GitRepo.get(  sp );
131                 list_cache.append_val(rep);             
132             
133         }
134     
135         return list_cache;
136          
137         }
138         
139         public static GitRepo get(string path) 
140         {
141                 var cache = GitRepo.singleton().cache;
142                 if (cache.has_key(path)) {
143                         return cache.get(path);
144                 }
145                 return new GitRepo(path);
146         }
147         
148     private GitRepo.single() {
149                 // used to create the signleton
150         }
151     /**
152      * constructor:
153      * 
154      * @param {Object} cfg - Configuration
155      *     (basically repopath is currently only critical one.)
156      *
157      */
158      
159     private GitRepo(string path) 
160     {
161         // cal parent?
162         this.name =   File.new_for_path(path).get_basename();
163         this.ignore_files = new Gee.HashMap<string,bool>();
164         
165         this.git_working_dir = path;
166         this.gitdir = path + "/.git";
167         if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) {
168             this.gitdir = path; // naked...
169         }
170         this.cmds = new  Gee.ArrayList<GitMonitorQueue> ();
171         
172                 var cache = GitRepo.singleton().cache;
173         //Repo.superclass.constructor.call(this,cfg);
174                 if ( !cache.has_key(path) ) {
175                         cache.set( path, this);
176         }
177         
178         var r = this.git({ "remote" , "get-url" , "--push" , "origin"});
179         var uri = new Soup.URI(r);      
180         this.host = uri.get_host();
181                 this.init_config();
182         
183         this.loadBranches();
184         this.loadActiveTicket();
185         this.loadStatus();
186     } 
187     
188     public bool is_master_branch()
189     {
190         // special branches that do not allow autopushing now...
191         return this.currentBranch.name == "master" || this.currentBranch.name == "roojs";
192                 
193     }
194     public void init_config()
195     {
196         this.config_cache = new Gee.HashMap<string,string>();
197         // managed = 
198         if (this.get_config("managed") == "") {
199                 this.set_config("managed", this.host == "git.roojs.com" ? "1" : "0");
200                 }
201         if (this.get_config("autocommit") == "") {
202                 this.set_config("autocommit", this.host == "git.roojs.com" ? "1" : "0");
203                 }
204         if (this.get_config("autopush") == "") {
205                 this.set_config("autopush", this.host == "git.roojs.com" ? "1" : "0");
206                 }
207                 
208     }
209     
210     
211     
212     public string get_config(string key) {
213     
214         if (this.config_cache.has_key(key)) {
215                 //GLib.debug("get_config %s = '%s'", key, this.config_cache.get(key));
216                 return this.config_cache.get(key);
217                 }
218         try {
219                 var ret =   this.git({ "config" , "gitlive." + key }).strip();
220                 this.config_cache.set(key, ret);
221                 //GLib.debug("get_config %s = '%s'", key, ret);
222                 return ret;
223         } catch (Error e) {
224                 this.config_cache.set(key, "");
225                 //GLib.debug("get_config (fail) %s = '%s'", key, "");
226                 return ""; // happens when there is nothing set...
227         }
228
229         }
230     public void set_config(string key, string value) {
231         this.git({ "config" , "gitlive." + key, value });
232         this.config_cache.set(key,value);
233         }
234     
235     public bool is_managed()
236     {
237         return this.get_config("managed") == "1";
238     }
239     
240     
241     public bool is_autocommit ()
242     {           
243         return this.get_config("autocommit") == "1";            
244     }
245     
246     public void set_autocommit(bool val)
247     {
248                 this.set_config("autocommit", val ? "1" : "0");
249     
250     }
251     
252     public bool is_auto_branch ()
253     {
254         if (this.name == "gitlog") {
255                 return false;
256                 }
257                 // check remote...
258         if (this.is_managed()) {
259                 return true;
260                 }
261         return false;
262         
263  
264     }
265     
266     public void set_auto_branch(bool val)
267     {
268                 if (this.name == "gitlog") {
269                 return;
270                 }
271                 this.set_config("managed", val ? "1" : "0");
272     
273     }
274     public bool is_autopush ()
275     {
276         return this.get_config("autopush") == "1";
277     }
278     public void set_autopush(bool val)
279     {
280                 this.set_config("autopush", val ? "1" : "0");
281     }
282     
283     
284         public void loadStatus()
285         {
286                 var r = this.git({ "status" , "--porcelain" });
287                 this.git_status = r;
288                 this.has_local_changes = r.length > 0;
289                 
290                 var rs = this.git({ "status" , "-sb" });
291
292                 this.ahead_or_behind = rs.contains("[ahead") ? "A" : (rs.contains("[behind") ? "B" : "");
293                 
294                 
295                 this.git_diff  = this.git({ "diff" , "HEAD", "--no-color" });
296         }    
297
298     
299     public void loadBranches()
300     {
301
302         GitBranch.loadBranches(this);
303     }
304      
305     
306     
307     
308     public string branchesToString()
309     {
310         var ret = "";
311                 foreach( var br in this.branches.values) {
312                         if (br.name == "") {
313                                 continue; 
314                         }
315                         ret += ret.length > 0 ? "\n"  : "";
316                         ret += br.name;
317                 
318                 }
319                 return ret;
320         
321     }
322      public static void doMerges(string action, string ticket_id, string commit_message)
323     {
324        GitMonitor.gitmonitor.stop();
325        
326        var commitrevs = "";
327        var sucess = true;
328        foreach(var  repo in GitRepo.singleton().cache.values) {
329                if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
330                        var res = repo.doMerge(action,ticket_id, commit_message);
331                        if (!res) {
332                                sucess = false;
333                                continue;
334                        }
335                        commitrevs += commitrevs.length > 0 ? " " : "";
336                        commitrevs += repo.currentBranch.lastrev;
337                }
338        }
339        if (sucess && action == "CLOSE") {
340                RooTicket.singleton().getById(ticket_id).close(commitrevs);
341        }
342        GitMonitor.gitmonitor.start();
343     }
344      
345
346     public bool doMerge(string action, string ticket_id, string commit_message)
347     {
348        // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
349        // also need to decide which branch we will merge into?
350                    var ret = "";
351                    if (action == "CLOSE" || action == "LEAVE") {
352                                    
353                try {
354                    var oldbranch = this.currentBranch.name;
355                    this.setActiveTicket(null, "master");
356                            string [] cmd = { "merge",   "--squash",  oldbranch };
357                            this.git( cmd );
358                            cmd = { "commit",   "-a" , "-m",  commit_message };
359                            this.git( cmd );
360                            this.push();
361                            this.loadBranches(); // updates lastrev..
362                
363                        var notification = new Notify.Notification(
364                                "Merged branch %s to master".printf(oldbranch),
365                                "",
366                                 "dialog-information"
367                                
368                        );
369
370                        notification.set_timeout(5);
371                        notification.show();   
372                
373                // close ticket..
374                return true; 
375                
376            } catch (Error e) {
377
378                GitMonitor.gitmonitor.pauseError(e.message);
379                return false;
380            }
381            // error~?? -- show the error dialog...
382                    return false;
383        }
384        if (action == "MASTER") {
385                // merge master into ours..
386                        try {
387                        string[] cmd = { "merge",  "master" };
388                        this.git( cmd );
389                        var notification = new Notify.Notification(
390                                        "Merged code from master to %s".printf(this.currentBranch.name),
391                                        "",
392                                         "dialog-information"
393                                        
394                                );
395                                notification.set_timeout(5);
396                                notification.show();   
397                       
398                        return true;
399                        } catch (Error e) {
400                        GitMonitor.gitmonitor.pauseError(e.message);
401                        return false;
402                    }
403            }
404        if (action == "EXIT") {
405                        try {
406                        var oldbranch  = this.currentBranch.name;
407                          this.setActiveTicket(null, "master");
408                        this.loadBranches();
409                        var notification = new Notify.Notification(
410                                        "Left branch %s".printf(oldbranch),
411                                        "",
412                                         "dialog-information"
413                                        
414                                );
415                                notification.set_timeout(5);
416                                notification.show();   
417                        
418                        return true;
419                    } catch (Error e) {
420                        GitMonitor.gitmonitor.pauseError(e.message);
421
422                        return false;                   
423                    }
424                    // error~?? -- show the error dialog...
425
426        }
427        return false;
428     }
429         
430     public void loadActiveTicket()
431     {
432         this.activeTicket = null;
433                 var ticket_id = this.get_config("ticket");
434         
435         if (ticket_id.length < 1) {
436                 return;
437                 }
438                 this.activeTicket = RooTicket.singleton().getById(ticket_id.strip());
439         
440         
441     }
442     
443     
444     
445     public bool setActiveTicket(RooTicket? ticket, string branchname)
446     {
447         this.set_config("ticket", "");
448         if (!this.createBranchNamed(branchname)) {
449                 return false;
450                 }
451                 this.set_config("ticket", ticket == null ? "": ticket.id);
452         this.activeTicket = ticket;
453         return true;
454     }
455     
456     public bool createBranchNamed(string branchname)
457     {   
458                 
459
460                      if (this.branches.has_key(branchname)) {
461                         this.switchToExistingBranchNamed(branchname);
462                     
463                     } else {
464                                  this.createNewBranchNamed(branchname); 
465                             
466                     }
467                        var notification = new Notify.Notification(
468                        "Changed to branch %s".printf(branchname),
469                        "",
470                         "dialog-information"
471                        
472                );
473
474                notification.set_timeout(5);
475                notification.show();   
476        
477          
478          this.loadBranches(); // update branch list...
479          //GitMonitor.gitmonitor.runQueue(); // no point - we have hidden the queue..
480          return true;
481     }
482      bool switchToExistingBranchNamed(string branchname)
483      {
484                 var stash = false;
485                                          // this is where it get's tricky...
486                 string files = "";
487                 try {                   
488                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
489                                 files = this.git(cmd);
490                                 stash = files.length> 1 ;
491                                 
492                                 
493                                 cmd = { "stash" };                      
494                                 if (stash) { this.git(cmd); }
495                                 
496                                 this.pull();
497                                 
498                                 cmd = { "checkout", branchname  };
499                                 this.git(cmd);
500                   } catch(Error e) {
501                                 GitMonitor.gitmonitor.pauseError(e.message);
502                                 return false;           
503                   }
504                 try {
505                    if (branchname != "master") {
506                        string[] cmd = { "merge", "master"  };
507                             this.git(cmd);
508                             this.push();
509                        
510                     }
511                     
512                 } catch(Error e) {
513                     string[] cmd = { "checkout", "master"  };
514                     this.git(cmd);
515                         GitMonitor.gitmonitor.pauseError(
516                                 "Use\n\na) git checkout %s\nb) git mergetool\nc) git commit\nd) git push\n d) stash pop \ne) start gitlive again\n".printf(
517                                         branchname)
518                                  + e.message
519                         );
520                         return false;           
521                  
522                 }
523                 try {                                   
524                     string[]  cmd = { "stash", "pop"  };
525                     if (stash) { 
526                         this.git(cmd); 
527                         var fl = files.split("\n");
528                         cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
529                         foreach(var f in fl) {
530                                 if (f.length < 1) continue;
531                                 cmd += f;
532                         }
533                         this.git(cmd);                              
534                 }
535              
536
537                    
538                 } catch(Error ee) {
539                         GitMonitor.gitmonitor.pauseError(ee.message);
540                         return false;           
541                 }
542        this.push();
543        return true;                             
544                  
545      }
546     
547     
548     
549      bool createNewBranchNamed(string branchname)
550      {
551                 var stash = false;
552                  try {                                  
553                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
554                                 var files = this.git(cmd);
555                                 stash = files.length> 1 ;
556                         
557                          cmd = { "checkout", "-b" , branchname  };
558                         this.git(cmd);
559
560                cmd = { "push", "-u" , "origin" ,"HEAD"  };
561                         this.git(cmd);
562                                 if (stash) { 
563
564                                 var fl = files.split("\n");
565                                 cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
566                                 foreach(var f in fl) {
567                                         if (f.length < 1) continue;
568                                         cmd += f;
569                                 }
570                                 this.git(cmd);  
571                                 this.push();                        
572                         }
573
574              
575                 } catch(Error ee) {
576                                 GitMonitor.gitmonitor.pauseError(ee.message);
577                                 return false;           
578                         }
579                         return true;
580      
581      }
582     
583     
584     
585     /**
586      * add:
587      * add files to track.
588      *
589      * @argument {Array} files the files to add.
590      */
591     public string add ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
592     {
593         // should really find out if these are untracked files each..
594         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
595         // not sure if that is how git works.. but just be certian.
596         var ret = "";
597         for (var i = 0; i < files.size;i++) {
598             var f = files.get(i).vname;
599             try {
600                 string[] cmd = { "add",    f  };
601                 this.git( cmd );
602             } catch (Error e) {
603                 ret += e.message  + "\n";
604             }        
605
606         }
607         return ret;
608     }
609         
610     public bool is_ignore(string fname) throws Error, SpawnError
611     {
612                 if (fname == ".gitignore") {
613                         this.ignore_files.clear();
614                 }
615                 
616                 if (this.ignore_files.has_key(fname)) {
617                         return this.ignore_files.get(fname);
618                 }
619                 
620                 try {
621                         var ret = this.git( { "check-ignore" , fname } );
622                         this.ignore_files.set(fname, ret.length >  0);
623                         return ret.length > 0;
624                 } catch (SpawnError e) {
625                         this.ignore_files.set(fname, false);
626                         return false;
627                 }
628                  
629     } 
630     
631     
632       /**
633      * remove:
634      * remove files to track.
635      *
636      * @argument {Array} files the files to add.
637      */
638     public string remove  ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
639     {
640         // this may fail if files do not exist..
641         // should really find out if these are untracked files each..
642         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
643         // not sure if that is how git works.. but just be certian.
644         var ret = "";
645
646         for (var i = 0; i < files.size;i++) {
647             var f = files.get(i).vname;
648             try {
649                 string[] cmd = { "rm",  "-f" ,  f  };
650                 this.git( cmd );
651             } catch (Error e) {
652                 ret += e.message  + "\n";
653             }        
654         }
655
656         return ret;
657
658     }
659     
660     
661     /**
662      * commit:
663      * perform a commit.
664      *
665      * @argument {Object} cfg commit configuration
666      * 
667      * @property {String} name (optional)
668      * @property {String} email (optional)
669      * @property {String} changed (date) (optional)
670      * @property {String} reason (optional)
671      * @property {Array} files - the files that have changed. 
672      * 
673      */
674      
675     public string commit ( string message, Gee.ArrayList<GitMonitorQueue> files  ) throws Error, SpawnError
676     {
677         
678
679         /*
680         var env = [];
681
682         if (typeof(cfg.name) != 'undefined') {
683             args.push( {
684                 'author' : cfg.name + ' <' + cfg.email + '>'
685             });
686             env.push(
687                 "GIT_COMMITTER_NAME" + cfg.name,
688                 "GIT_COMMITTER_EMAIL" + cfg.email
689             );
690         }
691
692         if (typeof(cfg.changed) != 'undefined') {
693             env.push("GIT_AUTHOR_DATE= " + cfg.changed )
694             
695         }
696         */
697         string[] args = { "commit", "-m" };
698         args +=  (message.length > 0  ? message : "Changed" );
699         for (var i = 0; i< files.size ; i++ ) {
700             args += files.get(i).vname; // full path?
701         }
702          
703         return this.git(args);
704     }
705     
706     /**
707      * pull:
708      * Fetch and merge remote repo changes into current branch..
709      *
710      * At present we just need this to update the current working branch..
711      * -- maybe later it will have a few options and do more stuff..
712      *
713      */
714     public string pull () throws Error, SpawnError
715     {
716         // should probably hand error conditions better... 
717         string[] cmd = { "pull" , "--no-edit" };
718         return this.git( cmd );
719
720         
721     }
722     
723     public delegate void GitAsyncCallback (GitRepo repo, int err, string str);
724     public void pull_async(GitAsyncCallback cb) 
725     {
726     
727          string[] cmd = { "pull" , "--no-edit" };
728          this.git_async( cmd , cb);
729          
730     
731     }
732     
733     /**
734      * push:
735      * Send local changes to remote repo(s)
736      *
737      * At present we just need this to push the current branch.
738      * -- maybe later it will have a few options and do more stuff..
739      *
740      */
741     public string push () throws Error, SpawnError
742     {
743         // should 
744         return this.git({ "push"  });
745         
746     }
747     
748     
749     
750      /**
751      * git:
752      * The meaty part.. run spawn.. with git..
753      *
754      *
755      */
756     
757     public string git(string[] args_in ) throws Error, SpawnError
758     {
759         // convert arguments.
760         
761         string[]  args = { "git" };
762         //args +=  "--git-dir";
763         //args +=  this.gitdir;
764         args +=  "--no-pager";
765  
766  
767         //if (this.gitdir != this.repopath) {
768         //    args +=   "--work-tree";
769          //   args += this.repopath; 
770         //}
771         for (var i = 0; i < args_in.length;i++) {
772             args += args_in[i];
773         }            
774
775         //this.lastCmd = args.join(" ");
776         //if(this.debug) {
777             GLib.debug( "CWD=%s",  this.git_working_dir ); 
778             GLib.debug( "cmd: %s", string.joinv (" ", args)); 
779         //}
780
781         string[]   env = {};
782         string  home = "HOME=" + Environment.get_home_dir() ;
783         env +=  home ;
784         // do not need to set gitpath..
785         //if (File.exists(this.repo + '/.git/config')) {
786             //env.push("GITPATH=" + this.repo );
787         //}
788           
789         var cfg = new SpawnConfig(this.git_working_dir , args , env);
790         //cfg.debug = true;
791
792        // may throw error...
793         var sp = new Spawn(cfg);
794       
795              //GLib.debug( "GOT result: %d" , sp.result);
796       
797         // diff output is a bit big..
798                 if (args_in[0] != "diff") {
799                 GLib.debug( "GOT: %s" , sp.output);
800         }
801         // parse output for some commands ?
802         return sp.output;
803     }
804         
805    unowned GitAsyncCallback git_async_on_callback;
806         public void  git_async( string[] args_in,   GitAsyncCallback cb ) throws Error, SpawnError
807     {
808         // convert arguments.
809        this.git_async_on_callback = cb;
810         string[]  args = { "git" };
811         //args +=  "--git-dir";
812         //args +=  this.gitdir;
813         args +=  "--no-pager";
814  
815  
816         //if (this.gitdir != this.repopath) {
817         //    args +=   "--work-tree";
818          //   args += this.repopath; 
819         //}
820         for (var i = 0; i < args_in.length;i++) {
821             args += args_in[i];
822         }            
823
824         //this.lastCmd = args.join(" ");
825         //if(this.debug) {
826             GLib.debug( "CWD=%s",  this.git_working_dir ); 
827             //print( "cmd: %s\n", string.joinv (" ", args)); 
828         //}
829
830         string[]   env = {};
831         string  home = "HOME=" + Environment.get_home_dir() ;
832         env +=  home ;
833         // do not need to set gitpath..
834         //if (File.exists(this.repo + '/.git/config')) {
835             //env.push("GITPATH=" + this.repo );
836         //}
837         
838
839         var cfg = new SpawnConfig(this.git_working_dir , args , env);
840         cfg.async = true;
841        
842
843        // may throw error...
844         var sp = new Spawn(cfg);
845                 //sp.ref();
846         //this.ref();
847         sp.run(this.git_async_on_complete); 
848          
849     }
850     
851     void git_async_on_complete(int err, string output)
852     {
853                 GLib.debug("GOT %d : %s", err, output);
854                 this.git_async_on_callback(this, err, output);
855 //              this.unref();   
856         //      sp.unref();             
857     
858     
859     }
860     
861  
862          
863     
864  
865     public void update_async(GitAsyncCallback cb) 
866     {
867          string[] cmd = { "fetch" , "--all" };
868          this.git_async( cmd , cb);
869          
870     }
871     
872     
873     static uint update_all_total = 0;
874     static string update_all_after = "";
875      
876     public static void updateAll(string after)
877     {
878                 update_all_after = after;
879                 var tr =  GitRepo.singleton().cache;
880             
881         
882        update_all_total = tr.size;
883        foreach(var repo  in tr.values) {
884                 if (!repo.is_managed()) {
885                         update_all_total--;                     
886                         continue;
887                 }
888            repo.update_async(updateAllCallback); 
889         } 
890                 GLib.debug("calls total = %d", (int) update_all_total);
891     }
892     public static void  updateAllCallback(GitRepo repo, int err, string res)
893     {
894         repo.loadBranches();
895         repo.loadStatus();
896         
897         update_all_total--;
898                 GLib.debug("calls remaining = %d", (int)update_all_total);      
899         if (update_all_total > 0 ) {
900
901                 return;
902                 }
903                 GLib.debug("call after load = %s", update_all_after);    
904                 
905                 switch (update_all_after) {
906                         case "show_clones":
907                                 Clones.singleton().show();
908                                 break;
909                         default:
910                                 GLib.debug("Unkown call after load = %s", update_all_after);            
911                                 break;
912                 }
913                 return;
914     }
915     
916     
917     
918 }