POKE ME for any consultancy

Friday, May 30, 2014

SVN Hook Scripts

PRE-COMMIT HOOK
REPOS="$1"
TXN="$2"
MAX_SIZE=31457280
MIN_LOG=10

# Make sure that the log message contains some text.
SVNLOOK=/data/csvn/bin/svnlook
# $SVNLOOK log -t "$TXN" "$REPOS" | \
#   grep "[a-zA-Z0-9]" > /dev/null || exit 1
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)
if [ "$LOGMSG" -lt "$MIN_LOG" ]
then
echo -e "*** Your commit has been blocked because of blank comment log or your log message is less than 9 character ***" >&2
echo -e "*** Please write a log message and then try committing again. ***" >&2
echo -e "*** Thank You:Amit Anand***" >&2
exit 1
fi

files=$("$SVNLOOK" changed -t "$TXN" "$REPOS" | awk '{print $2}')
for f in $files
do
# check file size.
filesize=$($SVNLOOK cat -t "$TXN" "$REPOS" "$f" | wc -c)
if [ "$filesize" -gt "$MAX_SIZE" ]
then
echo -e "*** File $f is too large.***" >&2
echo -e "*** Thank You:CMTEAM***" >&2
exit 1
fi

done
# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
# commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1

# All checks passed, so allow the commit.
exit 0

POST-COMMIT HOOK

REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

# Only do actual work when the "svn:date" property is modified, which seems
  # to be the last revision property modified by the svnsync process.
  if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then
    AUTHOR=`svnlook author $REPOS -r $REV`
    DATE=`svnlook date $REPOS -r $REV`
    LOG=`svnlook log $REPOS -r $REV`

    echo "$REPOS@$REV: $LOG by $AUTHOR at $DATE"
  fi
 
# mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf

# Example for synchronizing one repository from the post-commit hook
#SVNSYNC synchronize URL_TO_SLAVE_REPO --username=svnsync --password=svnsyncpassword
#svnsync initialize URL_TO_SLAVE_REPO URL_TO_MASTER_REPO --username=svnsync --password=svnsyncpassword
exit 0


PRE-REVPROP-CHANGE

#!/bin/sh

USER="$3"

if [ "$USER" = "svnsync" ]; then exit 0; fi

echo "Only the admin user may change revision properties as this is a read-only, mirror repository."  >&2

exit 1


SCM tools










CODE CHURN MEASURES

  • Total LOC is the number of lines of non-commented executable lines in the files comprising the new version of a binary. Internal Microsoft tools were used to compute this measure.
  • Churned LOC is the sum of the added and changed lines of code between a baseline version and a new version of the files comprising a binary.
  • Deleted LOC is the number of lines of code deleted between the baseline version and the new version of a binary. The churned LOC and the deleted LOC are computed by the version control systems using a file comparison utility like diff.
  • File count is the number of files compiled to create a binary.
  • Weeks of churn is the cumulative time that a file was opened for editing from the version control system.
http://sourceforge.net/projects/sloccount/

http://cloc.sourceforge.net/


Software Version Control

 Software Version Control is a software system designed to track changes to individual files and directories. It's primary function is to facilitate, track and help organize changes to constantly evolving software systems.

Why we branch a code?

  • Physical
  • Functional
  • Environment
  • Organizational
  • Procedural

Branching Best Practices?


  • Use Meaningful Branch Names
  • Prefer Branching over Code Freezing
  • Isolate Change and work


SCM Best Practices



  • Use a reliable and dedicated server to house your code
  • Backup your code daily
  • Test your backup and restore processes
  • Choose a source control tool that fits your organization's requirements
  • Perform all tool specific administrative tasks
  • Keep your code repositories as clean as possible
  • Secure access to your code
  • Source Control Administration

Software Configuration Management Definition


SCM are the practices and procedures for administering source code, producing software development builds, controlling change, and managing software configurations.