aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2019-05-16 00:45:11 +0100
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2019-05-16 17:31:50 +0000
commita68627ae96994ce56fd4ff9e7255cd0104851abe (patch)
treeaf576837062a0a064123692e861b9f85704cb414
parent1ee7c1105fd0e41f0fa5dc9fa2485752ef32558d (diff)
version: include version information for tarballs from git
Embed the git commit hash as well as the tag information for tarballs produced by 'git archive' (this includes the Github tarball). Example: TShark (Wireshark) 3.0.1 (Git commit ea351cd80516) Note that the embedded git ref names can include branch information, see for example `git log -n1 -s --format=%D v3.0.1`: tag: wireshark-3.0.1, tag: v3.0.1 HEAD -> bug/15544, tag: v99.99 HEAD, origin/master, origin/HEAD, master Thus, when creating release tarballs, I would recommend using the above command to see whether unnecessary branch information is present. If so, create a new post-release commit first on the same branch. This way, the release tarballs should be reproducible. While at it, increase the commit abbreviation length from 8 to 12. Currently git describe abbreviates to 10 by default. The default length is at minimum 7 and is dependent on the number of objects: git count-objects -v | perl -lne 'print int(log($1)/log(2)/2)+1 if /^in-pack: (\d+)/' Bug: 15544 Change-Id: Ifd1ed636b69f7687a7272775686f51387040a596 Reviewed-on: https://code.wireshark.org/review/33214 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
-rw-r--r--.gitattributes1
-rwxr-xr-xtools/make-version.pl29
2 files changed, 29 insertions, 1 deletions
diff --git a/.gitattributes b/.gitattributes
index 26b401002e..c9ca36b067 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -5,3 +5,4 @@
.gitattributes export-ignore
.gitignore export-ignore
.gitreview export-ignore
+tools/make-version.pl export-subst
diff --git a/tools/make-version.pl b/tools/make-version.pl
index 71cc0ec7e8..161c6a44da 100755
--- a/tools/make-version.pl
+++ b/tools/make-version.pl
@@ -80,17 +80,36 @@ sub read_repo_info {
my $do_hack = 1;
my $info_source = "Unknown";
my $is_git_repo = 0;
+ my $git_abbrev_length = 12;
my $git_cdir;
my $vcs_tag;
my $repo_branch = "unknown";
my $info_cmd = "";
+ # Tarball produced by 'git archive' will have the $Format string
+ # substituted due to the use of 'export-subst' in .gitattributes.
+ my $git_archive_commit = '$Format:%H$';
+ my @git_refs = split(/, /, '$Format:%D$');
+ if (substr($git_archive_commit, 0, 1) eq '$') {
+ # If $Format is still present, then this is not a git archive.
+ $git_archive_commit = undef;
+ } else {
+ foreach my $git_ref (@git_refs) {
+ if ($git_ref =~ /^tag: (v[1-9].+)/) {
+ $vcs_tag = $1;
+ $is_tagged = 1;
+ }
+ }
+ }
+
$package_string = $untagged_version_extra;
# For tarball releases, do not invoke git at all and instead rely on
# versioning information that was provided at tarball creation time.
if ($git_description) {
$info_source = "Forced via command line flag";
+ } elsif ($git_archive_commit) {
+ $info_source = "git archive";
} elsif (-e "$src_dir/.git" && ! -d "$src_dir/.git/svn") {
$info_source = "Command line (git)";
$git_client = 1;
@@ -148,6 +167,10 @@ sub read_repo_info {
$do_hack = 0;
# Assume format like v2.3.0rc0-1342-g7bdcf75
$commit_id = ($git_description =~ /([0-9a-f]+)$/)[0];
+ } elsif ($git_archive_commit) {
+ $do_hack = 0;
+ # Assume a full commit hash, abbreviate it.
+ $commit_id = substr($git_archive_commit, 0, $git_abbrev_length);
} elsif ($git_client) {
eval {
use warnings "all";
@@ -159,7 +182,7 @@ sub read_repo_info {
}
# Commits since last annotated tag.
- chomp($line = qx{git --git-dir="$src_dir"/.git describe --abbrev=8 --long --always --match "v[1-9]*"});
+ chomp($line = qx{git --git-dir="$src_dir"/.git describe --abbrev=$git_abbrev_length --long --always --match "v[1-9]*"});
if ($? == 0 && length($line) > 1) {
my @parts = split(/-/, $line);
$git_description = $line;
@@ -577,6 +600,10 @@ sub new_version_h
return "#define VCSVERSION \"$line-$vcs_name-$num_commits\"\n";
}
+ if ($commit_id) {
+ return "#define VCSVERSION \"$vcs_name commit $commit_id\"\n";
+ }
+
return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
}