Skip to content

Commit

Permalink
Output diff of file instead of file itself
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Jul 8, 2012
1 parent e4c5f5f commit 55450a8
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion git-playback.sh
Expand Up @@ -128,14 +128,57 @@ output_to_file() {
do
echo '<li><pre><code>' >> $output_file
if [ -f $file ]; then
cat $file >> $output_file
eval "$(git diff --unified=999999 HEAD~1 $file | read_diff >> $output_file)"
fi
echo '</code></pre></li>' >> $output_file
done
echo '</ul></div>' >> $output_file
fi
}

read_diff() {
OIFS=$IFS
IFS=''

read -r s

while [[ $? -eq 0 ]]
do
if [[ $s == diff* ]] ||
[[ $s == +++* ]] ||
[[ $s == ---* ]] ||
[[ $s == @@* ]] ||
[[ $s == index* ]]; then
cls='none'
elif [[ $s == +* ]]; then
s=$(sed 's/^\s*./ /g' <<<"$s")
cls='new'
elif [[ $s == -* ]]; then
s=$(sed 's/^\s*./ /g' <<<"$s")
cls='old'
else
cls=
fi

if [[ "$cls" == 'none' ]]; then
cls='none'
else [[ "$cls" ]]
echo
fi

if [[ "$cls" == 'none' ]]; then
cls='none'
elif [[ "$cls" ]]; then
echo -n '<div class="'${cls}'">'${s}'</div>'
else
echo -n ${s}
fi
read -r s
done

IFS=$OIFS
}

rm -f $output_file
echo $htmlStart >> $output_file
foreach_git_revision output_to_file
Expand Down

0 comments on commit 55450a8

Please sign in to comment.