All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Loeffler <zvpunry@zvpunry.de>
To: git@vger.kernel.org
Subject: [PATCH] import-tars: use Archive::Tar instead of unpack()
Date: Mon, 12 Feb 2007 15:17:11 +0100	[thread overview]
Message-ID: <1171289831.629.6.camel@ibook.zvpunry.de> (raw)

this is less obscure, does not use gzcat (which is often installed as zcat)
and it is shorter.

Signed-off-by: Michael Loeffler <zvpunry@zvpunry.de>
---

This version does no longer support bzip2 or compress which will be fixed in
an amend. I did this patch to solve 2 problems. Maybe I do another patch with
GetoptLong and bzip2/compress support.

The first is a bug with this $git_mode variable which should be 0644 of
0755, but nothing else I think.

The second problem was the usage of gzcat, I don't have this link
(Debian sid).

diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
index 26c42c9..c084573 100755
--- a/contrib/fast-import/import-tars.perl
+++ b/contrib/fast-import/import-tars.perl
@@ -10,6 +10,10 @@
 ##
 
 use strict;
+use Archive::Tar;
+use Archive::Tar::File;
+use Archive::Tar::Constant;
+
 die "usage: import-tars *.tar.{gz,bz2,Z}\n" unless @ARGV;
 
 my $branch_name = 'import-tars';
@@ -23,48 +27,25 @@ foreach my $tar_file (@ARGV)
 {
 	$tar_file =~ m,([^/]+)$,;
 	my $tar_name = $1;
-
-	if ($tar_name =~ s/\.(tar\.gz|tgz)$//) {
-		open(I, '-|', 'gzcat', $tar_file) or die "Unable to gzcat $tar_file: $!\n";
-	} elsif ($tar_name =~ s/\.(tar\.bz2|tbz2)$//) {
-		open(I, '-|', 'bzcat', $tar_file) or die "Unable to bzcat $tar_file: $!\n";
-	} elsif ($tar_name =~ s/\.tar\.Z$//) {
-		open(I, '-|', 'zcat', $tar_file) or die "Unable to zcat $tar_file: $!\n";
-	} elsif ($tar_name =~ s/\.tar$//) {
-		open(I, $tar_file) or die "Unable to open $tar_file: $!\n";
-	} else {
-		die "Unrecognized compression format: $tar_file\n";
-	}
+	$tar_name =~ s/\.(tar|tgz|tar\.gz)$//;
+	my $tar = new Archive::Tar($tar_file) or die "Unable to open $tar_file: $!\n";
 
 	my $commit_time = 0;
 	my $next_mark = 1;
 	my $have_top_dir = 1;
 	my ($top_dir, %files);
 
-	while (read(I, $_, 512) == 512) {
-		my ($name, $mode, $uid, $gid, $size, $mtime,
-			$chksum, $typeflag, $linkname, $magic,
-			$version, $uname, $gname, $devmajor, $devminor,
-			$prefix) = unpack 'Z100 Z8 Z8 Z8 Z12 Z12
-			Z8 Z1 Z100 Z6
-			Z2 Z32 Z32 Z8 Z8 Z*', $_;
-		last unless $name;
-		$mode = oct $mode;
-		$size = oct $size;
-		$mtime = oct $mtime;
-		next if $mode & 0040000;
-
-		print FI "blob\n", "mark :$next_mark\n", "data $size\n";
-		while ($size > 0 && read(I, $_, 512) == 512) {
-			print FI substr($_, 0, $size);
-			$size -= 512;
-		}
-		print FI "\n";
-
-		my $path = "$prefix$name";
-		$files{$path} = [$next_mark++, $mode];
-
-		$commit_time = $mtime if $mtime > $commit_time;
+	foreach my $entry ($tar->get_files()) {
+		next if $entry->type != FILE;
+
+		printf FI "blob\nmark :%s\ndata %s\n%s\n", $next_mark,
+			$entry->size, $entry->get_content();
+
+		my $path = $entry->prefix . $entry->name;
+		$files{$path} = [$next_mark++, $entry->mode];
+
+		$commit_time = $entry->mtime if $entry->mtime > $commit_time;
+
 		$path =~ m,^([^/]+)/,;
 		$top_dir = $1 unless $top_dir;
 		$have_top_dir = 0 if $top_dir ne $1;
@@ -83,10 +64,8 @@ EOF
 	foreach my $path (keys %files)
 	{
 		my ($mark, $mode) = @{$files{$path}};
-		my $git_mode = 0644;
-		$git_mode |= 0700 if $mode & 0111;
 		$path =~ s,^([^/]+)/,, if $have_top_dir;
-		printf FI "M %o :%i %s\n", $git_mode, $mark, $path;
+		printf FI "M %o :%i %s\n", $mode & 0111 ? 0755 : 0644, $mark, $path;
 	}
 	print FI "\n";
 
-- 
1.5.0.rc4

             reply	other threads:[~2007-02-12 14:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-12 14:17 Michael Loeffler [this message]
2007-02-12 14:25 ` [PATCH] import-tars: use Archive::Tar instead of unpack() Johannes Schindelin
2007-02-12 17:28 ` Shawn O. Pearce
2007-02-14 16:03   ` Michael Loeffler
2007-02-15  2:51     ` Shawn O. Pearce
     [not found] ` <127B27FE-1F9A-4328-A87A-77B907FFEBA7@zvpunry.de>
2007-04-24 10:13   ` Karl Hasselström
2007-04-24 10:55     ` Sam Vilain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1171289831.629.6.camel@ibook.zvpunry.de \
    --to=zvpunry@zvpunry.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.