Re: CYGPORT: add configurable compressor for GIT class.

"Carlo B. via Cygwin-apps" <[email protected]>
Newsgroups gmane.os.cygwin.applications
Message-ID <CADt957660ntVTu3LgjJmNCaVcNrMwSH5=2q3XOb9La0reskaVw@mail.gmail.com>
Hello,
I created a patch for implementing this feature inside cygport.
I did several tests and it worked fine in my opinion.
I hope that you will find this useful.

Sincerely,

Carlo Bramini.

Il giorno dom 18 mag 2025 alle ore 20:46 Jon Turney
<[email protected]> ha scritto:
>
> On 29/04/2025 16:42, Carlo B. via Cygwin-apps wrote:
> [...]
> >
> > I can see these possible improvements into the code:
> >
> > 1)
> > The __tar() function inside lib/pkg_pkg.cygpart could be simplified by
> > writing just this:
> >
> > TAR_COMPRESSION_OPT=$(__tar_compress_opt ${TAR_COMPRESSION_EXT})
> >
> > and removing duplicated code now moved inside __tar_compress_opt()
> >
> > 2)
> > For adding the selection of the type of compression, I suggest to add
> > a new identifier called GIT_COMPRESSION_EXT. This will be used in a
> > similar manner of existing TAR_COMPRESSION_EXT.
> >
> > Inside cygclass/git.cygclass, we can add this:
> >
> > if ! defined GIT_COMPRESSION_EXT
> > then
> >      GIT_COMPRESSION_EXT="bz2"
> > fi
> >
> > which forces the default extension to bz2 for compatibility (I don't
> > know if it is useful or not).
> > Next, git_tarball symbol can be modified like this:
> >
> > git_tarball="${GIT_MODULE}-${PV}.tar.${GIT_COMPRESSION_EXT}"
> >
> > and finally, the call to tar will be:
> >
> > tar $(__tar_compress_opt ${GIT_COMPRESSION_EXT})cf
> > ${top}/${git_tarball} --exclude-vcs ${GIT_MODULE}/${GIT_SUBDIR}
> >
> > 3)
> > The same logic can be replicated if somebody will want to add the same
> > feature for selecting the compressor for other revision control
> > system: subversion, bazaar, cvs, mercurial.
>
> Thanks very much for looking into this.
>
> I think I would take a patch which just changes the compression used for
> archives made from git to lzma.
>
> (I can't see any particular use the ability to force the previous
> behavior of bz2 compression, but the more elaborate changes you propose
> seem like the right approach for doing that)
>
> > What do you think? Actually, this is first solution that entered in my
> > head and perhaps it could not be the best one.
>
> Give yourself a pat on the back for demonstrating an awareness of
> cognitive biases!
>
cygport.patch (application/octet-stream, 2.7 KB)
diff --git a/cygclass/git.cygclass b/cygclass/git.cygclass
index 3cb2c0d..56ca69e 100644
--- a/cygclass/git.cygclass
+++ b/cygclass/git.cygclass
@@ -42,6 +42,15 @@
 #  git
 #****
 
+#****v* git.cygclass/GIT_COMPRESSION_EXT
+#  SYNOPSIS
+#  GIT_COMPRESSION_EXT="xz"
+#  DESCRIPTION
+#  The compression to be used for package tar archives, default xz.
+#  DEFINITION
+GIT_COMPRESSION_EXT="${GIT_COMPRESSION_EXT:-xz}"
+#****
+
 #****v* git.cygclass/GIT_URI
 #  DESCRIPTION
 #  Address of Git repository from which to clone.  Must be defined before
@@ -60,7 +69,7 @@ then
 	GIT_MODULE=${GIT_MODULE%.git}
 fi
 
-git_tarball="${GIT_MODULE}-${PV}.tar.bz2"
+git_tarball="${GIT_MODULE}-${PV}.tar.${GIT_COMPRESSION_EXT}"
 
 SRC_URI="${git_tarball} "
 SRC_DIR="${GIT_MODULE}${GIT_SUBDIR+/}${GIT_SUBDIR}"
@@ -144,7 +153,7 @@ git_fetch() {
 	fi
 
 	cd ${T}/
-	tar ${_tar_bz2_flag}cf ${top}/${git_tarball} --exclude-vcs ${GIT_MODULE}/${GIT_SUBDIR}
+	tar $(__tar_compress_opt ${GIT_COMPRESSION_EXT})cf ${top}/${git_tarball} --exclude-vcs ${GIT_MODULE}/${GIT_SUBDIR}
 }
 
 readonly -f git_fetch
diff --git a/lib/pkg_pkg.cygpart b/lib/pkg_pkg.cygpart
index fb0805e..bf1a8cf 100644
--- a/lib/pkg_pkg.cygpart
+++ b/lib/pkg_pkg.cygpart
@@ -41,31 +41,46 @@
 TAR_COMPRESSION_EXT="${TAR_COMPRESSION_EXT:-xz}"
 #****
 
-__tar() {
-	local TAR_COMPRESSION_OPT TAR_SOURCE_DATE_OPTS;
+__tar_compress_opt() {
+	local _COMPRESSION_OPT COMPRESSION_EXT;
+
+	if [ $# -eq 0 ]; then
+		# Assume .xz as default compression engine
+		_COMPRESSION_EXT="xz"
+	else
+		_COMPRESSION_EXT="$1"
+	fi
 
 	# We could use --auto-compress, but this also constrains the extension
 	# to the currently valid set. We could probe if tar supports the
 	# compression and/or use an external compressor.
-	case ${TAR_COMPRESSION_EXT} in
-		bz2)
-			TAR_COMPRESSION_OPT="-j"
-			;;
-		gz)
-			TAR_COMPRESSION_OPT="-z"
-			warning "gzip compression for packages is considered obsolete"
-			;;
-		xz)
-			TAR_COMPRESSION_OPT="-J"
-			;;
-		zst)
-			TAR_COMPRESSION_OPT="--zstd"
-			;;
-		*)
-			error "tar option for TAR_COMPRESSION_EXT='${TAR_COMPRESSION_EXT}' unknown"
-			;;
+	case ${_COMPRESSION_EXT} in
+	bz2)
+		_COMPRESSION_OPT="${_tar_bz2_flag}"
+		;;
+	gz)
+		_COMPRESSION_OPT="-z"
+		warning "gzip compression for packages is considered obsolete"
+		;;
+	xz)
+		_COMPRESSION_OPT="-J"
+		;;
+	zst)
+		_COMPRESSION_OPT="--zstd -"
+		;;
+	*)
+		error "tar compressor '${_COMPRESSION_EXT}' is unknown"
+	;;
 	esac
 
+	echo -n ${_COMPRESSION_OPT}
+}
+
+__tar() {
+	local TAR_COMPRESSION_OPT TAR_SOURCE_DATE_OPTS;
+
+	TAR_COMPRESSION_OPT=$(__tar_compress_opt ${TAR_COMPRESSION_EXT})
+
 	if [ -n "${SOURCE_DATE_EPOCH}" ]
 	then
 		# Ensure reproducible sort order and last modification times <= SOURCE_DATE_EPOCH
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.