{"thread":{"id":"20775","subject":"[PATCH v4] import-tars: Allow per-tar author and commit message.","startedAt":"2009-08-26T19:26:55Z","lastAt":"2009-08-28T20:50:30Z","messageCount":2,"participants":["Peter Krefting","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"122034","messageId":"20090828185652.448AD189B7B@perkele","threadId":"20775","inReplyTo":null,"subject":"[PATCH v4] import-tars: Allow per-tar author and commit message.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2009-08-26T19:26:55Z","receivedAt":"2009-08-26T19:26:55Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"If the \"--metainfo=<ext>\" option is given on the command line, a file\ncalled \"<filename.tar>.<ext>\" will be used to create the commit message\nfor \"<filename.tar>\", instead of using \"Imported from filename.tar\".\n\nThe author and committer of the tar ball can also be overridden by\nembedding an \"Author:\" or \"Committer:\" header in the metainfo file.\n\nSigned-off-by: Peter Krefting <peter@softwolves.pp.se>\n---\nThis version stops parsing the meta file for headers as soon as a\nnon-header line is seen, as requested by Junio.\n\n contrib/fast-import/import-tars.perl |   56 +++++++++++++++++++++++++++++++--\n 1 files changed, 52 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl\nindex 78e40d2..081694f 100755\n--- a/contrib/fast-import/import-tars.perl\n+++ b/contrib/fast-import/import-tars.perl\n@@ -8,9 +8,20 @@\n ##  perl import-tars.perl *.tar.bz2\n ##  git whatchanged import-tars\n ##\n+## Use --metainfo to specify the extension for a meta data file, where\n+## import-tars can read the commit message and optionally author and\n+## committer information.\n+##\n+##  echo 'This is the commit message' > myfile.tar.bz2.msg\n+##  perl import-tars.perl --metainfo=msg myfile.tar.bz2\n \n use strict;\n-die \"usage: import-tars *.tar.{gz,bz2,Z}\\n\" unless @ARGV;\n+use Getopt::Long;\n+\n+my $metaext = '';\n+\n+die \"usage: import-tars [--metainfo=extension] *.tar.{gz,bz2,Z}\\n\"\n+\tunless GetOptions('metainfo=s' => \\$metaext) && @ARGV;\n \n my $branch_name = 'import-tars';\n my $branch_ref = \"refs/heads/$branch_name\";\n@@ -109,12 +120,49 @@ foreach my $tar_file (@ARGV)\n \t\t$have_top_dir = 0 if $top_dir ne $1;\n \t}\n \n+\tmy $commit_msg = \"Imported from $tar_file.\";\n+\tmy $this_committer_name = $committer_name;\n+\tmy $this_committer_email = $committer_email;\n+\tmy $this_author_name = $author_name;\n+\tmy $this_author_email = $author_email;\n+\tif ($metaext ne '')\n+\t{\n+\t\t# Optionally read a commit message from <filename.tar>.msg\n+\t\t# Add a line on the form \"Committer: name <e-mail>\" to override\n+\t\t# the committer and \"Author: name <e-mail>\" to override the\n+\t\t# author for this tar ball.\n+\t\tif (open MSG, '<', \"${tar_file}.${metaext}\")\n+\t\t{\n+\t\t\tmy $header_done = 0;\n+\t\t\t$commit_msg = '';\n+\t\t\twhile (<MSG>)\n+\t\t\t{\n+\t\t\t\tif (!$header_done && /^Committer:\\s+([^<>]*)\\s+<(.*)>\\s*$/i)\n+\t\t\t\t{\n+\t\t\t\t\t$this_committer_name = $1;\n+\t\t\t\t\t$this_committer_email = $2;\n+\t\t\t\t}\n+\t\t\t\telsif (!$header_done && /^Author:\\s+([^<>]*)\\s+<(.*)>\\s*$/i)\n+\t\t\t\t{\n+\t\t\t\t\t$this_author_name = $1;\n+\t\t\t\t\t$this_author_email = $2;\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t{\n+\t\t\t\t\t$commit_msg .= $_;\n+\t\t\t\t\t$header_done = 1;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tclose MSG;\n+\t\t}\n+\t}\n+\n \tprint FI <<EOF;\n commit $branch_ref\n-author $author_name <$author_email> $author_time +0000\n-committer $committer_name <$committer_email> $commit_time +0000\n+author $this_author_name <$this_author_email> $author_time +0000\n+committer $this_committer_name <$this_committer_email> $commit_time +0000\n data <<END_OF_COMMIT_MESSAGE\n-Imported from $tar_file.\n+$commit_msg\n END_OF_COMMIT_MESSAGE\n \n deleteall\n-- \n1.6.3.3\n"},{"id":"122053","messageId":"7vskfbhdd5.fsf@alter.siamese.dyndns.org","threadId":"20775","inReplyTo":"20090828185652.448AD189B7B@perkele","subject":"Re: [PATCH v4] import-tars: Allow per-tar author and commit message.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-28T20:50:30Z","receivedAt":"2009-08-28T20:50:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Peter Krefting <peter@softwolves.pp.se> writes:\n\n> +\tmy $commit_msg = \"Imported from $tar_file.\";\n> +\tmy $this_committer_name = $committer_name;\n> +\tmy $this_committer_email = $committer_email;\n> +\tmy $this_author_name = $author_name;\n> +\tmy $this_author_email = $author_email;\n> +\tif ($metaext ne '')\n> +\t{\n> +\t\t# Optionally read a commit message from <filename.tar>.msg\n> +\t\t# Add a line on the form \"Committer: name <e-mail>\" to override\n> +\t\t# the committer and \"Author: name <e-mail>\" to override the\n> +\t\t# author for this tar ball.\n> +\t\tif (open MSG, '<', \"${tar_file}.${metaext}\")\n> +\t\t{\n> +\t\t\tmy $header_done = 0;\n> +\t\t\t$commit_msg = '';\n> +\t\t\twhile (<MSG>)\n> +\t\t\t{\n> +\t\t\t\tif (!$header_done && /^Committer:\\s+([^<>]*)\\s+<(.*)>\\s*$/i)\n> +\t\t\t\t{\n> +\t\t\t\t\t$this_committer_name = $1;\n> +\t\t\t\t\t$this_committer_email = $2;\n> +\t\t\t\t}\n> +\t\t\t\telsif (!$header_done && /^Author:\\s+([^<>]*)\\s+<(.*)>\\s*$/i)\n> +\t\t\t\t{\n> +\t\t\t\t\t$this_author_name = $1;\n> +\t\t\t\t\t$this_author_email = $2;\n> +\t\t\t\t}\n> +\t\t\t\telse\n> +\t\t\t\t{\n> +\t\t\t\t\t$commit_msg .= $_;\n> +\t\t\t\t\t$header_done = 1;\n> +\t\t\t\t}\n> +\t\t\t}\n> +\t\t\tclose MSG;\n> +\t\t}\n> +\t}\n> +\n\nI think people would expect that if they put a blank line after the header\npart, it would be stripped away, because a format that has a list of\ncolon-separated key-value pairs, followed by a blank line, and then\nfollowed by the body of the message is so familiar.\n\nWhile you are at it, can you also fix the style?  Existing code in\nimport-tars.perl looks like this:\n\n\t\tif ($typeflag == 2) { # symbolic link\n\t\t\tprint FI \"data \", length($linkname), \"\\n\", $linkname;\n\t\t\t$mode = 0120000;\n\t\t} else {\n\t\t\tprint FI \"data $size\\n\";\n\t\t\twhile ($size > 0 && read(I, $_, 512) == 512) {\n\t\t\t\tprint FI substr($_, 0, $size);\n\t\t\t\t$size -= 512;\n\t\t\t}\n\t\t}\n\ni.e. opening brace comes at the end of the line of \"if\" and \"else\";\nclosing brace comes on the same line immediately before \"else\".\n"}]}