[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] git-version-gen: Support git-archive tarballs.
From: |
Simon Josefsson |
Subject: |
[PATCH] git-version-gen: Support git-archive tarballs. |
Date: |
Fri, 27 Dec 2024 12:35:08 +0100 |
Hi Jim, all,
If I run git-version-gen in a snapshot of a git repository it will
return UNKNOWN because it cannot find out the version.
Git has a .gitattribute mechanism to mark some files as 'export-subst'
which makes git-archive substitute some strings in the file, when it is
exporting a snapshot.
Instead of giving UNKNOWN in this situation, I think it would be nice if
git-version-gen handled this case, when the maintainer has opted in on
this scheme.
The code addition is small, after all current logic I'm adding this:
if test "x$v" = xUNKNOWN \
&& test -f ${tarball_version_file}-git \
&& head -1 ${tarball_version_file}-git \
| grep -v '^$Format' > /dev/null 2>&1; then
v=$(head -1 ${tarball_version_file}-git)
fi
The idea is that if git-version-gen is about to give up and use UNKNOWN,
and the maintainer somehow made it so that the .tarball-version-git file
exist, that content is used instead of UNKNOWN. There is protection to
not use the content if it was not substituted properly (the '$Format'
string).
Maintainers who want to opt in to support this can run these commands:
echo '$Format:%(describe)$' > .tarball-version-git
echo '.tarball-version-git export-subst' >> .gitattributes
git commit -a -m "Add .tarball-version-git for git-version-gen."
After that, git-version-gen will do the right thing when invoked in a
git-archive snapshot of that repository.
I'm using this patch in GNU Libidn and expect to add it to several other
projects too.
The patch doesn't change behaviour for existing users of git-version-gen
so I felt it was okay to push this, if not let's revert and discuss.
/Simon
From 4b4ba8b347e245aa7edcb779d6b0579c9bcbdf18 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Fri, 27 Dec 2024 10:44:16 +0100
Subject: [PATCH] git-version-gen: Support git-archive tarballs.
* build-aux/git-version-gen: Use .tarball-version-git as final guess.
---
build-aux/git-version-gen | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 780b7e99f7..8076685df4 100755
--- a/build-aux/git-version-gen
+++ b/build-aux/git-version-gen
@@ -1,6 +1,6 @@
#!/bin/sh
# Print a version string.
-scriptversion=2024-07-04.10; # UTC
+scriptversion=2024-12-27.09; # UTC
# Copyright (C) 2007-2024 Free Software Foundation, Inc.
#
@@ -18,13 +18,20 @@ scriptversion=2024-07-04.10; # UTC
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/.
-# It may be run two ways:
+
+# It may be run in the following ways, presuming the script is invoked
+# like "./git-version-gen .tarball-version":
+#
# - from a git repository in which the "git describe" command below
# produces useful output (thus requiring at least one signed tag)
-# - from a non-git-repo directory containing a .tarball-version file, which
-# presumes this script is invoked like "./git-version-gen .tarball-version".
+#
+# - from a "make dist" non-git-repo directory containing a
+# .tarball-version file
+#
+# - from a "git archive" non-git-repo directory containing a
+# .tarball-version-git file
-# In order to use intra-version strings in your project, you will need two
+# In order to use intra-version strings in your project, you will need some
# separate generated version string files:
#
# .tarball-version - present only in a distribution tarball, and not in
@@ -37,6 +44,12 @@ scriptversion=2024-07-04.10; # UTC
# hooks to force a reconfigure at distribution time to get the value
# correct, without penalizing normal development with extra reconfigures.
#
+# .tarball-version-git - a file committed to git containing a single
+# line with the string $Format:%(describe)$ and that the file is
+# marked in .gitattributes with ".tarball-version-git export-subst".
+# If the file doesn't exist or the export-subst keyword wasn't
+# effective, the file is ignored.
+#
# .version - present in a checked-out repository and in a distribution
# tarball. Usable in dependencies, particularly for files that don't
# want to depend on config.h but do want to track version changes.
@@ -69,7 +82,12 @@ scriptversion=2024-07-04.10; # UTC
# mv $@-t $@
# dist-hook:
# echo '$(VERSION)' > $(distdir)/.tarball-version
-
+#
+# To setup support for "git archive" tarballs, use the following:
+#
+# echo '$Format:%(describe)$' > .tarball-version-git
+# echo '.tarball-version-git export-subst' >> .gitattributes
+# git commit -a -m "Add .tarball-version-git for git-version-gen."
me=$0
@@ -195,6 +213,13 @@ else
v=$fallback
fi
+if test "x$v" = xUNKNOWN \
+ && test -f ${tarball_version_file}-git \
+ && head -1 ${tarball_version_file}-git \
+ | grep -v '^$Format' > /dev/null 2>&1; then
+ v=$(head -1 ${tarball_version_file}-git)
+fi
+
v=`echo "$v" |sed "s/^$prefix//"`
# Test whether to append the "-dirty" suffix only if the version
--
2.46.0
signature.asc
Description: PGP signature
- [PATCH] git-version-gen: Support git-archive tarballs.,
Simon Josefsson <=