From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gabriel Subject: [PATCH] import-tars: Make it possible to include the original commit ID Date: Thu, 18 Feb 2010 16:02:12 +0100 Message-ID: <1266505333-20286-1-git-send-email-g2p.code@gmail.com> References: <20100218132709.8CEBA2FC07@perkele> Cc: Peter Krefting , Gabriel To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Thu Feb 18 16:02:37 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ni7tk-0002QD-3Y for gcvg-git-2@lo.gmane.org; Thu, 18 Feb 2010 16:02:36 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758107Ab0BRPCb (ORCPT ); Thu, 18 Feb 2010 10:02:31 -0500 Received: from smtp3-g21.free.fr ([212.27.42.3]:43364 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757728Ab0BRPCa (ORCPT ); Thu, 18 Feb 2010 10:02:30 -0500 Received: from smtp3-g21.free.fr (localhost [127.0.0.1]) by smtp3-g21.free.fr (Postfix) with ESMTP id 0A35A81810D; Thu, 18 Feb 2010 16:02:23 +0100 (CET) Received: from localhost (pro75-5-88-162-203-35.fbx.proxad.net [88.162.203.35]) by smtp3-g21.free.fr (Postfix) with ESMTP id 1437A818052; Thu, 18 Feb 2010 16:02:21 +0100 (CET) Received: from g2p by localhost with local (Exim 4.69) (envelope-from ) id 1Ni7tP-0005KS-8d; Thu, 18 Feb 2010 16:02:15 +0100 X-Mailer: git-send-email 1.7.0.rc2.31.g618d1 In-Reply-To: <20100218132709.8CEBA2FC07@perkele> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: Peter Krefting 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 Signed-off-by: Gabriel --- That's a sensible patch, thanks. A small correction; when both --readpax and --metainfo=msg are passed, incorporate both message and original sha1. I amended your commit. contrib/fast-import/import-tars.perl | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl index a5170a1..f41480e 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 @@ -124,7 +141,7 @@ foreach my $tar_file (@ARGV) $have_top_dir = 0 if $top_dir ne $1; } - my $commit_msg = "Imported from $tar_file."; + my $commit_msg = "Imported from $tar_file.\n"; my $this_committer_name = $committer_name; my $this_committer_email = $committer_email; my $this_author_name = $author_name; @@ -154,6 +171,10 @@ foreach my $tar_file (@ARGV) close MSG; } } + if ($orig_commitid ne '') + { + $commit_msg .= "\nThis tarball was generated by git, from commit id\n$orig_commitid."; + } print FI <