This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add git commit info into archive exports to allow building outside git
authorGraham Knop <haarg@haarg.org>
Sun, 20 Oct 2019 15:23:09 +0000 (17:23 +0200)
committerTodd Rinaldo <toddr@cpan.org>
Wed, 23 Oct 2019 16:24:03 +0000 (11:24 -0500)
Normally, builds require either a .patch file or to be built out of git
when not a proper release.  We can use git attributes to make a file
that will give partial information about the commit when an archive is
created.  This allows downloads from github to build.

.git_patch [new file with mode: 0644]
.gitattributes [new file with mode: 0644]
Porting/manicheck
make_patchnum.pl
t/porting/manifest.t

diff --git a/.git_patch b/.git_patch
new file mode 100644 (file)
index 0000000..c044fd5
--- /dev/null
@@ -0,0 +1 @@
+$Format:%H|%ci|%D$
diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..a5cc737
--- /dev/null
@@ -0,0 +1 @@
+.git_patch export-subst
index e206861..16f5fc2 100644 (file)
@@ -20,6 +20,8 @@ find {
         my $x = $File::Find::name; $x =~ s/^..//;
         return if -d;
         return if $_ eq '.gitignore';
+        return if $_ eq '.gitattributes';
+        return if $_ eq '.git_patch';
         return if $x =~ /^\.git\b/;
         return if $x =~ m{^\.github/};
         print "$x\t\tnot in MANIFEST\n" if !$files{$x};
index fc28d58..df352cb 100644 (file)
@@ -126,11 +126,40 @@ my $unpushed_commits = '    ';
 my ($read, $branch, $snapshot_created, $commit_id, $describe)= ("") x 5;
 my ($changed, $extra_info, $commit_title)= ("") x 3;
 
+my $git_patch_file;
 if (my $patch_file= read_file(".patch")) {
     ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patch_file;
     $extra_info = "git_snapshot_date='$snapshot_created'";
     $commit_title = "Snapshot of:";
 }
+elsif ($git_patch_file = read_file(".git_patch") and $git_patch_file !~ /\A\$Format:%H/) {
+    chomp $git_patch_file;
+    ($commit_id, my $commit_date, my $names)
+        = split /\|/, $git_patch_file;
+
+    my @names = split /,\s*/, $names;
+
+    ($branch) = map m{^HEAD -> (.*)}, @names;
+    if (!$branch) {
+        ($branch) = map m{^(blead|maint/.*)}, @names;
+    }
+    if (!$branch) {
+        ($branch) = map m{^tag: (.*)}, @names;
+        $describe = $branch;
+    }
+    if (!$branch) {
+        my ($pr) = map m{^refs/pull/([0-9]+)/}, @names;
+        $branch = "pull-request-$pr";
+    }
+    if (!$branch) {
+        $branch = $names[0] || $commit_id;
+    }
+
+    $describe ||= $commit_id;
+    $extra_info = "git_commit_date='$commit_date'\n";
+    $extra_info .= "git_snapshot_date='$commit_date'\n";
+    $commit_title = "Snapshot of:";
+}
 elsif (-d "$srcdir/.git") {
     # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
     ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick("git branch");
index a1b28c1..30d21d2 100644 (file)
@@ -87,6 +87,8 @@ SKIP: {
     find_git_or_skip(6);
     my %seen; # De-dup ls-files output (can appear more than once)
     chomp(my @repo= grep {
+        !m{\.git_patch$} &&
+        !m{\.gitattributes$} &&
         !m{\.gitignore$} &&
         !m{^\.github/} &&
         !$seen{$_}++