Personal Source Control
If you’re a developer like me, chances are that in addition to the programming you do at work, you probably also have some personal projects that you work on at home as well. Whether you are consulting on the side, or just want to write your own applications, it may make sense for you to have a source control server of your own. There are many benefits to having a home source control system, including:
- Having a backup of your source code
- Access to revision history and previous versions
- Single repository for source code across multiple machines
These are all very good things. It’s very reassuring to know that your source code will still exist on the source control server if your hard drive should crash and burn. It’s also nice to be able to revert to previous versions of your code should you irreparably break something. And lastly being able to easily synchronize source between multiple machines, such as your desktop and laptop, is very handy.
Why Perforce?
You can of course use any source control system you are most comfortable with. I used Perforce quite a bit at National Instruments, and it makes sense to me. I like the ability to have multiple changesets at once. I like that I have a consistent, semi-permanent mapping from my hard drive to the source depot. And most of all, I like that I can install it for free.
I also previously installed an SVN server, and was using TortoiseSVN for a while to check in code on my home network. This kinda sorta works, but… I don’t really like it. It’s hard to explain, but I am so familiar with the way that Perforce works that using TortoiseSVN is a pain. For example, it doesn’t seem like there is any permanent mapping between the source server and your hard drive. You can check out a folder to anywhere, and update a folder from anywhere, but it’s really easy to screw it up. And as for checking out code, well, it seems like you don’t check it out so much as you download it locally, edit it, and then try to commit your changes. I’m sure there are people out there that use it and love it, but I can’t wrap my head around the way it’s supposed to work, and I’d rather use a paradigm much more familiar to me like the one Perforce uses.
Installing P4D
You can download the Perforce Server, called P4D, from Perforce Downloads. I chose Windows for 32-bit Intel (x86) for my machine. Install it. You can pretty much keep all of the default options.
Once it’s installed, you can take a look at your system Services, and you should see that the Perforce service is Started and is Automatic.
Create a New User and a Depot
Use the command p4 user -f from a command prompt in the Perforce directory to create a new user. Your text editor will open a temporary file used to configure your user’s options. You can stick to simply editing the full name and adding a password.
Use the command p4 depot to create a new source depot. You will probably already have a default depot called “depot”, but I added a new one because I want it to be called Root, and I wanted it to be located in D:\Root\ on my server. As before, when you execute this command a temporary document will open in your text editor. Most likely you will just want to change the Map parameter.
Fix Your Firewall
In order to allow connections from other machines on your network, you need to tell your Windows Home Server to allow connections on port 1666, because that’s the port that the Perforce server uses by default. Open up your Windows Firewall Settings, select the Exceptions tab, and click on the Add Port button. Type in “Perforce” and “1666” respectively. Now your Perforce client should be able to connect to the server.
Installing P4V
Now you’re ready to install the Perforce Visual Client, or P4V, on your desktop or laptop. Again, you can download the client from Perforce Downloads. Go ahead and install. Again, you can leave most of the options as default, but you will want to change the server name to match the name of your Windows Home Server.
Go ahead and run the Connection Setup Wizard. You will probably have to manually choose your server name, and to login with the username and password you created on the server. Don’t bother copying files from the server to your workspace, as there are no files in your depot yet.
Once that’s done, your P4V window should look approximately like this:
Creating a Client Workspace
Perforce allows each user to have a set of client workspaces, which is essentially just a way of mapping the depot folders you are interested in to a local drive on your machine. Create a new workspace like so:
Enter a name for your new workspace; generally people use some combination of their username and machine name.
Now, you have to define your client spec. The most important two fields are the Root and the View. Here I set my root to D:/Perforce/Artemis_Hexar/. All of my source files will be under this directory. Next I set my View to a single line mapping of //Root/… //Artemis_Hexar/Root/… The ellipses are a symbol that means all subfolders and files. So here I’m just saying that everything under the Root depot should go under the clientspec, in the Root directory. You can do some interesting things with the View, including exclusions and inclusions, but it’s probably not necessary for our purposes here.
Now your client probably looks something like this:
Add Files to Source Control
Lastly, it’s time to add some files to source control. Take some files that you want to add, and copy them into your clientspec root. For me that means D:\Perforce\Artemis_Hexar\Root\. Next, click on the Workspace View tab so that you can see your local disk tree instead of the depot tree. Right click on the files/folders you want to add and choose “Mark for Add…” This will add them to the default changelist.
Lastly, right-click on the default changelist and submit. You should write a comment on the reason for the change, and make sure you really do want to submit all of the files in that changelist. Now, if you go back to the Depot view, you can see that your files have been added to the depot, and you can check them out for editing, deletion, or rename.
Conclusion
So that’s it! Congratulations, now your personal projects have professional source control. Check in some code, and celebrate with the food/beverage of your choice.
Thanks Hexar! I would have assumed that this would be difficult, but I had it all done in thirty minutes with your tutorial.
LikeLike
Yeah no problem! I thought it would be harder to figure out as well, and actually the firewall part had me stumped for a while because I couldn't connect and didn't know why. But other than that it's not too bad =)
LikeLike
really good for biginners like me !! Thanks Hexar
LikeLike