BASH – Extracting Subversion Log

Subversion

Subversion Subversion (SVN) is a version control system initiated in 2000 by CollabNet Inc. It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS). Subversion is well-known in the open source community and is used on many open source projects.

Subversion was started in 2000 as an effort to write a free version control system which operated much like CVS but with fixed bugs and misfeatures in CVS. By 2001, Subversion was sufficiently developed to be capable of hosting its own source code. More information, including this above paragraphs, is here.

Why This Script?

Per SVN Book:

svnlook is a tool provided by Subversion for examining the various revisions and transactions in a repository. No part of this program attempts to change the repository—it’s a read-only tool. svnlook is typically used by the repository hooks for reporting the changes that are about to be committed (in the case of the pre-commit hook) or that were just committed (in the case of the post-commit hook) to the repository. A repository administrator may use this tool for diagnostic purposes.

This BASH script uses svnlook and extends its usage to produce an elegant display of log of a Subversion repository.

The Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/bash
#
# BASH script to generate SVN repository log
# Refer to http://svnbook.red-bean.com/en/1.1/ch05s03.html for details
#
# Usage: svn_log.sh [REPO_PATH]
# First written: Thu, 28 Jan 2010 12:19:37 -0500
# Last modified: Thu, 28 Jan 2010 12:19:37 -0500
 
 
if [ $# != 1 ];
then
  echo
  echo "  ERROR : REPOSITORY PATH missing"
  echo "  Usage : svn_log.sh [REPO_PATH]"
  echo
  exit
else
  export REPO=$1
 
  # Determine the youngest/newest/latest revision number
  export REVISION=`svnlook youngest $REPO`
 
  echo "----------------------------------------------------------------------------------------------------------------"
  echo " Rev #  Date/Time                                    Message"
  echo "----------------------------------------------------------------------------------------------------------------"
 
  while [ $REVISION -ge 1 ];
  do
    # Extract all information about the given revision
    svnlook info $REPO -r $REVISION > /tmp/sg_svnlook.tmp
 
    # Pick out relevant information from the above
    export DATETIME=`cat /tmp/sg_svnlook.tmp | head -2 | tail -1`
    export MESSAGE=`cat /tmp/sg_svnlook.tmp | tail -1`
 
    # Print them to the screen
    printf "%6s %45s %s\n"  "$REVISION" "$DATETIME" "$MESSAGE"
 
    # Decrement the revision number by 1
    export REVISION=`expr $REVISION - 1`
  done
 
  echo "----------------------------------------------------------------------------------------------------------------"
fi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.