Hi,
this is a patch for src/tools/version_stamp.pl that adds the current Git 
commit information from "git describe --tags --long" to the current 
version string if "git" is specified on the command line. I've been 
testing for regressions and such lately (none found, yay), and the 
current output from for example "psql --version" only shows "psql 
(PostgreSQL) 9.6devel" without any reference to which commit it was 
compiled from.

The following is an example from current master when I compile it 
locally:

  $ src/tools/version_stamp.pl git
  Stamped these files with version number 9.6devel+REL9_5_ALPHA1-331-g119cf76:
          configure.in
          doc/bug.template
          src/include/pg_config.h.win32
          src/interfaces/libpq/libpq.rc.in
          src/port/win32ver.rc
  Don't forget to run autoconf 2.69 before committing.
  $ autoconf
  $ ./configure
  [snip]
  $ make
  [snip]
  $ src/bin/psql/psql --version
  psql (PostgreSQL) 9.6devel+REL9_5_ALPHA1-331-g119cf76

The format I suggest for this is "[version]+[git_info]", as recommended 
by the Semantic Version Specification (http://semver.org).

This format is not meant for public releases, of course, but I've found 
it very useful when compiling local versions and I quickly want to see 
which commit I have compiled from. The version string can also be used 
together with git(1). For example, right now I have an ancient version 
of REL9_5_STABLE from yesterday installed. To see if there are any new 
commits I should check out, I can just use copy+paste to see what's 
happened since then:

  $ git log --format=oneline 9.5alpha2+REL9_5_ALPHA2-82-gce56a64..
  440fc48cac7f450bb71d1f06f0d1326c63e3e42f dblink docs:  fix typo to use 
"connname" (3 n's), not "conname"

The patch applies cleanly with -p1 to all REL9_*_STABLE branches and 
master except REL9_0_STABLE and REL9_1_STABLE (due to perltidy in 
2bc09ff three years ago) and has been tested with all minor version 
variatons that version_stamp.pl accepts.

In case something fishy happens to the mail, the commit is also 
available from <https://github.com/sunny256/postgres/> in these 
branches:

  git-versioning - squashed commit with suggested log message
  git-versioning.wip - the branch I worked on

Online patch:

  
<https://github.com/sunny256/postgres/commit/0a6b8728f8105d05fd5b13c4b7ae80a44ff57576.patch>

Regards,
Øyvind

+-| Øyvind A. Holm <su...@sunbase.org> - N 60.37604° E 5.33339° |-+
| OpenPGP: 0xFB0CBEE894A506E5 - http://www.sunbase.org/pubkey.asc |
| Fingerprint: A006 05D6 E676 B319 55E2  E77E FB0C BEE8 94A5 06E5 |
+------------| 681035c8-4d32-11e5-ab81-fefdb24f8e10 |-------------+
diff --git a/src/tools/version_stamp.pl b/src/tools/version_stamp.pl
new file mode 100755
index 6be1ac0..b0a5af0
*** a/src/tools/version_stamp.pl
--- b/src/tools/version_stamp.pl
***************
*** 17,23 ****
  # Usage: cd to top of source tree and issue
  #	src/tools/version_stamp.pl MINORVERSION
  # where MINORVERSION can be a minor release number (0, 1, etc), or
! # "devel", "alphaN", "betaN", "rcN".
  #
  
  # Major version is hard-wired into the script.  We update it when we branch
--- 17,23 ----
  # Usage: cd to top of source tree and issue
  #	src/tools/version_stamp.pl MINORVERSION
  # where MINORVERSION can be a minor release number (0, 1, etc), or
! # "devel", "git", "alphaN", "betaN", "rcN".
  #
  
  # Major version is hard-wired into the script.  We update it when we branch
*************** elsif ($minor eq "devel")
*** 39,44 ****
--- 39,68 ----
  	$dotneeded    = 0;
  	$numericminor = 0;
  }
+ elsif ($minor eq "git")
+ {
+ 	# Add Git commit info to the end of the current version string
+ 	$currminor = get_minor_version(get_current_version());
+ 	if ($currminor =~ /^\./) # Does the minor version start with a dot?
+ 	{
+ 		$dotneeded = 1;
+ 		$currminor =~ s/^\.//;
+ 	}
+ 	else
+ 	{
+ 		$dotneeded = 0;
+ 	}
+ 	if ($currminor =~ /^(\d+)$/) # Does the minor version contain digits only?
+ 	{
+ 		$numericminor = $1;
+ 	}
+ 	else
+ 	{
+ 		$numericminor = 0;
+ 	}
+ 	$minor = $currminor;
+ 	$add_git_info = 1;
+ }
  elsif ($minor =~ m/^alpha\d+$/)
  {
  	$dotneeded    = 0;
*************** elsif ($minor =~ m/^rc\d+$/)
*** 56,62 ****
  }
  else
  {
! 	die "$0: minor-version must be N, devel, alphaN, betaN, or rcN\n";
  }
  
  # Create various required forms of the version number
--- 80,86 ----
  }
  else
  {
! 	die "$0: minor-version must be N, devel, git, alphaN, betaN, or rcN\n";
  }
  
  # Create various required forms of the version number
*************** $aconfver ne ""
*** 94,99 ****
--- 118,132 ----
  
  $fixedfiles = "";
  
+ # If 'git' is specified on the command line, add Git commit information
+ # to the end of the current version string
+ 
+ if (defined($add_git_info))
+ {
+ 	$fullversion .= '+' . `git describe --tags --long`;
+ 	$fullversion =~ s/\s+$//;
+ }
+ 
  sed_file("configure.in",
  "-e 's/AC_INIT(\\[PostgreSQL\\], \\[[0-9a-z.]*\\]/AC_INIT([PostgreSQL], [$fullversion]/'"
  );
*************** sub sed_file
*** 138,140 ****
--- 171,201 ----
  
  	$fixedfiles .= "\t$filename\n";
  }
+ 
+ # Extract current version from configure.in
+ sub get_current_version
+ {
+ 	my $retval = '';
+ 	open(my $fh, "configure.in")
+ 	  or die("could not open configure.in: $!\n");
+ 	while (<$fh>) {
+ 		if (/AC_INIT\(\[PostgreSQL\], \[(\S+?)\]/)
+ 		{
+ 			$retval = $1;
+ 			last;
+ 		}
+ 	}
+ 	close($fh);
+ 	if (!length($retval)) {
+ 		die("could not extract version information from configure.in\n");
+ 	}
+ 	return($retval);
+ }
+ 
+ # Extract minor version from version string
+ sub get_minor_version
+ {
+ 	my $currversion = shift;
+ 	$currversion =~ s/^\d+\.\d+//;
+ 	return($currversion);
+ }
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to