Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
svndiff2html runs svn diff on the current directory path and outputs a formatted HTML file to provide easier legibility.
#!/bin/bash
# svndiff2html runs svn diff on the current directory path and outputs a
# formatted HTML file to provide easier legibility.
diff="";
out="";
html="";
args="";
# ******************************************************************************
# FUNCTIONS
# ******************************************************************************
function displayHelp
{
echo " ";
echo "diff2html -- outputs an html encoded diff file for the current svn repo.";
echo " ";
echo "USAGE:";
echo " diff2html [-local or -l] outputPath";
echo " ";
echo "PARAMETERS:"
echo " -local (optional)"
echo " This parameter tells diff2html to make the comparison between "
echo " the local file changes and the current state of the svn repository.";
echo " If -local is not present, the script will compare the most recent ";
echo " commit to the repository with the repo version previous to it.";
echo " ";
echo " outputPath";
echo " This is simply the output path for the html file that is generated";
echo " by the script.";
echo " ";
echo "To use, add to PATH, chmod to 755, navigate to folder of svn files";
echo "that are to be diff'ed, and run diff2html. (diff2html must be run within";
echo "the directory of the files to be diffed.)";
}
function pipeout
{
# echo -n "$1";
echo -n "$1" >> $out;
}
# ******************************************************************************
# Parse the parameters
if [[ "$1" == "-h" || "$1" == "-help" || "$1" == "help" ]]; then
displayHelp;
exit;
elif [[ "$1" == "-local" || "$1" == "-l" ]]; then
# for comparing local to repo
args="HEAD";
# diff=`svn diff --no-diff-deleted -x "-u -b -w --ignore-eol-style" -r HEAD`;
out="$2";
else
# for comparing the most recent commit to the one previous
args="PREV:HEAD";
# diff=`svn diff --no-diff-deleted -x "-u -b -w --ignore-eol-style" -r PREV:HEAD`;
out="$1";
fi
# Error if not enough parameters have been entered
if [ "$out" == "" ]; then
echo;
echo "ERROR! *************************************";
echo "You must at least enter an output file path.";
echo "Enter 'diff2html help' for usage."
echo;
exit;
fi
echo;
if [ "$args" == "HEAD" ]; then
echo "NOTE: Keep in mind files not 'added' to source control will not be ";
echo "included in the diff. Please first 'add' those files to run local diff ";
echo "on them. (These files with be displayed in their entirety.)";
echo;
echo "Sending local diff to: $out";
else
echo "Sending head to previous diff to: $out";
fi
echo "" > $out;
# Send the header of the html file to the output file
pipeout "
<html>
<head>
<title>Diff for $PWD</title>
</head>
<style media=\"screen\" type=\"text/css\">
body {
margin: 0;
padding: 0;
background-color: #000000;
}
pre {
color: #F8F8F8;
background-color: #0B161D;
margin: 0;
padding: 0 0 0 2px;
font-family: PanicSans, monospace;
font-size: 12px;
line-height: 1.3em;
word-wrap: break-word;
white-space: pre;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
padding-top: 0.2em;
padding-bottom: 0.1em;
}
pre span {
padding-top: 0.2em;
padding-bottom: 0.1em;
}
/* Comment */
pre .comment {
color: #F8F8F8;
font-style: italic;
background-color: #0B161D;
}
/* diff.header */
pre.textmate-source.plasticcodewrap .meta_diff, pre.textmate-source.plasticcodewrap .meta_diff_header {
color: #F8F8F8;
font-style: italic;
background-color: #0E2231;
}
/* diff.header */
pre .at2 {
color: #F8F8F8;
font-style: italic;
font-weight: bold;
background-color: #0B161D;
}
/* diff.deleted */
pre .minus {
color: #F8F8F8;
background-color: #D03620;
}
/* diff.inserted */
pre .plus {
color: #F8F8F8;
background-color: #41A83E;
}
pre span .index {
background-color: #0E2231;
}
pre span .index:before {
/* content:\"<div></div>\";*/
}
.break {
padding-top:15px;
}
.headerDivider {
background-color: #0E2231;
padding-bottom: 4px;
}
pre .minus3 {
font-weight: bold;
background-color: #280A06; /*#0B161D;*/
}
pre .plus3 {
font-weight: bold;
background-color: #0B230E; /*#0B161D;*/
}
pre .only { color: purple; }
pre .diff { color: #8A2BE2; }
/* diff.changed */
pre.textmate-source.plasticcodewrap .markup_changed {
color: #F8F8F8;
background-color: #C4B14A;
}
</style>
<body>
<pre>
<span class=\"comment\">
========= DIFFS =========";
echo -n ''
first=1
diffseen=0
lastonly=0
folderPropertiesSkipped=0
OIFS=$IFS
IFS='
'
# Pipe out the svn diff to our processing loop to add html tags
svn diff --no-diff-deleted -x "-u -b -w --ignore-eol-style" -r $args | while read -r s
do
# echo "$line";
# Get beginning of line to determine what type
# of diff line it is.
t1=${s:0:1}
t2=${s:0:2}
t3=${s:0:3}
t4=${s:0:4}
t6=${s:0:6}
t7=${s:0:7}
# Determine HTML class to use.
if [[ "$t7" == 'Only in' ]]; then
cls='only'
if [[ $diffseen -eq 0 ]]; then
diffseen=1
if [ $folderPropertiesSkipped -eq 1 ]; then
echo -n '</span>' >> $out;
fi
else
if [[ $lastonly -eq 0 ]]; then
if [ $folderPropertiesSkipped -eq 1 ]; then
echo "</div>" >> $out;
fi
fi
fi
if [[ $lastonly -eq 0 ]]; then
if [ $folderPropertiesSkipped -eq 1 ]; then
echo "<div class='diffdiv'>" >> $out;
fi
fi
lastonly=1
elif [[ "$t4" == 'diff' ]]; then
cls='diff'
if [[ $diffseen -eq 0 ]]; then
diffseen=1
if [ $folderPropertiesSkipped -eq 1 ]; then
echo -n '</span>' >> $out;
fi
else
if [ $folderPropertiesSkipped -eq 1 ]; then
echo "</div>" >> $out;
fi
fi
if [ $folderPropertiesSkipped -eq 1 ]; then
echo "<div class='diffdiv'>" >> $out;
fi
lastonly=0
elif [[ "$t3" == '+++' ]]; then
cls='plus3'
lastonly=0
elif [[ "$t6" == 'Index:' ]]; then
cls='index'
lastonly=0
folderPropertiesSkipped=1
elif [[ "$t6" == '======' ]]; then
cls='headerDivider'
lastonly=0
elif [[ "$t3" == '---' ]]; then
cls='minus3'
lastonly=0
elif [[ "$t2" == '@@' ]]; then
cls='at2'
lastonly=0
elif [[ "$t1" == '+' ]]; then
cls='plus'
lastonly=0
elif [[ "$t1" == '-' ]]; then
cls='minus'
lastonly=0
else
cls=
lastonly=0
fi
# Convert &, <, > to HTML entities.
s=$(sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' <<<"$s")
if [[ $first -eq 1 ]]; then
first=0
else
if [ $folderPropertiesSkipped -eq 1 ]; then
echo >> $out;
fi
fi
# Output the line.
if [ $folderPropertiesSkipped -eq 1 ]; then
if [ "$cls" == "index" ]; then
echo -n '<div class="break"><span> </span></div><span class="'${cls}'">'${s}'</span>' >> $out;
elif [ "$cls" == "headerDivider" ]; then
echo -n '<div class="headerDivider"><span class="index">'${s}'</span></div>' >> $out;
elif [ "$cls" == "at2" ]; then
echo -n '<div style="padding-top:2px"><span> </span></div><span class="'${cls}'">'${s}'</span>' >> $out;
elif [[ "$cls" ]]; then
echo -n '<span class="'${cls}'">'${s}'</span>' >> $out;
else
echo -n ${s} >> $out;
fi
fi
done
IFS=$OIFS
if [[ $diffseen -eq 0 && $onlyseen -eq 0 ]]; then
echo -n '</span>' >> $out;
else
echo "</div>" >> $out;
fi
echo >> $out;
# Add the footer to the output file
pipeout "
========= END OF DIFFS =========
</span>
</pre>
</body>
</html>
";
echo "HTML diff complete.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment