{"thread":{"id":"20744","subject":"[PATCH v3] import-tars: Allow per-tar author and commit message.","startedAt":"2009-08-26T19:26:55Z","lastAt":"2009-08-28T18:56:47Z","messageCount":5,"participants":["Peter Krefting","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"121820","messageId":"20090826193015.962A7189B12@perkele","threadId":"20744","inReplyTo":null,"subject":"[PATCH v3] 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 adds a command line option --metainfo that is used to\nenable the new behaviour, as suggested by Junio C Hamano.\n\n contrib/fast-import/import-tars.perl |   54 +++++++++++++++++++++++++++++++--\n 1 files changed, 50 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl\nindex 78e40d2..15835cb 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,47 @@ 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\t$commit_msg = '';\n+\t\t\twhile (<MSG>)\n+\t\t\t{\n+\t\t\t\tif (/^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 (/^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}\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":"121845","messageId":"7viqg96ehf.fsf@alter.siamese.dyndns.org","threadId":"20744","inReplyTo":"20090826193015.962A7189B12@perkele","subject":"Re: [PATCH v3] import-tars: Allow per-tar author and commit message.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-27T04:57:16Z","receivedAt":"2009-08-27T04:57:16Z","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> +\t\t\twhile (<MSG>)\n> +\t\t\t{\n> +\t\t\t\tif (/^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 (/^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}\n\nDo you really want to slurp Committer:/Author: lines from _anywhere_ in\nthe file?  Wouldn't it make more sense to vaguely emulate e-mail message\nformat with headers, empty-line and then body that is free form?\n"},{"id":"121848","messageId":"alpine.DEB.2.00.0908270741170.6459@perkele.intern.softwolves.pp.se","threadId":"20744","inReplyTo":"7viqg96ehf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] import-tars: Allow per-tar author and commit message.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2009-08-27T06:42:57Z","receivedAt":"2009-08-27T06:42:57Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Junio C Hamano:\n\n> Do you really want to slurp Committer:/Author: lines from _anywhere_ in \n> the file?  Wouldn't it make more sense to vaguely emulate e-mail message \n> format with headers, empty-line and then body that is free form?\n\nI just tried not to overdo it, and keep the parsing code as simple as \npossible. I wasn't trying to implement an RFC 5322 compliant parser...\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"121945","messageId":"7vskfcd8ep.fsf@alter.siamese.dyndns.org","threadId":"20744","inReplyTo":"alpine.DEB.2.00.0908270741170.6459@perkele.intern.softwolves.pp.se","subject":"Re: [PATCH v3] import-tars: Allow per-tar author and commit message.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-28T01:38:54Z","receivedAt":"2009-08-28T01:38:54Z","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> Junio C Hamano:\n>\n>> Do you really want to slurp Committer:/Author: lines from _anywhere_\n>> in the file?  Wouldn't it make more sense to vaguely emulate e-mail\n>> message format with headers, empty-line and then body that is free\n>> form?\n>\n> I just tried not to overdo it, and keep the parsing code as simple as\n> possible. I wasn't trying to implement an RFC 5322 compliant parser...\n\nIt is not about overdoing, but about not glossly underdoing.\n\nDon't you at least want to avoid misparsing a msg file that looks like\nthis?\n\n\tAuthor: Peter Krefting <peter@softwolves.pp.se>\n\n\timport-tars: Allow per-tar author and commit message\n\n        This version updates the import-tars program so that another\n\tfile next to the archive can be read for the log message and\n        other meta information.  A line that begins with Committer: or\n        Author: is used as long as it consists of name and <email>\n\tto override the corresponding metainformation.  Remaining lines\n\tare used as the commit log message.\n\nAnd I do not think you need a complex parser.  Stop paying attention to a\nline that begins with Author:/Committer:, once you see a line that does\nnot match the pattern; and you would be Ok.\n\nIOW, something like...\n\n\tmy $reading_metainfo = 1;\n        my $squashing_empty = 0;\n\twhile (<>) {\n        \tif ($reading_metainfo) {\n\t\t\tif (/^Committer:.../) {\n                        \t...\n\t\t\t\tnext;\n\t\t\t} elsif (/^Author:.../) {\n                        \t...\n\t\t\t\tnext;\n\t\t\t} else {\n                        \t$reading_metainfo = 0;\n\t\t\t}\n                }\n                if (/^$/) {\n\t\t\t$squashing_empty = 1;\n                        next;\n\t\t}\n                if ($squashing_empty && $commit_msg ne '') {\n                \t$commit_msg .= \"\\n\";\n\t\t}\n                $commit_msg .= $_;\n                $squashing_empty = 0;\n\t}\n"},{"id":"122033","messageId":"alpine.DEB.2.00.0908281955160.24273@ds9.cixit.se","threadId":"20744","inReplyTo":"7vskfcd8ep.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] import-tars: Allow per-tar author and commit message.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2009-08-28T18:56:47Z","receivedAt":"2009-08-28T18:56:47Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Junio C Hamano:\n\n> Don't you at least want to avoid misparsing a msg file that looks like\n> this?\n\nGood point... Will post a fixed version.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"}]}