In this lab you will familiarize yourself with the Subversion (or SVN) source control system. While many people interact with SVN using a GUI interface (often part of their development IDE), we can access SVN with command line parameters on bluenose.
All development companies use some form of source control, so becoming familiar with the basic notions of source control is useful. You won't be a master of source control after this lab, but you will have at least seen some of the basic concepts and commands. Subversion is relatively popular (as far as free software goes). A more recent source control system is called "git" while Perforce and ClearCase are two popular commercial offerings. Older source control systems include SCCS, RCS, and CVS (in case you hear about them).
In this lab you will learn how to
svn mkdir https://svn.cs.dal.ca/your_id/2132 svn checkout https://svn.cs.dal.ca/your_id/2132The rest of your lab will be done within the 2132 directory that gets created. I suggest that you make the 2132 directory that is created your main directory for your course material; you will be asked to submit assignments to the course using SVN and having them in this subdirectory will be the easiest way for you to accomplish that task.
Note that in the commands for this lab, I include my username (mcallist). Whenever you see that name, substitute in your own bluenose username.
Each time that you enter an SVN command in this lab, you will be asked for your bluenose password. Enter it. When asked if you want to store the password, answer "no" each time. While it becomes troublesome in the lab, the password isn't stored safely for now so we don't want you to store it. Tech support is working to fix this problem.
SVN helps you manage a remote directory system where you can store files. That directory system is called a repository. The repository keeps a history of all the changes that are made to its files so that you can review how the files changed and retrieve previous versions of your files. Repositories are often shared among people as a way for all the people to get access to the same set of files.
SVN uses the notion of a working copy of the repository. So, when you put files into the SVN repository, you don't edit the files directly there. Instead, you retrieve a working copy of the files, modify your working copy, and then send (or commit) the files back to the SVN repository when you are satisfied with their state. So, you generally just commit files from your working copy to the SVN repository once the files are in some kind of stable (though possibly incomplete) state. For example, when using a repository to store programs, you generally do not commit files until they compile, at the least. In most cases, you will just commit the program files after they pass your unit tests.
The make_svn script from the preparation step created a project in your personal SVN repository called SVN. It has no subprojects. Our first step is to create a subproject for this lab in your repository.
svn checkout https://svn.cs.dal.ca/mcallist/2132Notice that the checkout command uses a web address, so you can get to the machine from anywhere on the Internet. Also notice that the start of the web address is https and not http.
ls -aWhile there are no visible files, SVN created a hidden subdirectory called .svn. This directory contains all the SVN state for the directory, including the location of your repository. While you are in this directory, you don't need to specify the repository name anymore since SVN will get that information from the .svn subdirectory
mkdir lab8We will now add this directory to the SVN repository with the SVN add command:
svn add lab8 cd lab8You should see the output line
A lab8where SVN is telling you that lab8 will be added (the "A") when you next commit your changes to SVN. The lab8 subdirectory is not in your repository yet. It is just ready to go. To create the lab8 subdirectory in your repository, you must commit the add command using the SVN commit command:
svn commit -m "Creating a project for my lab 8 work"And you should see back
Adding lab8 Committed revision 2.This subdirectory is now available in your repository with the web address https://svn.cs.dal.ca/mcallist/2132/lab8
#include <stdio.h> #define UNIX_ALL_OK (0) int main( int argc, char **argv ) { int status = UNIX_ALL_OK; int i; for (i = 0; i < 10; i++) { printf ("*"); } printf ("\n"); return status; }and make sure that it compiles, leaving the a.out compile file in your directory. Create a second copy of the file as sample2.c
cp sample.c sample2.cWe will now add both files to your repository, again with the SVN add command:
svn add sample.c sample2.cwith output
A sample.c A sample2.cNotice that we can add any number of files at the same time to the repository. Are these files in the repository yet? No, since we haven't issued a commit command to send them from your working copy to your repository.
svn statusYour output should look like
? a.out A sample.c A sample2.cThe "A" for the two sample files indicates that these files are waiting to be added to the repository. The "?" at a.out indicates that SVN knows nothing about the a.out file and will do nothing with the file.
svn commit -m "Adding the first version of my sample files. Both compile but are untested."If you re-issue the SVN status command, you should now get as output
? a.outSVN doesn't report on sample.c and sample2.c since the copy in your working directory is now identical to what is in the repository.
svn delete sample2.cthat outputs
D sample2.cThe leading "D" indicates that the file is now set for deletion. Re-issue the SVN status command to get the output
? a.out D sample2.cagain, showing that SVN doesn't know about a.out and is ready to delete sample2.c. The change doesn't happen until you commit it to the repository:
svn commit -m "File sample2.c was added by mistake earlier. It was just a backup copy of sample.c"While sample2.c is no longer active in the SVN repository, we can still retrieve past copies of it later if we conclude that we shouldn't have deleted the file. Notice that the sample2.c file is no longer in our working directory.
svn checkout https://svn.cs.dal.ca/mcallist/2132/lab8You should now have a lab8 directory in your secondary window with a sample.c file in it. Make that lab8 directory your working directory in the secondary window. Notice that there is no sample2.c file in this directory. We did the SVN delete command on the file, so we don't retrieve the file when we checkout fresh copies from the repository.
? a.out M sample.cThe "M" with sample.c indicates that your working copy of the file has modifications that are not in the repository. You can view the modifications with the SVN diff command:
svn diff sample.cThe command will show you the lines where your version and the repository version of the file are different along with a few lines before and after the difference.
svn commit -m "Use a longer loop iteration"You should get a message to show that the change was sent to the repository. Re-issue the SVN diff command for the sample.c file. Does it report any differences? Why?
svn updatewith output
U sample.c Updated to revision 16.The leading "U" means that there is a more recent copy of the code in the repository than what is in the working copy of the code.
rm sample.cConfirm that the file is gone with the UNIX ls command.
! sample.cIssue the SVN update command one more time. What happens to the contents of the working directory?
printf ("I am about to start the loop\n");In sample.c of your secondary window, add a printf statement just before the return statement:
printf ("I have finished the loop\n");Now each copy of your file has a different change to sample.c. In each of the directories, use the SVN status command to confirm that the sample.c file is different from what is in the repository (look for the leading "M" tag beside the file names).
svn updatewith output
G sample.c Updated to revision 17.The "M" tag on sample.c from before has now changed to a "G". The "G" indicates that your changes and those from the repository have been automatically merged in the file. SVN was able to merge the changes since the changes in the primary and secondary windows didn't overlap.
svn update
Conflict discovered in 'sample.c'. Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options:SVN is giving you the opportunity to fix see the differences (df) or fix the problem (edit the file). If you choose to edit the file, SVN will show you the file in your default editor. Since we haven't defined that editor, let's select the postpone option. Enter p and let SVN continue with the update (if there were other files).
C sample.cwhere the leading "C" indicates that sample.c has a conflict that you need to resolve before it is sent to the repository.
svn log sample.cYou will get output to show each of the versions of the file along with the commit messages. If the message on the last commit for sample.c isn't giving you enough information, you can use the SVN diff command again to see where your file differs from what is in the repository
svn diff sample.c
svn resolved sample.cAfter issuing this command, the sample.c.mine, and sample.c.rXfiles will be removed from your working directory. You can now issue the SVN commit command to send the changes to the repository.
svn revert sample.cAfter issuing the command, look at sample.c again to notice that you now have the version of the file that precedes your latest editing.
svn update -r 5 sample.cWhat is the content of this sample.c file?
svn update -r {"2010-10-27 13:00:00"}
Add assignments 0, 1, 2, and 3 to your 2132 SVN repository, each as its own project.