git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] import-tars: properly import git-archive tarballs
@ 2010-02-17 19:20 Gabriel
  2010-02-18  9:40 ` Peter Krefting
  2010-02-18 13:00 ` Gabriel
  0 siblings, 2 replies; 6+ messages in thread
From: Gabriel @ 2010-02-17 19:20 UTC (permalink / raw)
  To: git; +Cc: Gabriel

git-archive adds a special entry to the archives it creates,
pax_global_header, containing the SHA1 of the exported commit.

import-tars.perl extracted it as a file, the top directory of
the archive became a subdirectory, and files moved with every
imported tarball.

Now import-tars correctly ignores the comment.

Signed-off-by: Gabriel <g2p.code@gmail.com>
---
 contrib/fast-import/import-tars.perl |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
index 95438e1..a5170a1 100755
--- a/contrib/fast-import/import-tars.perl
+++ b/contrib/fast-import/import-tars.perl
@@ -108,6 +108,7 @@ foreach my $tar_file (@ARGV)
 			}
 		}
 		print FI "\n";
+		next if $typeflag eq 'g' && $name eq 'pax_global_header';
 
 		my $path;
 		if ($prefix) {
-- 
1.7.0.rc2.31.g618d1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] import-tars: properly import git-archive tarballs
  2010-02-17 19:20 [PATCH] import-tars: properly import git-archive tarballs Gabriel
@ 2010-02-18  9:40 ` Peter Krefting
  2010-02-18 13:00 ` Gabriel
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Krefting @ 2010-02-18  9:40 UTC (permalink / raw)
  To: Gabriel; +Cc: Git Mailing List

Gabriel:

> git-archive adds a special entry to the archives it creates, 
> pax_global_header, containing the SHA1 of the exported commit.

Interesting use-case.

> Now import-tars correctly ignores the comment.

In the case where you actually would care, perhaps it should be added as a 
comment to the default commit message? Something like "Imported from 
$tar_file, created from commit $commit.".

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] import-tars: properly import git-archive tarballs
  2010-02-17 19:20 [PATCH] import-tars: properly import git-archive tarballs Gabriel
  2010-02-18  9:40 ` Peter Krefting
@ 2010-02-18 13:00 ` Gabriel
  2010-02-18 13:24   ` [PATCH] import-tars: Make it possible to include the original commit ID Peter Krefting
  1 sibling, 1 reply; 6+ messages in thread
From: Gabriel @ 2010-02-18 13:00 UTC (permalink / raw)
  To: git; +Cc: Peter Krefting

> Gabriel:
> > git-archive adds a special entry to the archives it creates, 
> > pax_global_header, containing the SHA1 of the exported commit.
> 
> Interesting use-case.

My use case really was a simple “import a range of tarballs for
bisecting”. That they were from git was a surprise, but I don't have
access to that repo, which for all I know is full of junk and not meant
for publication, so I'm not trying to get the original history.

I just want importing to work on tarballs found in the wild.

> > Now import-tars correctly ignores the comment.
> 
> In the case where you actually would care, perhaps it should be added
> as a comment to the default commit message? Something like "Imported
> from $tar_file, created from commit $commit.".

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.

It will serve as a hint when the person doing the import has access to
the original history. I don't think there's a point in keeping a sha1
when there's no access; keeping it in the history would confuse people,
or require sticking a longer explanation to each of these commits.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] import-tars: Make it possible to include the original commit ID
  2010-02-18 13:00 ` Gabriel
@ 2010-02-18 13:24   ` Peter Krefting
  2010-02-18 15:02     ` Gabriel
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Krefting @ 2010-02-18 13:24 UTC (permalink / raw)
  To: git; +Cc: g2p.code

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] import-tars: Make it possible to include the original commit ID
  2010-02-18 13:24   ` [PATCH] import-tars: Make it possible to include the original commit ID Peter Krefting
@ 2010-02-18 15:02     ` Gabriel
  2010-02-19  8:12       ` Peter Krefting
  0 siblings, 1 reply; 6+ messages in thread
From: Gabriel @ 2010-02-18 15:02 UTC (permalink / raw)
  To: git; +Cc: Peter Krefting, Gabriel

From: Peter Krefting <peter@softwolves.pp.se>

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>
Signed-off-by: Gabriel <g2p.code@gmail.com>
---

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 <<EOF;
 commit $branch_ref
-- 
1.7.0.rc2.31.g618d1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] import-tars: Make it possible to include the original commit ID
  2010-02-18 15:02     ` Gabriel
@ 2010-02-19  8:12       ` Peter Krefting
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Krefting @ 2010-02-19  8:12 UTC (permalink / raw)
  To: Gabriel; +Cc: Git Mailing List

Gabriel:

> A small correction; when both --readpax and --metainfo=msg are passed, 
> incorporate both message and original sha1. I amended your commit.

My initial thought was to let have the --metainfo message override the 
auto-generated message in its entirety, but I have no strong feelings either 
way, so i am OK with this change.

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-19  8:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-17 19:20 [PATCH] import-tars: properly import git-archive tarballs Gabriel
2010-02-18  9:40 ` Peter Krefting
2010-02-18 13:00 ` Gabriel
2010-02-18 13:24   ` [PATCH] import-tars: Make it possible to include the original commit ID Peter Krefting
2010-02-18 15:02     ` Gabriel
2010-02-19  8:12       ` Peter Krefting

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).