GitRepo.vala
[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                 return this.config_cache.get(key);
216                 }
217         try {
218                 var ret =   this.git({ "config" , "gitlive." + key });
219                 this.config_cache.set(key, ret);
220                 return ret;
221         } catch (Error e) {
222                 this.config_cache.set(key, "");
223                 return ret;
224                 return ""; // happens when there is nothing set...
225         }
226
227         }
228     public void set_config(string key, string value) {
229         this.git({ "config" , "gitlive." + key, value });
230         this.config_cache.set(key,value);
231         }
232     
233     public bool is_managed()
234     {
235         return this.get_config("managed") == "1";
236     }
237     
238     
239     public bool is_autocommit ()
240     {           
241         return this.get_config("autocommit") == "1";            
242     }
243     
244     public void set_autocommit(bool val)
245     {
246                 this.set_config("autocommit", val ? "1" : "0");
247     
248     }
249     
250     public bool is_auto_branch ()
251     {
252         if (this.name == "gitlog") {
253                 return false;
254                 }
255                 // check remote...
256         if (this.is_managed()) {
257                 return true;
258                 }
259         return false;
260         
261  
262     }
263     
264     public void set_auto_branch(bool val)
265     {
266                 if (this.name == "gitlog") {
267                 return;
268                 }
269                 this.set_config("managed", val ? "1" : "0");
270     
271     }
272     public bool is_autopush ()
273     {
274         return this.get_config("autopush") == "1";
275     }
276     public void set_autopush(bool val)
277     {
278                 this.set_config("autopush", val ? "1" : "0");
279     }
280     
281     
282         public void loadStatus()
283         {
284                 var r = this.git({ "status" , "--porcelain" });
285                 this.git_status = r;
286                 this.has_local_changes = r.length > 0;
287                 
288                 var rs = this.git({ "status" , "-sb" });
289
290                 this.ahead_or_behind = rs.contains("[ahead") ? "A" : (rs.contains("[behind") ? "B" : "");
291                 
292                 
293                 this.git_diff  = this.git({ "diff" , "HEAD", "--no-color" });
294         }    
295
296     
297     public void loadBranches()
298     {
299
300         GitBranch.loadBranches(this);
301     }
302      
303     
304     
305     
306     public string branchesToString()
307     {
308         var ret = "";
309                 foreach( var br in this.branches.values) {
310                         if (br.name == "") {
311                                 continue; 
312                         }
313                         ret += ret.length > 0 ? "\n"  : "";
314                         ret += br.name;
315                 
316                 }
317                 return ret;
318         
319     }
320      public static void doMerges(string action, string ticket_id, string commit_message)
321     {
322        GitMonitor.gitmonitor.stop();
323        
324        var commitrevs = "";
325        var sucess = true;
326        foreach(var  repo in GitRepo.singleton().cache.values) {
327                if (repo.activeTicket != null && repo.activeTicket.id == ticket_id) {
328                        var res = repo.doMerge(action,ticket_id, commit_message);
329                        if (!res) {
330                                sucess = false;
331                                continue;
332                        }
333                        commitrevs += commitrevs.length > 0 ? " " : "";
334                        commitrevs += repo.currentBranch.lastrev;
335                }
336        }
337        if (sucess && action == "CLOSE") {
338                RooTicket.singleton().getById(ticket_id).close(commitrevs);
339        }
340        GitMonitor.gitmonitor.start();
341     }
342      
343
344     public bool doMerge(string action, string ticket_id, string commit_message)
345     {
346        // in theory we should check to see if other repo's have got the same branch and merge all them at the same time.
347        // also need to decide which branch we will merge into?
348                    var ret = "";
349                    if (action == "CLOSE" || action == "LEAVE") {
350                                    
351                try {
352                    var oldbranch = this.currentBranch.name;
353                    this.setActiveTicket(null, "master");
354                            string [] cmd = { "merge",   "--squash",  oldbranch };
355                            this.git( cmd );
356                            cmd = { "commit",   "-a" , "-m",  commit_message };
357                            this.git( cmd );
358                            this.push();
359                            this.loadBranches(); // updates lastrev..
360                
361                        var notification = new Notify.Notification(
362                                "Merged branch %s to master".printf(oldbranch),
363                                "",
364                                 "dialog-information"
365                                
366                        );
367
368                        notification.set_timeout(5);
369                        notification.show();   
370                
371                // close ticket..
372                return true; 
373                
374            } catch (Error e) {
375
376                GitMonitor.gitmonitor.pauseError(e.message);
377                return false;
378            }
379            // error~?? -- show the error dialog...
380                    return false;
381        }
382        if (action == "MASTER") {
383                // merge master into ours..
384                        try {
385                        string[] cmd = { "merge",  "master" };
386                        this.git( cmd );
387                        var notification = new Notify.Notification(
388                                        "Merged code from master to %s".printf(this.currentBranch.name),
389                                        "",
390                                         "dialog-information"
391                                        
392                                );
393                                notification.set_timeout(5);
394                                notification.show();   
395                       
396                        return true;
397                        } catch (Error e) {
398                        GitMonitor.gitmonitor.pauseError(e.message);
399                        return false;
400                    }
401            }
402        if (action == "EXIT") {
403                        try {
404                        var oldbranch  = this.currentBranch.name;
405                          this.setActiveTicket(null, "master");
406                        this.loadBranches();
407                        var notification = new Notify.Notification(
408                                        "Left branch %s".printf(oldbranch),
409                                        "",
410                                         "dialog-information"
411                                        
412                                );
413                                notification.set_timeout(5);
414                                notification.show();   
415                        
416                        return true;
417                    } catch (Error e) {
418                        GitMonitor.gitmonitor.pauseError(e.message);
419
420                        return false;                   
421                    }
422                    // error~?? -- show the error dialog...
423
424        }
425        return false;
426     }
427         
428     public void loadActiveTicket()
429     {
430         this.activeTicket = null;
431                 var ticket_id = this.get_config("ticket");
432         
433         if (ticket_id.length < 1) {
434                 return;
435                 }
436                 this.activeTicket = RooTicket.singleton().getById(ticket_id.strip());
437         
438         
439     }
440     
441     
442     
443     public bool setActiveTicket(RooTicket? ticket, string branchname)
444     {
445         this.set_config("ticket", "");
446         if (!this.createBranchNamed(branchname)) {
447                 return false;
448                 }
449                 this.set_config("ticket", ticket == null ? "": ticket.id);
450         this.activeTicket = ticket;
451         return true;
452     }
453     
454     public bool createBranchNamed(string branchname)
455     {   
456                 
457
458                      if (this.branches.has_key(branchname)) {
459                         this.switchToExistingBranchNamed(branchname);
460                     
461                     } else {
462                                  this.createNewBranchNamed(branchname); 
463                             
464                     }
465                        var notification = new Notify.Notification(
466                        "Changed to branch %s".printf(branchname),
467                        "",
468                         "dialog-information"
469                        
470                );
471
472                notification.set_timeout(5);
473                notification.show();   
474        
475          
476          this.loadBranches(); // update branch list...
477          //GitMonitor.gitmonitor.runQueue(); // no point - we have hidden the queue..
478          return true;
479     }
480      bool switchToExistingBranchNamed(string branchname)
481      {
482                 var stash = false;
483                                          // this is where it get's tricky...
484                 string files = "";
485                 try {                   
486                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
487                                 files = this.git(cmd);
488                                 stash = files.length> 1 ;
489                                 
490                                 
491                                 cmd = { "stash" };                      
492                                 if (stash) { this.git(cmd); }
493                                 
494                                 this.pull();
495                                 
496                                 cmd = { "checkout", branchname  };
497                                 this.git(cmd);
498                   } catch(Error e) {
499                                 GitMonitor.gitmonitor.pauseError(e.message);
500                                 return false;           
501                   }
502                 try {
503                    if (branchname != "master") {
504                        string[] cmd = { "merge", "master"  };
505                             this.git(cmd);
506                             this.push();
507                        
508                     }
509                     
510                 } catch(Error e) {
511                     string[] cmd = { "checkout", "master"  };
512                     this.git(cmd);
513                         GitMonitor.gitmonitor.pauseError(
514                                 "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(
515                                         branchname)
516                                  + e.message
517                         );
518                         return false;           
519                  
520                 }
521                 try {                                   
522                     string[]  cmd = { "stash", "pop"  };
523                     if (stash) { 
524                         this.git(cmd); 
525                         var fl = files.split("\n");
526                         cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
527                         foreach(var f in fl) {
528                                 if (f.length < 1) continue;
529                                 cmd += f;
530                         }
531                         this.git(cmd);                              
532                 }
533              
534
535                    
536                 } catch(Error ee) {
537                         GitMonitor.gitmonitor.pauseError(ee.message);
538                         return false;           
539                 }
540        this.push();
541        return true;                             
542                  
543      }
544     
545     
546     
547      bool createNewBranchNamed(string branchname)
548      {
549                 var stash = false;
550                  try {                                  
551                                 string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
552                                 var files = this.git(cmd);
553                                 stash = files.length> 1 ;
554                         
555                          cmd = { "checkout", "-b" , branchname  };
556                         this.git(cmd);
557
558                cmd = { "push", "-u" , "origin" ,"HEAD"  };
559                         this.git(cmd);
560                                 if (stash) { 
561
562                                 var fl = files.split("\n");
563                                 cmd = { "commit", "-m" , "Changed " + string.joinv("",fl) };
564                                 foreach(var f in fl) {
565                                         if (f.length < 1) continue;
566                                         cmd += f;
567                                 }
568                                 this.git(cmd);  
569                                 this.push();                        
570                         }
571
572              
573                 } catch(Error ee) {
574                                 GitMonitor.gitmonitor.pauseError(ee.message);
575                                 return false;           
576                         }
577                         return true;
578      
579      }
580     
581     
582     
583     /**
584      * add:
585      * add files to track.
586      *
587      * @argument {Array} files the files to add.
588      */
589     public string add ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
590     {
591         // should really find out if these are untracked files each..
592         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
593         // not sure if that is how git works.. but just be certian.
594         var ret = "";
595         for (var i = 0; i < files.size;i++) {
596             var f = files.get(i).vname;
597             try {
598                 string[] cmd = { "add",    f  };
599                 this.git( cmd );
600             } catch (Error e) {
601                 ret += e.message  + "\n";
602             }        
603
604         }
605         return ret;
606     }
607         
608     public bool is_ignore(string fname) throws Error, SpawnError
609     {
610                 if (fname == ".gitignore") {
611                         this.ignore_files.clear();
612                 }
613                 
614                 if (this.ignore_files.has_key(fname)) {
615                         return this.ignore_files.get(fname);
616                 }
617                 
618                 try {
619                         var ret = this.git( { "check-ignore" , fname } );
620                         this.ignore_files.set(fname, ret.length >  0);
621                         return ret.length > 0;
622                 } catch (SpawnError e) {
623                         this.ignore_files.set(fname, false);
624                         return false;
625                 }
626                  
627     } 
628     
629     
630       /**
631      * remove:
632      * remove files to track.
633      *
634      * @argument {Array} files the files to add.
635      */
636     public string remove  ( Gee.ArrayList<GitMonitorQueue> files ) throws Error, SpawnError
637     {
638         // this may fail if files do not exist..
639         // should really find out if these are untracked files each..
640         // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
641         // not sure if that is how git works.. but just be certian.
642         var ret = "";
643
644         for (var i = 0; i < files.size;i++) {
645             var f = files.get(i).vname;
646             try {
647                 string[] cmd = { "rm",  "-f" ,  f  };
648                 this.git( cmd );
649             } catch (Error e) {
650                 ret += e.message  + "\n";
651             }        
652         }
653
654         return ret;
655
656     }
657     
658     
659     /**
660      * commit:
661      * perform a commit.
662      *
663      * @argument {Object} cfg commit configuration
664      * 
665      * @property {String} name (optional)
666      * @property {String} email (optional)
667      * @property {String} changed (date) (optional)
668      * @property {String} reason (optional)
669      * @property {Array} files - the files that have changed. 
670      * 
671      */
672      
673     public string commit ( string message, Gee.ArrayList<GitMonitorQueue> files  ) throws Error, SpawnError
674     {
675         
676
677         /*
678         var env = [];
679
680         if (typeof(cfg.name) != 'undefined') {
681             args.push( {
682                 'author' : cfg.name + ' <' + cfg.email + '>'
683             });
684             env.push(
685                 "GIT_COMMITTER_NAME" + cfg.name,
686                 "GIT_COMMITTER_EMAIL" + cfg.email
687             );
688         }
689
690         if (typeof(cfg.changed) != 'undefined') {
691             env.push("GIT_AUTHOR_DATE= " + cfg.changed )
692             
693         }
694         */
695         string[] args = { "commit", "-m" };
696         args +=  (message.length > 0  ? message : "Changed" );
697         for (var i = 0; i< files.size ; i++ ) {
698             args += files.get(i).vname; // full path?
699         }
700          
701         return this.git(args);
702     }
703     
704     /**
705      * pull:
706      * Fetch and merge remote repo changes into current branch..
707      *
708      * At present we just need this to update the current working branch..
709      * -- maybe later it will have a few options and do more stuff..
710      *
711      */
712     public string pull () throws Error, SpawnError
713     {
714         // should probably hand error conditions better... 
715         string[] cmd = { "pull" , "--no-edit" };
716         return this.git( cmd );
717
718         
719     }
720     
721     public delegate void GitAsyncCallback (GitRepo repo, int err, string str);
722     public void pull_async(GitAsyncCallback cb) 
723     {
724     
725          string[] cmd = { "pull" , "--no-edit" };
726          this.git_async( cmd , cb);
727          
728     
729     }
730     
731     /**
732      * push:
733      * Send local changes to remote repo(s)
734      *
735      * At present we just need this to push the current branch.
736      * -- maybe later it will have a few options and do more stuff..
737      *
738      */
739     public string push () throws Error, SpawnError
740     {
741         // should 
742         return this.git({ "push"  });
743         
744     }
745     
746     
747     
748      /**
749      * git:
750      * The meaty part.. run spawn.. with git..
751      *
752      *
753      */
754     
755     public string git(string[] args_in ) throws Error, SpawnError
756     {
757         // convert arguments.
758         
759         string[]  args = { "git" };
760         //args +=  "--git-dir";
761         //args +=  this.gitdir;
762         args +=  "--no-pager";
763  
764  
765         //if (this.gitdir != this.repopath) {
766         //    args +=   "--work-tree";
767          //   args += this.repopath; 
768         //}
769         for (var i = 0; i < args_in.length;i++) {
770             args += args_in[i];
771         }            
772
773         //this.lastCmd = args.join(" ");
774         //if(this.debug) {
775             GLib.debug( "CWD=%s",  this.git_working_dir ); 
776             GLib.debug( "cmd: %s", string.joinv (" ", args)); 
777         //}
778
779         string[]   env = {};
780         string  home = "HOME=" + Environment.get_home_dir() ;
781         env +=  home ;
782         // do not need to set gitpath..
783         //if (File.exists(this.repo + '/.git/config')) {
784             //env.push("GITPATH=" + this.repo );
785         //}
786           
787         var cfg = new SpawnConfig(this.git_working_dir , args , env);
788         //cfg.debug = true;
789
790        // may throw error...
791         var sp = new Spawn(cfg);
792       
793              //GLib.debug( "GOT result: %d" , sp.result);
794       
795         // diff output is a bit big..
796                 if (args_in[0] != "diff") {
797                 GLib.debug( "GOT: %s" , sp.output);
798         }
799         // parse output for some commands ?
800         return sp.output;
801     }
802         
803    unowned GitAsyncCallback git_async_on_callback;
804         public void  git_async( string[] args_in,   GitAsyncCallback cb ) throws Error, SpawnError
805     {
806         // convert arguments.
807        this.git_async_on_callback = cb;
808         string[]  args = { "git" };
809         //args +=  "--git-dir";
810         //args +=  this.gitdir;
811         args +=  "--no-pager";
812  
813  
814         //if (this.gitdir != this.repopath) {
815         //    args +=   "--work-tree";
816          //   args += this.repopath; 
817         //}
818         for (var i = 0; i < args_in.length;i++) {
819             args += args_in[i];
820         }            
821
822         //this.lastCmd = args.join(" ");
823         //if(this.debug) {
824             GLib.debug( "CWD=%s",  this.git_working_dir ); 
825             //print( "cmd: %s\n", string.joinv (" ", args)); 
826         //}
827
828         string[]   env = {};
829         string  home = "HOME=" + Environment.get_home_dir() ;
830         env +=  home ;
831         // do not need to set gitpath..
832         //if (File.exists(this.repo + '/.git/config')) {
833             //env.push("GITPATH=" + this.repo );
834         //}
835         
836
837         var cfg = new SpawnConfig(this.git_working_dir , args , env);
838         cfg.async = true;
839        
840
841        // may throw error...
842         var sp = new Spawn(cfg);
843                 //sp.ref();
844         //this.ref();
845         sp.run(this.git_async_on_complete); 
846          
847     }
848     
849     void git_async_on_complete(int err, string output)
850     {
851                 GLib.debug("GOT %d : %s", err, output);
852                 this.git_async_on_callback(this, err, output);
853 //              this.unref();   
854         //      sp.unref();             
855     
856     
857     }
858     
859  
860          
861     
862  
863     public void update_async(GitAsyncCallback cb) 
864     {
865          string[] cmd = { "fetch" , "--all" };
866          this.git_async( cmd , cb);
867          
868     }
869     
870     
871     static uint update_all_total = 0;
872     static string update_all_after = "";
873      
874     public static void updateAll(string after)
875     {
876                 update_all_after = after;
877                 var tr =  GitRepo.singleton().cache;
878             
879         
880        update_all_total = tr.size;
881        foreach(var repo  in tr.values) {
882                 if (!repo.is_managed()) {
883                         update_all_total--;                     
884                         continue;
885                 }
886            repo.update_async(updateAllCallback); 
887         } 
888                 GLib.debug("calls total = %d", (int) update_all_total);
889     }
890     public static void  updateAllCallback(GitRepo repo, int err, string res)
891     {
892         repo.loadBranches();
893         repo.loadStatus();
894         
895         update_all_total--;
896                 GLib.debug("calls remaining = %d", (int)update_all_total);      
897         if (update_all_total > 0 ) {
898
899                 return;
900                 }
901                 switch (update_all_after) {
902                         case "show_clones":
903                                 Clones.singleton().show();
904                                 break;
905                         default:
906                                 break;
907                 }
908                 return;
909     }
910     
911     
912     
913 }