Zac Medico wrote: > Hello All, > > The use of global scope code should be minimized in order to prevent > confusion and thereby make code more understandable and maintainable. > After some analysis of emerge's global scope code, I am confident that > all of it can be refactored quite easily, with no regressions or changes > in functionality (reorganization only). > > In order to accomplish this goal, I have categorized the global scope > variables by which parts of code depend on them. The variables are > listed in the following table, in the order that they occur in the > source code: > > Variable Name Dependency > ------------------------------------------------------- > spinner search.execute(),depgraph.create() > merged unused > params unused > actions local > options local > shortmapping local > myaction global > myopts global > myfiles global > edebug global > verbosity global > tmpcmdline local > cmdline local > CLEAN_DELAY unmerge() > EMERGE_WARNING_DELAY global > myparams depgraph.create(),depgraph.xcreate() > add local > sub local > > Variables within a given category can be dealt with in a similar > manner. For example, variables with "local" dependency should be > enclosed within a function or method along with the code that depends on > them. Variables with "global" dependency can either remain as global > variables or become instance variables of an object. > > Based on this analysis, I believe that I can quickly create an emerge > refactorization patch for portage-2.1 with no regressions or changes in > functionality (reorganization only). If all (or some) of the portage > developers agree that it is a good idea then I would be happy to create > a patch for all to scrutinize. :-) > > Zac > Okay folks, I've done quite a bit of cleanup and I am pleased with the result. I have created a new class called emerge_cmd that encapsulates all of the previously global variables. All of the global scope code has been moved to the bottom so start down there if you want to see how it works. The new class is also at the bottom. I had to move so many things around that the diff against portage-2.1.0_alpha20050718 is practically useless. Therefore, I have attached the entire emerge source file. Let me emphasize again that it should be 100% equivalent in functionality to the emerge from portage-2.1.0_alpha20050718. If I have overlooked anything during the refactoring it should be easy to fix. I have done some minimal testing and it seems to work well. I would appreciate any feedback. Thanks, Zac