Saturday, October 13, 2012

Repositories - Back up ALL the files!

Repository? What is that and why is this related to game engines? Well it's useful for game engines, more specifically programming in general and has a variety of other uses too. A repository is sort of like a back up system for your code (or other files). If you have a repository for your code and you make a really terrible mistake later on, you have the ability to revert to an older version and restore code! It has a lot of other things too but let's seperate this blog post neatly into some sections first.


Backing Up


Repositories have the ability to back up your files and revert to older versions. You would set up a folder of your choice as a repository and from there the program will let you do a variety of things (program of your choice, I use mercurial and tortoise HG, but more on that later). Essentially I can choose which files I would like to include to back up, so even if there are a ton of files in the folder I chose, I can select each one that I want and exclude the ones I don't want. There is even a file called .hgignore that allows you to ignore certain types of files so that they will never appear when choosing to select what to back up.

From there (for mercurial) all you have to do is add a comment that says something about what you're doing so, something like "Just created this program that adds numbers" or "[ADD] Added the ability to multiply to program". And then you just click commit. This will add a new "revision" which can be reverted back to in the future. You can add new revisions whenever you want to add a new file or change a file.

It's also possible to branch off as well, which means you're making another version that might be significantly different. From there you can multiple branches, each changing different things and even merge them later. So you could edit one file A, and one file B in a different revision. And later on do a merge that allows you to have both the changes. There can be conflicts though so you will have to use some provided tools to resolve those.



Online Functionality


You're aren't limited to only backing up offline, you can also back up online. You can send your repository to online repositories in sites such as bitbucket. You will be able to store it online, make it public or private and allow certain users to see it. That means since you can upload it, you can also download it to, or rather "clone" the repository if you have permission. This allows users to clone online and transfer to others with relative ease.

The coolest feature involves the use of having multiple people all with permission to upload to the same repository. This allows multiple users to update from that repository and work on code simultaneously. This allows an entire group of programmers to collaborate much easier as there are back up versions, code easily accesible online and updated to the most recent version. Merging code is also easier than normal as it even highlights what changes there are between version too! This is a really useful tool for the GDW groups in our school.


How to set up Mercurial


Setting up mercurial is not too difficult. You need mercurial itself and then another program to properly use repositories.

First download mercurial
http://mercurial.selenic.com/

Then download Tortoise HG, this handy application allows you to interact with bitbucket.org for creating repositories, pushing to them and cloning them.
http://tortoisehg.bitbucket.org/

From there all you need is a bitbucket account to be created.
https://bitbucket.org/

With a bitbucket account, you can create repositories online and be able to share them with anyone you want. You can choose who gets persmission and be able to push and clone from repositories.


How to set up a simple repository


Now once you have everything installed, here are some tips on how to get started with a simple repository.

Offline portion


First right click a folder you would like to make as a repository. Go to Tortoise HG -> Create Repository


After you've done that, right click on the folder again. Go to Hg Workbench.



Once you're in tortoise hg, make sure you're in the correct folder. In the bottom left you will see a list of files.  Select the ones you want, right click and press "Add".


This will add them to the repository. All you have to do is add in a message like on the right side and click commit (Its further right, in the program).

Online 


Go into your bitbucket account and go under repositories. Go to Create repository.


It will then give you a list of options. Make sure to have Repository Type : Mercurial. 
If you're using code, select the appropriate one under language.



Once you're created the repository online, go back into tortoise HG. Find the recycle sign on the upper task bar. Once you do that you will go to this screen.

Click on the button I have highlighted, the cylinder pointing to a cylinder farther away. This will allow you to "push" to an online repository.

All you need to do from there is get the link of the repository itself and type it in. They will ask for your username and password.



Once it says you've successfully pushed, to test if you did it right make a new folder. Right click it and go to Tortoise Hg-> Clone. This will make a clone of your online repository.


From there, put the source as the linked repository you want and then press clone. It will again ask for your username and password (This is to check if you have the rights to clone this repository).


And there we have it! A cloned repository with everything we checked off, available for us to store online. Be careful about putting files too big. If you're doing programming only included files that are absolutely necessary.

Anyways I hope this was interesting to anyone who read it and that repositories might help them!










No comments:

Post a Comment