#!/bin/zsh
setopt extendedglob nomatch

parse() {
  local pkgdata
  IFS=- read -A pkgdata <<<"${${1:t}%.pkg.tar*}"
  pkgname=${(j:-:)pkgdata[1,-4]}
  epoch=
  pkgver=${pkgdata[-3]}
  pkgrel=${pkgdata[-2]}
  arch=${pkgdata[-1]}

  IFS=: read -A pkgdata <<<$pkgver
  if (( ${#pkgdata} > 1 )); then
    epoch=${pkgdata[1]}:
    pkgver=${pkgdata[2]}
  fi
}

function {
  local pkgname epoch pkgver pkgrel arch
  for pkg in $(makepkg --packagelist); do
    parse $pkg
    if [[ -n $1 ]]; then
        otherpkg=( /srv/ftp/pool/*/${pkgname}-${1}-${arch}.pkg.tar*~*.sig(Nom[1]) )
    else
        otherpkg=( /srv/ftp/pool/*/${pkgname}-[^-]##-[^-]##-${arch}.pkg.tar*~*.sig(Nom[1]) )
    fi
    if [[ -n $otherpkg ]]; then
      ${${(%):-%x}:A:h}/diffpkg $otherpkg $pkg
    else
      print -P "%F{11}%BWarning:%b No repo package found for $pkg%f"
    fi
  done
} $1

# vim:set sw=2 et:
