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

[PATCH] import-tars: Make it possible to include the original commit ID

From
Peter Krefting <peter@softwolves.pp.se>
Date
Feb 18, 2010, 13:24 UTC
Message-ID
<20100218132709.8CEBA2FC07@perkele>
In-Reply-To
<20100218140002.14f79853@gmail.com>

Add an option --readpax which makes import-tars read the commit ID stored by git-archive, adding it to the default commit message.

Signed-off-by: Peter Krefting <peter@softwolves.pp.se>
---
> Someone with stronger perl-fu to parse the hash comment could print on
> stderr (keep me CC-ed if you do that):
>   This tarball was generated by git, from commit id $SHA1.

Actually, having this information could be useful, for instance to create a "history-skipping" repository, and use bisect in that. When one finds which released version causes the problem, one can bisect in the original repository, using the commit ID indicated.

This applies on top of your patch.
 contrib/fast-import/import-tars.perl |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
index a5170a1..3451309 100755
--- a/contrib/fast-import/import-tars.perl
+++ b/contrib/fast-import/import-tars.perl
@@ -14,14 +14,20 @@
 ##
 ##  echo 'This is the commit message' > myfile.tar.bz2.msg
 ##  perl import-tars.perl --metainfo=msg myfile.tar.bz2
+##
+## Use --readpax to read the pax_global_header generated by git archive.
+## The commit ID stored in the header will be appended to the default
+## generated commit message for the imported tarball. If the parameter
+## is not given, the pax_global_header is ignored.
 
 use strict;
 use Getopt::Long;
 
 my $metaext = '';
+my $readpax;
 
-die "usage: import-tars [--metainfo=extension] *.tar.{gz,bz2,lzma,xz,Z}\n"
-	unless GetOptions('metainfo=s' => \$metaext) && @ARGV;
+die "usage: import-tars [--metainfo=extension] [--readpax] *.tar.{gz,bz2,lzma,xz,Z}\n"
+	unless GetOptions('metainfo=s' => \$metaext, 'readpax' => \$readpax) && @ARGV;
 
 my $branch_name = 'import-tars';
 my $branch_ref = "refs/heads/$branch_name";
@@ -61,6 +67,7 @@ foreach my $tar_file (@ARGV)
 	my $author_time = 0;
 	my $next_mark = 1;
 	my $have_top_dir = 1;
+	my $orig_commitid = '';
 	my ($top_dir, %files);
 
 	while (read(I, $_, 512) == 512) {
@@ -95,6 +102,16 @@ foreach my $tar_file (@ARGV)
 		$size = oct $size;
 		$mtime = oct $mtime;
 		next if $typeflag == 5; # directory
+		if (defined $readpax && $typeflag eq 'g' && $name eq 'pax_global_header')
+		{
+			while ($size > 0 && read(I, $_, 512) == 512) {
+				if (/52 comment=([0-9a-f]{40})/)
+				{
+					$orig_commitid = $1;
+				}
+			}
+			next;
+		}
 
 		print FI "blob\n", "mark :$next_mark\n";
 		if ($typeflag == 2) { # symbolic link
@@ -154,6 +171,10 @@ foreach my $tar_file (@ARGV)
 			close MSG;
 		}
 	}
+	elsif ($orig_commitid ne '')
+	{
+		$commit_msg .= "\n\nThis tarball was generated by git, from commit id\n$orig_commitid.";
+	}
 
 	print FI <<EOF;
 commit $branch_ref
-- 
1.7.0
Previous: GabrielNext: Gabriel
Message 4 of 6 in “import-tars: properly import git-archive tarballs”
  1. import-tars: properly import git-archive tarballsGabriel, Feb 17, 2010
  2. Peter KreftingFeb 18, 2010
  3. GabrielFeb 18, 2010
  4. import-tars: Make it possible to include the original commit IDPeter Krefting, Feb 18, 2010
  5. import-tars: Make it possible to include the original commit IDGabriel, Feb 18, 2010
  6. Peter KreftingFeb 19, 2010

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.