# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=mercurial
pkgver=7.1.1
pkgrel=1
pkgdesc="A scalable distributed SCM tool"
arch=('i686' 'x86_64')
url="https://www.mercurial-scm.org/"
msys2_repository_url='https://foss.heptapod.net/mercurial/mercurial-devel'
msys2_changelog_url='https://www.mercurial-scm.org/relnotes'
msys2_references=(
  "purl: pkg:pypi/mercurial"
  "cpe: cpe:/a:mercurial:mercurial"
)
license=('spdx:GPL-2.0-or-later')
groups=('VCS')
depends=('python')
makedepends=(
  'python-devel'
  'gcc'
  "python-setuptools"
  "python-setuptools-scm"
  "python-build"
  "python-installer"
)
#optdepends=('tk: for the hgk GUI')
backup=('etc/mercurial/hgrc')
source=("https://mercurial-scm.org/release/${pkgname}-${pkgver}.tar.gz"{,.asc}
        'mercurial.profile')
sha256sums=('47cf66ba89c175536faf844c9b4cd962eb432afb516c073e51f436bf3f0bc148'
            'SKIP'
            '87427151713e689cd87dc50d50c048e0e58285815e4eb61962b50583532cbde5')
validpgpkeys=(2BCCE14F5C6725AA2EA8AEB7B9C9DC824AA5BDD5
              3A8155163D0E20A530FCB78647A67FFAA346AACE
              EB851395B4223EE2F7BA0B28DA54740BF08732BA
              818D87CD1AC180C394C86E633A33DE460D9EC39F  # Pulkit Goyal <7895pulkit@gmail.com>
              1F66F8CDF654E905C11DA061A11E01CD0E05D956  # Raphaël Gomès <alphare@raphaelgomes.dev>
              ED213E486B23249BDC107B5945CAA92A71CA027B) # Pierre-Yves David <pierre-yves.david@ens-lyon.org>

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  python -m installer --destdir="${pkgdir}" dist/*.whl

  install -d ${pkgdir}/usr/share/man/{man1,man5}
  install -m644 doc/hg.1 "${pkgdir}/usr/share/man/man1"
  install -m644 doc/{hgrc.5,hgignore.5} "${pkgdir}/usr/share/man/man5"
  install -m755 contrib/hgk "${pkgdir}/usr/bin"
  #install -m644 -D contrib/zsh_completion "${pkgdir}/usr/share/zsh/site-functions/_hg"
  install -m644 -D contrib/bash_completion "${pkgdir}/usr/share/bash-completion/completions/hg"
  install -d "${pkgdir}/usr/share/emacs/site-lisp"
  install -m644 contrib/{mq.el,mercurial.el} "${pkgdir}/usr/share/emacs/site-lisp"

  vimpath="${pkgdir}/usr/share/vim/vimfiles"
  install -Dm644 contrib/vim/HGAnnotate.vim "${vimpath}/syntax/HGAnnotate.vim"

  # set some variables
  install -m755 -d ${pkgdir}/etc/profile.d
  install -m755 ${srcdir}/mercurial.profile "${pkgdir}/etc/profile.d/mercurial.sh"

  # install configuration file
  install -m755 -d ${pkgdir}/etc/mercurial
  #install -m644 contrib/sample.hgrc "${pkgdir}/etc/mercurial/hgrc"
  
  # FS#38825 - Add certs config to package
  echo -e "\n[web]\ncacerts = /usr/ssl/certs/ca-bundle.crt\n" >> "${pkgdir}/etc/mercurial/hgrc"

  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
