# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 119642 2014-05-02 23:02:50Z sean@macports.org $

PortSystem          1.0
PortGroup           python 1.0
PortGroup           bitbucket 1.0

bitbucket.setup     seanfarley mercurial 3.0
revision            0
categories          devel python
license             GPL-2+
maintainers         deric sean openmaintainer
description         A fast, lightweight, distributed SCM system written in \
                    Python.
long_description    Mercurial is a fast, lightweight Source Control Management \
                    system designed for efficient handling of very large \
                    distributed projects. A distributed SCM tool is designed \
                    to support a model in which each Repository is loosely \
                    coupled to many others. Each Repository contains a \
                    complete set of metadata describing one or more projects. \
                    These repositories may be located almost anywhere. \
                    Individual developers only need access to their own \
                    repositories, not to a central one, in order to commit \
                    changes. Changes can be share via the builtin webserver, \
                    CGI, SSH or a stream of patch emails. Mercurial supports \
                    Apples' FileMerge for merges.

homepage            http://www.selenic.com/mercurial/
platforms           darwin
checksums           rmd160  2f71e8b363f2583e73c4b84f67f977ad628e9228 \
                    sha256  ae4baf1fdd3f8943c84104f9aef1efe63cd9f72c39fce351664bd414e79e808a

depends_build       port:py27-docutils

depends_run         path:share/curl/curl-ca-bundle.crt:curl-ca-bundle

patchfiles          patch-setup.py.diff

python.default_version 27

conflicts           mercurial-devel

build.cmd           make
build.target        all PYTHON=${python.bin}

subport mercurial-devel {
    bitbucket.setup     seanfarley mercurial cadad384c97c
    name                mercurial-devel
    version             3.0.99
    revision            0

    conflicts           mercurial
    checksums           rmd160  4a57a7af1f5e491e27c03b982b0f1880006b457f \
                        sha256  10843e510fe72b92f03b7e89f66ff68032bbcbe86db5cc52de7f185371e12e41
}

post-destroot {
    # configure ssl certificates
    xinstall -d -m 755 ${destroot}${prefix}/etc/mercurial
    xinstall -m 644 ${filespath}/hgrc \
        ${destroot}${prefix}/etc/mercurial/hgrc.default
    reinplace "s|%%PREFIX%%|${prefix}|g" \
        ${destroot}${prefix}/etc/mercurial/hgrc.default

    # install html docs
    xinstall -m 644 -W ${worksrcpath}/doc hg.1.txt hgrc.5.txt hgignore.5.txt \
            ${destroot}${prefix}/share/doc/${name}

    # install contrib
    xinstall -d -m 755 ${destroot}${prefix}/share/${name}
    file copy ${worksrcpath}/contrib ${destroot}${prefix}/share/${name}/contrib

    # copy hgweb.cgi hgwebdir.cgi
    file copy ${worksrcpath}/hgweb.cgi ${destroot}${prefix}/share/${name}/

    # copy hgk, the visual history browser
    file copy ${worksrcpath}/contrib/hgk ${destroot}${prefix}/bin/hgk

    if {[variant_isset bash_completion]} {
        set completions_path ${prefix}/share/bash-completion/completions
        xinstall -d ${destroot}${completions_path}
        xinstall -m 644 ${worksrcpath}/contrib/bash_completion ${destroot}${completions_path}/mercurial
        ln -s ${completions_path}/mercurial ${destroot}${completions_path}/hg
    }

    if {[variant_isset zsh_completion]} {
        set site-functions ${destroot}${prefix}/share/zsh/site-functions
        xinstall -d ${site-functions}
        xinstall ${worksrcpath}/contrib/zsh_completion ${site-functions}/_mercurial
    }
}

post-activate {
    if {![file exists ${prefix}/etc/mercurial/hgrc]} {
        copy ${prefix}/etc/mercurial/hgrc.default ${prefix}/etc/mercurial/hgrc
    }
}

variant bash_completion {
    depends_run-append path:etc/bash_completion:bash-completion
}

variant zsh_completion description {Install mercurial zsh completion file} {
    depends_run-append path:${prefix}/bin/zsh:zsh
}

python.link_binaries_suffix
