git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] import-tars: Allow per-tar author and commit message.
@ 2009-08-26 19:26 Peter Krefting
  2009-08-28 20:50 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Krefting @ 2009-08-26 19:26 UTC (permalink / raw)
  To: git

If the "--metainfo=<ext>" option is given on the command line, a file
called "<filename.tar>.<ext>" will be used to create the commit message
for "<filename.tar>", instead of using "Imported from filename.tar".

The author and committer of the tar ball can also be overridden by
embedding an "Author:" or "Committer:" header in the metainfo file.

Signed-off-by: Peter Krefting <peter@softwolves.pp.se>
---
This version stops parsing the meta file for headers as soon as a
non-header line is seen, as requested by Junio.

 contrib/fast-import/import-tars.perl |   56 +++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
index 78e40d2..081694f 100755
--- a/contrib/fast-import/import-tars.perl
+++ b/contrib/fast-import/import-tars.perl
@@ -8,9 +8,20 @@
 ##  perl import-tars.perl *.tar.bz2
 ##  git whatchanged import-tars
 ##
+## Use --metainfo to specify the extension for a meta data file, where
+## import-tars can read the commit message and optionally author and
+## committer information.
+##
+##  echo 'This is the commit message' > myfile.tar.bz2.msg
+##  perl import-tars.perl --metainfo=msg myfile.tar.bz2
 
 use strict;
-die "usage: import-tars *.tar.{gz,bz2,Z}\n" unless @ARGV;
+use Getopt::Long;
+
+my $metaext = '';
+
+die "usage: import-tars [--metainfo=extension] *.tar.{gz,bz2,Z}\n"
+	unless GetOptions('metainfo=s' => \$metaext) && @ARGV;
 
 my $branch_name = 'import-tars';
 my $branch_ref = "refs/heads/$branch_name";
@@ -109,12 +120,49 @@ foreach my $tar_file (@ARGV)
 		$have_top_dir = 0 if $top_dir ne $1;
 	}
 
+	my $commit_msg = "Imported from $tar_file.";
+	my $this_committer_name = $committer_name;
+	my $this_committer_email = $committer_email;
+	my $this_author_name = $author_name;
+	my $this_author_email = $author_email;
+	if ($metaext ne '')
+	{
+		# Optionally read a commit message from <filename.tar>.msg
+		# Add a line on the form "Committer: name <e-mail>" to override
+		# the committer and "Author: name <e-mail>" to override the
+		# author for this tar ball.
+		if (open MSG, '<', "${tar_file}.${metaext}")
+		{
+			my $header_done = 0;
+			$commit_msg = '';
+			while (<MSG>)
+			{
+				if (!$header_done && /^Committer:\s+([^<>]*)\s+<(.*)>\s*$/i)
+				{
+					$this_committer_name = $1;
+					$this_committer_email = $2;
+				}
+				elsif (!$header_done && /^Author:\s+([^<>]*)\s+<(.*)>\s*$/i)
+				{
+					$this_author_name = $1;
+					$this_author_email = $2;
+				}
+				else
+				{
+					$commit_msg .= $_;
+					$header_done = 1;
+				}
+			}
+			close MSG;
+		}
+	}
+
 	print FI <<EOF;
 commit $branch_ref
-author $author_name <$author_email> $author_time +0000
-committer $committer_name <$committer_email> $commit_time +0000
+author $this_author_name <$this_author_email> $author_time +0000
+committer $this_committer_name <$this_committer_email> $commit_time +0000
 data <<END_OF_COMMIT_MESSAGE
-Imported from $tar_file.
+$commit_msg
 END_OF_COMMIT_MESSAGE
 
 deleteall
-- 
1.6.3.3

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

* Re: [PATCH v4] import-tars: Allow per-tar author and commit message.
  2009-08-26 19:26 [PATCH v4] import-tars: Allow per-tar author and commit message Peter Krefting
@ 2009-08-28 20:50 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2009-08-28 20:50 UTC (permalink / raw)
  To: Peter Krefting; +Cc: git

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

> +	my $commit_msg = "Imported from $tar_file.";
> +	my $this_committer_name = $committer_name;
> +	my $this_committer_email = $committer_email;
> +	my $this_author_name = $author_name;
> +	my $this_author_email = $author_email;
> +	if ($metaext ne '')
> +	{
> +		# Optionally read a commit message from <filename.tar>.msg
> +		# Add a line on the form "Committer: name <e-mail>" to override
> +		# the committer and "Author: name <e-mail>" to override the
> +		# author for this tar ball.
> +		if (open MSG, '<', "${tar_file}.${metaext}")
> +		{
> +			my $header_done = 0;
> +			$commit_msg = '';
> +			while (<MSG>)
> +			{
> +				if (!$header_done && /^Committer:\s+([^<>]*)\s+<(.*)>\s*$/i)
> +				{
> +					$this_committer_name = $1;
> +					$this_committer_email = $2;
> +				}
> +				elsif (!$header_done && /^Author:\s+([^<>]*)\s+<(.*)>\s*$/i)
> +				{
> +					$this_author_name = $1;
> +					$this_author_email = $2;
> +				}
> +				else
> +				{
> +					$commit_msg .= $_;
> +					$header_done = 1;
> +				}
> +			}
> +			close MSG;
> +		}
> +	}
> +

I think people would expect that if they put a blank line after the header
part, it would be stripped away, because a format that has a list of
colon-separated key-value pairs, followed by a blank line, and then
followed by the body of the message is so familiar.

While you are at it, can you also fix the style?  Existing code in
import-tars.perl looks like this:

		if ($typeflag == 2) { # symbolic link
			print FI "data ", length($linkname), "\n", $linkname;
			$mode = 0120000;
		} else {
			print FI "data $size\n";
			while ($size > 0 && read(I, $_, 512) == 512) {
				print FI substr($_, 0, $size);
				$size -= 512;
			}
		}

i.e. opening brace comes at the end of the line of "if" and "else";
closing brace comes on the same line immediately before "else".

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

end of thread, other threads:[~2009-08-28 20:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-26 19:26 [PATCH v4] import-tars: Allow per-tar author and commit message Peter Krefting
2009-08-28 20:50 ` Junio C Hamano

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).