################################################################################
#
# fossil.cygclass - functions for building packages from Fossil checkouts
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2016 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/fossil.cygclass
#  SYNOPSIS
#  FOSSIL_URI="..."
#  [FOSSIL_REV="..."]
#  inherit fossil
#  DESCRIPTION
#  Fossil is a distributed version control system which includes an integrated
#  bug tracking system and wiki.  It is used by the SQLite project.
#
#  This cygclass creates source tarballs from Fossil checkouts.
#  NOTE
#  This cygclass sets a special SRC_URI for the tarball it creates.  If
#  additional sources are required, be sure to _add_ to SRC_URI rather than
#  outright setting it.
#  REQUIRES
#  fossil
#****

# is this truly necessary?
FOSSIL_MODULE=${FOSSIL_MODULE:-${ORIG_PN:-${PN}}}

fossil_tarball="${FOSSIL_MODULE}-${PV}_fossil.tar.bz2"

SRC_URI="${fossil_tarball} "
SRC_DIR="${FOSSIL_MODULE}"

fossil_fetch() {
	check_prog_req fossil

#****v* fossil.cygclass/FOSSIL_URI
#  DESCRIPTION
#  Address of Fossil repository from which to clone.
#****
	if ! defined FOSSIL_URI
	then
		error "FOSSIL_URI must be defined"
	fi

	# T likely doesn't exist at this point, so create it first
	mkdir -p ${T}
	cd ${T}

	# just in case we are re-fetching
	rm -fr ${FOSSIL_MODULE}.fossil ${FOSSIL_MODULE}/

	verbose fossil clone ${FOSSIL_URI} ${FOSSIL_MODULE}.fossil || error "fossil clone failed"

	mkdir ${FOSSIL_MODULE}
	pushd ${FOSSIL_MODULE}

	verbose fossil open ${T}/${FOSSIL_MODULE}.fossil || error "fossil open failed"

#****v* fossil.cygclass/FOSSIL_REV
#  DESCRIPTION
#  This optional variable can be one of:
#  * A specific revision tag, in the form of a SHA1 hash (a 40-digit hexadecimal)
#    or an abbreviation thereof (typically the first 10 hexadecimal digits).
#  * A branch name, in which case the latest revision of that branch will be used.
#  If unset, the latest revision of the 'trunk' branch will be used.
#****
	if defined FOSSIL_REV
	then
		fossil update ${FOSSIL_REV}
	fi

	popd

	# manifest and manifest.uuid may be used in sources (e.g. fossil itself)
	tar ${_tar_bz2_flag}cf ${top}/${fossil_tarball} --exclude=.fslckout --exclude=_FOSSIL_ ${FOSSIL_MODULE}
}

readonly -f fossil_fetch
