For programmers on big projects, a version control system for managing source code is vital, but working on files in a large project from one of these programs' command-line interfaces is cumbersome. Worse, the results of the commands lack highlighting to show the differences between files and revisions. ViewVC is a handy browser-based code viewer that allows users to browse a source code tree managed by either CVS or Subversion, look at changes, compare revisions at the file or line level, and perform other operations -- just about anything except allow users to check out or commit files.
You can install ViewVC from a repository in Ubuntu, Gentoo, Fedora, and other distributions. If there is not a package available for your distro you can download the source code. You'll also need to install Apache2, Subversion or CVS, lib-apache2-mod-python, GNU diff, MySQL and for those using CVS, CvsGraph.
In Ubuntu, ViewVC is installed in /usr/lib/viewvc/ and the main executable is in /usr/lib/cgi-bin/. In order to make Apache recognize ViewVC, you must add the following line to /etc/apache2/httpd.conf:
You must also edit /etc/viewvc/viewvc.conf and change the following lines by adding the highlighted information:
svn_roots = svnroot: /path/to/svn/repository #for Subversion
cvs_roots = cvs: /home/cvsroot #for CVS
address = < a href="mailto:email@example.com" > youremail at yourservice dot com < /a >
Note: svnroot: and cvs: in the above lines will be the repository names as far as ViewVC is concerned, and they can be whatever you want. Unless you are going to use both Subversion and CVS, comment out the line for the service that you are not using with a #.
Finally, run the command
sudo /etc/init.d/apache2 restart to restart Apache. You should then be ready to browse through your source code. Note: Due to differences in terminology, I will be referring to tag/branches from CVS as revisions for the sake of brevity.
Browsing the repo
To begin browsing the repo that you configured above, open a Web browser and type enter http://localhost/viewvc/viewvc.cgi. You will see a very basic page that contains one of two Web links: cvs and svnroot. Click on the service you are using to display a summary of your project. The revision information will reflect what Subversion or CVS reports, including the age, author, and last log entry. A link that allows you download the entire project appears on every page that has a directory on it, along with a link to download source code that is just in the current directory. At the bottom of every page is a link for help on the repository Web server. At the top you'll see a link to the project path that you are viewing and a dropdown box that allows you to switch between repositories -- even when one repository is managed by CVS and another by Subversion.
Click on the project link. Once you have opened the page that has the repository, the links will follow the directory structure of the versioning system that you are using. For instance, Subversion generally has a directory called "trunk" that comes before the project directory. Once you're at the root directory of your project, you should see information about files, directories, revision numbers, ages, authors, and log entries that reflect the way Subversion and CVS handle the files in question. If you click on a file that shows several revisions, you'll bring up a log of its revisions. You can then view, download, annotate, or compare revisions. Click on the view link to see a complete view of the file at a given revision, or Download to download it. Annotate will show the entire file along with the changes made at each revision. Select For Diffs will cause the page to refresh with the selected revision number in the first field at the bottom of the page. The options for difference highlighting are Colored Diff, which shows only the snippets of code that have changed in any of several styles; Long Colored Diff, which shows the entire file with changes highlighted; Unidiff, which shows a listing of the changes in a Patch-compatible format; Context Diff, which shows another patch file, this time with context information shown; and Side by Side, which shows the revisions side by side.
In the colored diff selections you will see numbered links that show changes in the revisions, along with the author who made the changes and links to each revision. There are also links to the Parent Directory, the Revision Log for this file, and a link that will allow the user to download a Patch file for this particular revision.
On the file's revision log page, another link lets users jump directly to a colored diff page for each revision. The link shows a description of what the shortcut will show, and whether it is one of the previous revisions or the revision that you "select[ed] for diffs." Also on this page is a field that allow the user to select a revision to make it "sticky" so that this and other pages that show revisions, such as the index of the project, will only show up to the revision selected. This is useful for working with views that default to a particular revision.
If you are engaged in a project with lots of revisions, the command-line tools in both Subversion or CVS can be annoying and time-consuming to work with. ViewVC streamlines the process of source code browsing and highlighting. While not a replacement for command-line utilities, the ability to browse source code repositories is a real boon to developers, team leads, and managers. ViewVC provides a fast and easy way to browse source code and differences between revisions.