From 4a48c4584d7b979716e748b9cc257584b6c8984d Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 16 Sep 2014 18:25:46 -0700 Subject: [PATCH 1/2] add --tags to 'git describe' 'git describe' calculates the version since the last **annotated** diff. Adding --tags shows the most recent tags (v0.94, for example) regardless if they're annotated or not. --- lib/Qpsmtpd.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 4036f1a..3926655 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -16,7 +16,7 @@ my $git; if (-e ".git") { local $ENV{PATH} = "/usr/bin:/usr/local/bin:/opt/local/bin/"; - $git = `git describe`; + $git = `git describe --tags`; $git && chomp $git; } From 1ebe5ea6ec2a2f4eaa584c62966615f843b02435 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 17 Sep 2014 00:02:23 -0700 Subject: [PATCH 2/2] put git version detection code into a sub --- lib/Qpsmtpd.pm | 23 ++++++++++++----------- t/packaging.t | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 3926655..d2ebd58 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -1,9 +1,8 @@ package Qpsmtpd; use strict; - #use warnings; -our $VERSION = "0.95"; +our $VERSION = '0.95'; use vars qw($TraceLevel $Spool_dir $Size_threshold); use lib 'lib'; @@ -12,17 +11,9 @@ use Qpsmtpd::Address; use Qpsmtpd::Config; use Qpsmtpd::Constants; -my $git; - -if (-e ".git") { - local $ENV{PATH} = "/usr/bin:/usr/local/bin:/opt/local/bin/"; - $git = `git describe --tags`; - $git && chomp $git; -} - our $hooks = {}; - our $LOGGING_LOADED = 0; +my $git = git_version(); sub _restart { my $self = shift; @@ -41,6 +32,16 @@ sub _restart { sub version { $VERSION . ($git ? "/$git" : "") } +sub git_version { + return if !-e '.git'; + { + local $ENV{PATH} = "/usr/bin:/usr/local/bin:/opt/local/bin/"; + $git = `git describe --tags`; + $git && chomp $git; + } + return $git; +} + sub TRACE_LEVEL { $TraceLevel }; # leave for plugin compatibility sub hooks { diff --git a/t/packaging.t b/t/packaging.t index e0df631..7b7ed0c 100644 --- a/t/packaging.t +++ b/t/packaging.t @@ -14,7 +14,7 @@ sub get_qp_version { my $rvfile = get_file_contents('lib/Qpsmtpd.pm') or return; my ($ver_line) = grep { $_ =~ /^our \$VERSION/ } @$rvfile; - my ($ver) = $ver_line =~ /"([0-9\.]+)"/; + my ($ver) = $ver_line =~ /['"]([0-9\.]+)['"]/; return $ver; };