Flylib.com

Books Software

 
 
 

Section 4.6. Viewing the Logs


4.6. Viewing the Logs

After you have multiple revisions committed to the repository, you will likely find a time when you want to review the history of changes you have made. This can be done using the svn log command, which displays the commit logs for a file. If multiple files are given, Subversion aggregates the logs for all of the files into a single log output, showing the log entries for each revision where at least one of the listed files changed. If a directory is given, SVN will output the log information for not only the given directory, but also all files and subdirectories contained within the directory given.

You can view the log for the hello.c file by running the following.

$ svn log hello.c
----------------------------------------------------------------
r2  bill  2004-07-11 04:45:12 -0500 (Sun, 11 Jul 2004)  1 line

Changed program output
----------------------------------------------------------------
r1  bill  2004-07-08 16:28:57 -0500 (Thu, 08 Jul 2004)  1 line

Initial import
----------------------------------------------------------------

Looking at the output, you can see that it shows both of the revisions that you have committed, along with the name of the user who made the commit, the time of the commit, the total number of lines that were changed in files that were part of the commit (in this case, just one), and the log message that you gave for each commit.


4.7. Creating a Tag

It's hard to improve upon perfection , so you decide that it's time to release your Hello World application so that others can bask in its glory . You would, however, like to be able to continue work on version 2.0 of Hello World (with many new features) after you release version 1.0. To ensure that you always have access to exactly what you released as version 1.0 (in case, for example, you later find a bug that you want to fix), it would be handy to mark the revision of the repository that made up the version 1.0 release. You could do this by writing down the revision number somewhere, but the easier (and more reliable) way to keep track of the version 1.0 release is to create a tag.

Subversion has no explicit concept of a "tag." Instead, it simply uses lightweight copies of the files being tagged. So, to create a tag, you just have to use the svn copy command to create a copy of the files included in the release in the tags directory that you created when you made the initial repository. In order to avoid the expense of actually making a copy of the files in the directory (as opposed to just marking them as copied ), and because you never checked out the tags directory into your working copy, it is best to perform the copy entirely in the repository, by running the following command.

[View full width]

[View full width]

$ svn copy --message "Tagged version 1.0 release" file:///home/bill/my_repository/trunk/ file:///home/bill/my_repository/tags/version_1_0/ Committed revision 3.

This performs the copy inside the repository immediately, and creates a new revision. You can see that the copy occurred by using the svn list command to see the contents of the repository.

$ svn list file:///home/bill/my_repository/tags
version_1_0/
$ svn list file:///home/bill/my_repository/tags/version_1_0
Makefile
hello.c


4.8. Creating a Branch

You should have tags pretty well down at this point, so let's take a look at branches. Say, for example, that your boss isn't yet quite as enlightened as you are, and decides you need to release a version of Hello World that touts that other version control system. Because you know he's heading down a dead-end path , though, you don't want to stop development on your already excellent version of Hello World. The solution is to create a branch of the project, which will allow you to take the project in a different direction, while maintaining the current development path in parallel.

Branches in Subversion are just like tags, copies of the original repository part they refer to. Therefore, you make them exactly the same way; only in this case, you will want to copy the files into the branches directory, instead of the tags directory.

[View full width]

[View full width]

$ svn copy --message "Created a branch of the project to make the boss happy" file:///home /bill/my_repository/trunk/ file:///home/bill/my_repository/branches/cvs_version Committed revision 4.

After you have created the branch, you'll need to put it into a working copy so that you can make changes to it. You could check out the branch (using svn checkout ) into a new working copy. In fact, that will work just fine. There's a better solution, though. Instead of checking out a new working copy, you can switch your current working copy to point to the branch, instead of the /trunk directory that it points to now. To do this, you need to use the svn switch command. To switch your working copy to the branch, run the following command line.

$ svn switch file:///home/bill/my_repository/branches/cvs_version
Updated to revision 4.

The files in your working copy now point to the branches/cvs_version/ directory, and any changes that you commit will be applied to that directory. In this particular case, running svn switch didn't make any changes to the files in your working copy, because the branch and your trunk are identical. Had they been different, Subversion would have updated all of your working copy files to reflect the cvs_version/ directory that you switched to.

You can look at what directory you are currently switched to by running svn info . For instance, the following command line will show you that your current working copy is switched to the cvs_version branch (look at the URL line).

$ svn info
Path: .
URL: file:///home/bill/my_repository/branches/cvs_version
Repository UUID: 5380c965-27ea-0310-9e69-9d7dd738c2c1
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: bill
Last Changed Rev: 4
Last Changed Date: 2004-12-01 00:46:13 -0500 (Wed, 01 Dec 2004)

Now that you have switched your working copy to point to the branch, you'd probably like to make some changes to the branch. For instance, to make your boss happy, you might change my_repository/branches/cvs_version/hello.c to look like this:

#include <stdio.h>

int main(int argc, char** argv)
{
    printf("CVS is the best!!\n"); // Ugh! The boss made me do it

    return 0;
}

Then, when you commit those changes, they will be applied to the copied version of the file, but the original file will remain unaffected, as you can see in the log outputs here.

$ svn commit --message "Changed program output to praise CVS"
Sending        hello.c
Transmitting file data .
Committed revision 5.

After the commit, the branch shows the committed change.

$ svn log file:///home/bill/my_repository/branches/cvs_version/hello.c
 ----------------------------------------------------------------
r5  bill  2004-07-12 23:32:11 -0500 (Mon, 12 Jul 2004)  1 line

Changed program output to praise CVS
----------------------------------------------------------------
r4  bill  2004-07-12 22:47:11 -0500 (Mon, 12 Jul 2004)  1 line

Created a branch of the project to make the boss happy
----------------------------------------------------------------
r2  bill  2004-07-11 04:45:12 -0500 (Sun, 11 Jul 2004)  1 line

Changed program output
----------------------------------------------------------------
r1  bill  2004-07-08 16:28:57 -0500 (Thu, 08 Jul 2004)  1 line

Initial import
----------------------------------------------------------------

But the the original hello.c file, still only shows the first two revisions.

$ svn log file:///home/bill/my_repository/trunk/hello.c
----------------------------------------------------------------
r2  bill  2004-07-11 04:45:12 -0500 (Sun, 11 Jul 2004)  1 line

Changed program output
----------------------------------------------------------------
r1  bill  2004-07-08 16:28:57 -0500 (Thu, 08 Jul 2004)  1 line

Initial import
----------------------------------------------------------------

Of course, now that you're done modifying the branch, it's a good idea to switch your working copy back to the trunk. If you don't make the switch as soon as you're done with the branch, it can be all too easy to forget and accidentally apply modifications to the wrong place.

$ svn switch file:///home/bill/my_repository/trunk/
U hello.c
Updated to revision 5.

As you can see, Subversion updates your hello.c file so that it represents the trunk version, rather than your modified branch version of the file.