#!/bin/sh

# get limits
if [ -z "$1" ]; then
  LIMITS=
else
  if [ -z "$2" ]; then
    BEGIN=1
    BATCH=$1
  else
    BEGIN=$1
    BATCH=$2
  fi
  LIMITS=$BEGIN,~$BATCH
fi

# commits list
git submodule --quiet foreach "git log --abbrev=8 --no-merges --pretty=format:\"%at:%h: %ar: %an: [\$(basename \$PWD)] %B%x01\"" | \
tr "\n" "\0" | tr "\1" "\n" | \
grep -av "Reset submodule .* to latest HEAD" | \
sed -e "s|^\x00||" -e "s|git-svn-id:[^\x00]*\x00||" -e "s|\x00$||" | \
sort -rn | \
sed -n ${LIMITS}p | \
sed -e "s|^[^:]*:||" -e "s|\x00\+|\n|g"
