Version control for FoxPro source code
If you want to place your FoxPro source code files in a Source Code Repository of some sort, you usually need to generate text file versions of your table-based FoxPro files like SCX, VCX, and FRX. These text versions of the binary FoxPro files are necessary for the versioning features of code repository tools work properly. FoxPro is unique in having binary source code files in a projects, whereas most other languages use raw text for all of their code files.
We’ve long had a tool to generate these text versions of our Forms, Classlibs, and Reports (see the updated SCCText app here: http://vfpx.codeplex.com/wikipage?title=Alternate%20SCCText). However, using this file is still a tedious way to get your SCC files generated if you try to do it by hand. Sure, the FoxPro IDE can hook into this app if you set it all up and are working on one of the source control systems that VFP was natively designed to work with. But VFP is getting kind of old, and there are many options that exist today the VFP simply cannot work with out of the box.
I recently wanted to use the Mercurial source control repository to manage the development of my GoFish 4 Code Search project. I set up a free project hosting account on BitBucket.org and installed the Tortiose Hg software on my Windows machine, and then I was able to commit code changes to this magic repo in the sky and share it with the whole world.
Sadly, VFP does not have support for this newer Distributed Version Control System, so I can’t “hook up” FoxPro to use SCCText and then “check in” my code in the VFP way.
VFP Version Control with Mercurial
Rick Borup presented a session at SWFox 2011 on using Mercurial version control with FoxPro source code. You can get a free PDF copy of the whitepaper here:
The CreateSCCText Class
To automate creation of the SCC files, I have created a custom class with a method that recursively calls SCCText for each file in a VFP Project. It’s a snap to use this simple class in a PRG and run it each time right before you commit changes up to your repo. You can also create a ProjectHook class and include a call this class in the AfterBuild(). It will then automatically create updated SCC files every time you build your VFP project.
It’s DateTime aware for each file, so it will only re-generate the SCC files if the date of the VFP source file is newer than the existing SCC file. This way, when you post your commits, you’re only pushing up SCC files that have changed since the last push. There is also support for skipping over certain files that you may not want to process with SCCText.
I owe a lot of credit to Paul for getting me started on that SCCTextGeneration stuff. He gave me some helpful code in a UT message when I asked a question about running a process on every file in a Project. He basically gave me the code to do it in his reply (see message# 1507894). I just bundled it all up in a class/module and made some noise about it.
You can get the source code for this simple class here: http://codepaste.net/9yy1gm
Other sources for getting and using SccTextX
*UPDATE* Here’s newer way that I’ve begun to automate the generation of text files from the FoxPro binaries – *before each commit*, I run this code below which calls a Thor Procedure to generate the text files from the pass project (I wrote this Thor Proc and passed it on to Jim and he included it in Thor.) You can get Thor Tool Manager for FoxPro from the VFPx site. It adds lots of great developer tools to the Visual FoxPro IDE.
*======== Generate SCC files =================================================================
llGenereateSccFiles = ExecScript(_Screen.cThorDispatcher, 'Thor_Proc_GenerateSccFilesOnProject', lcProject)
? ' Error encountered during call to [Thor_Proc_GenerateSccFilesOnProject]'
Basically, you pass in your project path, and it generates the text files by calling a slightly modified-for-Thor verison of SccTextX that we’ve included with Thor.