# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.15.1

EAPI=8

CRATES="
"

declare -A GIT_CRATES=(
	[libmimalloc-sys]='https://github.com/eduDorus/mimalloc_rust;262fb407466952bf6ebaf4a5d586c3010396cb2f;mimalloc_rust-%commit%/libmimalloc-sys'
	[mimalloc]='https://github.com/eduDorus/mimalloc_rust;262fb407466952bf6ebaf4a5d586c3010396cb2f;mimalloc_rust-%commit%'
)

RUST_MIN_VER="1.94.0"

inherit cargo desktop wrapper xdg

MY_PN="GitComet"
MY_P=${MY_PN}-${PV}

DESCRIPTION="GitComet is user interface for GIT workflows"
HOMEPAGE="
	https://gitcomet.dev/
	https://github.com/Auto-Explore/GitComet
"
SRC_URI="
	https://github.com/Auto-Explore/GitComet/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	https://github.com/dsafxP/gentoo-distfiles/releases/download/${P}/${P}-crates.tar.xz
	${CARGO_CRATE_URIS}
"

S="${WORKDIR}/${MY_P}/crates/${PN}"

LICENSE="AGPL-3"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD-2 BSD Boost-1.0
	CC0-1.0 ISC MIT MPL-2.0 UoI-NCSA Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="dev-libs/libgit2:="
RDEPEND=">=dev-vcs/git-2.50.1"

src_prepare() {
	default

	local MIMALLOC_COMMIT="262fb407466952bf6ebaf4a5d586c3010396cb2f"
	local WORKSPACE="${WORKDIR}/mimalloc_rust-${MIMALLOC_COMMIT}"
	local VENDOR="${ECARGO_VENDOR}/libmimalloc-sys"

	# overwrite the broken c_src in the workspace
	rm -rf "${WORKSPACE}/libmimalloc-sys/c_src/mimalloc/v3" || die
	cp -r "${VENDOR}/c_src/mimalloc/v3" "${WORKSPACE}/libmimalloc-sys/c_src/mimalloc/v3" || die
}

src_configure() {
	export LIBGIT2_NO_VENDOR=1
	local myfeatures=(
		ui
		gix
	)
	cargo_src_configure --bin gitcomet # gitcomet-launcher unsupported in linux
}

src_install() {
	cargo_src_install

	dodir /usr/libexec/${PN}

	mv "${ED}/usr/bin/${PN}" "${ED}/usr/libexec/${PN}/" || die

	# prevents auto install of desktop & icons locally
	make_wrapper ${PN} "env GITCOMET_NO_DESKTOP_INSTALL=1 ${EPREFIX}/usr/libexec/${PN}/${PN}"

	cd "${WORKDIR}/${MY_P}" || die

	local DOCS=(
		README.md
		CONTRIBUTING.md
		NOTICE
		docs
	)

	einstalldocs

	domenu assets/linux/${PN}.desktop

	local x
	for x in 32 48 128 256 512; do
		doicon -s ${x} assets/linux/hicolor/${x}*/apps/*
	done

	newicon -s scalable assets/${PN}_logo.svg ${PN}.svg
}