| 1 |
#/bin/sh |
| 2 |
# |
| 3 |
# This script defines some helper functions used by other scripts in the docs |
| 4 |
# folder. |
| 5 |
|
| 6 |
|
| 7 |
# Get the time the given filename was last modified. |
| 8 |
get_last_modified_date() |
| 9 |
{ |
| 10 |
local filename=$1 |
| 11 |
RESULT=`git log -1 --format="%ad" --date=format:'%b %d, %Y' -- $filename` |
| 12 |
} |
| 13 |
|
| 14 |
get_dlib_version() |
| 15 |
{ |
| 16 |
cat ../dlib/CMakeLists.txt | awk '/set\(CPACK_PACKAGE_VERSION_'$1'/{ match($2,"\"(.*)\"",a); print a[1]}' |
| 17 |
} |
| 18 |
|
| 19 |
# Dump a copy of the repo contents to $1 |
| 20 |
dump_repo_to() |
| 21 |
{ |
| 22 |
mkdir -p $1 |
| 23 |
git archive HEAD `git rev-parse --show-toplevel` | tar -xC $1 |
| 24 |
} |
| 25 |
|
| 26 |
# Call like git_logs_as_xml HEAD~4..HEAD out.xml to write the logs in that range to out.xml |
| 27 |
git_logs_as_xml() |
| 28 |
{ |
| 29 |
local logrange=$1 |
| 30 |
local outfile=$2 |
| 31 |
|
| 32 |
# What paths to include in the logs |
| 33 |
local paths="../dlib ../examples ../tools ../python_examples" |
| 34 |
|
| 35 |
(echo "<log>"; git log --stat=80 --date=iso-strict --pretty=format:"</files_changed></logentry>%n<logentry revision=\"%H\">%n<author email=\"%ae\">%an</author>%n<date>%ad</date>%nGIT_COMMIT_MESSAGE_BEGIN%sGIT_COMMIT_MESSAGE_END%n<files_changed>%n" $logrange $paths | tail -n+2 ; echo; echo '</files_changed></logentry>' ; echo "</log>" ) > $outfile |
| 36 |
|
| 37 |
# sanitize git commit messages |
| 38 |
sed -e '/GIT_COMMIT_MESSAGE_BEGIN.*GIT_COMMIT_MESSAGE_END/ { s/</\</g; s/>/\>/g; s/&/&/g; s/GIT_COMMIT_MESSAGE_BEGIN/<msg>/g; s/GIT_COMMIT_MESSAGE_END/<\/msg>/g; }' -i $outfile |
| 39 |
|
| 40 |
# trim whitespace at start and end of <files_changed> tags. |
| 41 |
sed -e ':a' -e 'N' -e '$!ba' -e "s/<files_changed>[ \n]*/<files_changed> /g" -e "s/[ \n]*<\/files_changed>/<\/files_changed>/g" -i $outfile |
| 42 |
} |
| 43 |
|
| 44 |
# call like: set_dlib_version MAJOR 42 to set MAJOR version to 42. |
| 45 |
set_dlib_version() |
| 46 |
{ |
| 47 |
sed -i -e 's/\(set(CPACK_PACKAGE_VERSION_'$1' *"\).*\(".*\)/\1'$2'\2/' ../dlib/CMakeLists.txt |
| 48 |
} |
| 49 |
|
| 50 |
MAJOR_NUM=`get_dlib_version MAJOR` |
| 51 |
MINOR_NUM=`get_dlib_version MINOR` |
| 52 |
PATCH_NUM=`get_dlib_version PATCH` |