{"thread":{"id":"6740","subject":"[PATCH 2/2] tar archive frontend for fast-import.","startedAt":"2007-02-08T20:38:45Z","lastAt":"2007-02-08T21:01:41Z","messageCount":3,"participants":["Shawn O. Pearce","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"33969","messageId":"20070208203845.GB956@spearce.org","threadId":"6740","inReplyTo":null,"subject":"[PATCH 2/2] tar archive frontend for fast-import.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-08T20:38:45Z","receivedAt":"2007-02-08T20:38:45Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This is an example fast-import frontend, in less than 100 lines\nof Perl.  It accepts one or more tar archives on the command line,\npasses them through gzcat/bzcat/zcat if necessary, parses out the\nindividual file headers and feeds all contained data to fast-import.\nNo temporary files are involved.\n\nEach tar is treated as one commit, with the commit timestamp coming\nfrom the oldest file modification date found within the tar.\n\nEach tar is also tagged with an annotated tag, using the basename\nof the tar file as the name of the tag.\n\nCurrently symbolic links and hard links are not handled by the\nimporter.  The file checksums are also not verified.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n Nifty, eh?  :-)\n\n contrib/fast-import/import-tars.perl |  105 ++++++++++++++++++++++++++++++++++\n 1 files changed, 105 insertions(+), 0 deletions(-)\n create mode 100755 contrib/fast-import/import-tars.perl\n\ndiff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl\nnew file mode 100755\nindex 0000000..26c42c9\n--- /dev/null\n+++ b/contrib/fast-import/import-tars.perl\n@@ -0,0 +1,105 @@\n+#!/usr/bin/perl\n+\n+## tar archive frontend for git-fast-import\n+##\n+## For example:\n+##\n+##  mkdir project; cd project; git init\n+##  perl import-tars.perl *.tar.bz2\n+##  git whatchanged import-tars\n+##\n+\n+use strict;\n+die \"usage: import-tars *.tar.{gz,bz2,Z}\\n\" unless @ARGV;\n+\n+my $branch_name = 'import-tars';\n+my $branch_ref = \"refs/heads/$branch_name\";\n+my $committer_name = 'T Ar Creator';\n+my $committer_email = 'tar@example.com';\n+\n+open(FI, '|-', 'git', 'fast-import', '--quiet')\n+\tor die \"Unable to start git fast-import: $!\\n\";\n+foreach my $tar_file (@ARGV)\n+{\n+\t$tar_file =~ m,([^/]+)$,;\n+\tmy $tar_name = $1;\n+\n+\tif ($tar_name =~ s/\\.(tar\\.gz|tgz)$//) {\n+\t\topen(I, '-|', 'gzcat', $tar_file) or die \"Unable to gzcat $tar_file: $!\\n\";\n+\t} elsif ($tar_name =~ s/\\.(tar\\.bz2|tbz2)$//) {\n+\t\topen(I, '-|', 'bzcat', $tar_file) or die \"Unable to bzcat $tar_file: $!\\n\";\n+\t} elsif ($tar_name =~ s/\\.tar\\.Z$//) {\n+\t\topen(I, '-|', 'zcat', $tar_file) or die \"Unable to zcat $tar_file: $!\\n\";\n+\t} elsif ($tar_name =~ s/\\.tar$//) {\n+\t\topen(I, $tar_file) or die \"Unable to open $tar_file: $!\\n\";\n+\t} else {\n+\t\tdie \"Unrecognized compression format: $tar_file\\n\";\n+\t}\n+\n+\tmy $commit_time = 0;\n+\tmy $next_mark = 1;\n+\tmy $have_top_dir = 1;\n+\tmy ($top_dir, %files);\n+\n+\twhile (read(I, $_, 512) == 512) {\n+\t\tmy ($name, $mode, $uid, $gid, $size, $mtime,\n+\t\t\t$chksum, $typeflag, $linkname, $magic,\n+\t\t\t$version, $uname, $gname, $devmajor, $devminor,\n+\t\t\t$prefix) = unpack 'Z100 Z8 Z8 Z8 Z12 Z12\n+\t\t\tZ8 Z1 Z100 Z6\n+\t\t\tZ2 Z32 Z32 Z8 Z8 Z*', $_;\n+\t\tlast unless $name;\n+\t\t$mode = oct $mode;\n+\t\t$size = oct $size;\n+\t\t$mtime = oct $mtime;\n+\t\tnext if $mode & 0040000;\n+\n+\t\tprint FI \"blob\\n\", \"mark :$next_mark\\n\", \"data $size\\n\";\n+\t\twhile ($size > 0 && read(I, $_, 512) == 512) {\n+\t\t\tprint FI substr($_, 0, $size);\n+\t\t\t$size -= 512;\n+\t\t}\n+\t\tprint FI \"\\n\";\n+\n+\t\tmy $path = \"$prefix$name\";\n+\t\t$files{$path} = [$next_mark++, $mode];\n+\n+\t\t$commit_time = $mtime if $mtime > $commit_time;\n+\t\t$path =~ m,^([^/]+)/,;\n+\t\t$top_dir = $1 unless $top_dir;\n+\t\t$have_top_dir = 0 if $top_dir ne $1;\n+\t}\n+\n+\tprint FI <<EOF;\n+commit $branch_ref\n+committer $committer_name <$committer_email> $commit_time +0000\n+data <<END_OF_COMMIT_MESSAGE\n+Imported from $tar_file.\n+END_OF_COMMIT_MESSAGE\n+\n+deleteall\n+EOF\n+\n+\tforeach my $path (keys %files)\n+\t{\n+\t\tmy ($mark, $mode) = @{$files{$path}};\n+\t\tmy $git_mode = 0644;\n+\t\t$git_mode |= 0700 if $mode & 0111;\n+\t\t$path =~ s,^([^/]+)/,, if $have_top_dir;\n+\t\tprintf FI \"M %o :%i %s\\n\", $git_mode, $mark, $path;\n+\t}\n+\tprint FI \"\\n\";\n+\n+\tprint FI <<EOF;\n+tag $tar_name\n+from $branch_ref\n+tagger $committer_name <$committer_email> $commit_time +0000\n+data <<END_OF_TAG_MESSAGE\n+Package $tar_name\n+END_OF_TAG_MESSAGE\n+\n+EOF\n+\n+\tclose I;\n+}\n+close FI;\n-- \n1.5.0.rc4\n"},{"id":"33971","messageId":"Pine.LNX.4.63.0702082155210.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6740","inReplyTo":"20070208203845.GB956@spearce.org","subject":"Re: [PATCH 2/2] tar archive frontend for fast-import.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-08T20:56:02Z","receivedAt":"2007-02-08T20:56:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 8 Feb 2007, Shawn O. Pearce wrote:\n\n> Each tar is treated as one commit, with the commit timestamp coming\n> from the oldest file modification date found within the tar.\n\nYou mean the youngest, i.e. the newest file, right? (I did not read the \ncode yet...)\n\n>  Nifty, eh?  :-)\n\nYes!\n\nCiao,\nDscho\n"},{"id":"33973","messageId":"20070208210141.GA1047@spearce.org","threadId":"6740","inReplyTo":"Pine.LNX.4.63.0702082155210.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 2/2] tar archive frontend for fast-import.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-08T21:01:41Z","receivedAt":"2007-02-08T21:01:41Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> On Thu, 8 Feb 2007, Shawn O. Pearce wrote:\n> \n> > Each tar is treated as one commit, with the commit timestamp coming\n> > from the oldest file modification date found within the tar.\n> \n> You mean the youngest, i.e. the newest file, right? (I did not read the \n> code yet...)\n\nArrggh!  Yes, of course, the youngest/newest file.  The code (and\nyou) is right, the commit message is wrong.  ;-)\n\n-- \nShawn.\n"}]}