git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 11/11] Makefile: stop needing @@GIT_VERSION@@ in *.perl scripts

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 17, 2021, 00:26 UTC
Message-ID
<patch-11.11-defbd9b6db2-20211217T002023Z-avarab@gmail.com>
In-Reply-To
<cover-00.11-00000000000-20211217T002023Z-avarab@gmail.com>

Change the hardcoding of @@GIT_VERSION@@ in generated *.perl scripts to instead shell out to "git version". This means that we can stop re-building during development every time the HEAD changes.

These codepaths are not "hot", so shelling out to get the version shouldn't matter to users, in the one case where it potentially would in send-email (the loop for each E-Mail we send) we now cache the value, so we'll only retrieve it once.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile            | 2 +-
 git-cvsserver.perl  | 6 +++---
 git-send-email.perl | 7 ++-----
 git-svn.perl        | 2 +-
 4 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
index f2cee13ea5d..9ccfb1109f5 100644
--- a/Makefile
+++ b/Makefile
@@ -2343,7 +2343,7 @@ PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl
 perl_localedir_SQ =
 endif
 
-$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
+$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER
 	$(QUIET_GEN) \
 	sed -e '1{' \
 	    -e '	s|#!.*perl|#!$(PERL_PATH_SQ)|' \
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 4c8118010a8..4ec0cc1cc3c 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -26,8 +26,6 @@
 use File::Basename;
 use Getopt::Long qw(:config require_order no_ignore_case);
 
-my $VERSION = '@@GIT_VERSION@@';
-
 my $log = GITCVS::log->new();
 my $cfg;
 
@@ -126,7 +124,9 @@
     or die $usage;
 
 if ($state->{version}) {
-    print "git-cvsserver version $VERSION\n";
+    my $version = qx[git version];
+    $version =~ s/^(git)\b/$1-cvsserver/;
+    print $version;
     exit;
 }
 if ($state->{help}) {
diff --git a/git-send-email.perl b/git-send-email.perl
index 04087221aa7..390e8512627 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1504,6 +1504,7 @@ sub file_name_is_absolute {
 #
 # If an error occurs sending the email, this just dies.
 
+my $gitversion;
 sub send_message {
 	my @recipients = unique_email_list(@to);
 	@cc = (grep { my $cc = extract_valid_address_or_die($_);
@@ -1514,11 +1515,6 @@ sub send_message {
 	@recipients = unique_email_list(@recipients,@cc,@initial_bcc);
 	@recipients = (map { extract_valid_address_or_die($_) } @recipients);
 	my $date = format_2822_time($time++);
-	my $gitversion = '@@GIT_VERSION@@';
-	if ($gitversion =~ m/..GIT_VERSION../) {
-	    $gitversion = Git::version();
-	}
-
 	my $cc = join(",\n\t", unique_email_list(@cc));
 	my $ccline = "";
 	if ($cc ne '') {
@@ -1533,6 +1529,7 @@ sub send_message {
 Message-Id: $message_id
 ";
 	if ($use_xmailer) {
+		$gitversion ||= Git::version();
 		$header .= "X-Mailer: git-send-email $gitversion\n";
 	}
 	if ($in_reply_to) {
diff --git a/git-svn.perl b/git-svn.perl
index be987e316f9..727431412be 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -9,7 +9,6 @@
 		$_revision $_repository
 		$_q $_authors $_authors_prog %users/;
 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
-$VERSION = '@@GIT_VERSION@@';
 
 use Carp qw/croak/;
 use File::Basename qw/dirname basename/;
@@ -47,6 +46,7 @@
 	command_close_bidi_pipe
 	get_record
 );
+$VERSION = Git::version();
 
 BEGIN {
 	Memoize::memoize 'Git::config';
-- 
2.34.1.1119.g7a3fc8778ee
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 12 of 13 in “Makefile: fix "Perl" and "Python" rules, speed up re-builds”
  1. 00/11 Makefile: fix "Perl" and "Python" rules, speed up re-buildsÆvar Arnfjörð Bjarmason, Dec 17, 2021
  2. 01/11 Makefile: clean perl/build/ even with NO_PERL=YÆvar Arnfjörð Bjarmason, Dec 17, 2021
  3. 02/11 Makefile: don't set up "perl/build" rules under NO_PERL=YÆvar Arnfjörð Bjarmason, Dec 17, 2021
  4. 03/11 Makefile: use "=" not ":=" for po/* and perl/*Ævar Arnfjörð Bjarmason, Dec 17, 2021
  5. 04/11 Makefile: remove "mv $@ $@+" dance redundant to .DELETE_ON_ERRORÆvar Arnfjörð Bjarmason, Dec 17, 2021
  6. 05/11 Makefile: guard Perl-only variable assignmentsÆvar Arnfjörð Bjarmason, Dec 17, 2021
  7. 06/11 Makefile: change "ifndef NO_PERL" to "ifdef NO_PERL"Ævar Arnfjörð Bjarmason, Dec 17, 2021
  8. 07/11 Makefile: adjust Perl-related comments & whitespaceÆvar Arnfjörð Bjarmason, Dec 17, 2021
  9. 08/11 Makefile: correct "GIT-PERL-{DEFINES,HEADER}" dependency graphÆvar Arnfjörð Bjarmason, Dec 17, 2021
  10. 09/11 Makefile: sort PERL_DEFINES listÆvar Arnfjörð Bjarmason, Dec 17, 2021
  11. 10/11 Makefile: create a GIT-PYTHON-DEFINES, like "PERL"Ævar Arnfjörð Bjarmason, Dec 17, 2021
  12. 11/11 Makefile: stop needing @@GIT_VERSION@@ in *.perl scriptsÆvar Arnfjörð Bjarmason, Dec 17, 2021
  13. Ævar Arnfjörð BjarmasonFeb 21, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.