git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sam Vilain <sam@vilain.net>
To: Peter Krefting <peter@softwolves.pp.se>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] import-tars: Allow per-tar author and commit message.
Date: Mon, 24 Aug 2009 09:46:35 +1200	[thread overview]
Message-ID: <4A91B8BB.1030906@vilain.net> (raw)
In-Reply-To: <20090823203640.B195D189B12@perkele>

Peter Krefting wrote:
> Instead of having each imported tar ball's commit message be "Imported
> from filename.tar", optionally take a commit message from a file
> called "filename.tar.msg".
>
> Instead of having each commit have the same author and committer
> information, optionally read the committer information from a file
> called "filename.tar.committer" and author from a file called
> "filename.tar.author".
>
> Signed-off-by: Peter Krefting <peter@softwolves.pp.se>
> ---
> I used this (albeit based on a slightly earlier verison of the script)
> to generate a better-looking history when importing
> http://git.debian.org/?p=crashmail/jamnntpd.git and
> http://git.debian.org/?p=crashmail/crashmail.git into Git, using
> excerpts from the embedded change history as commit messages.
>
>  contrib/fast-import/import-tars.perl |   42 +++++++++++++++++++++++++++++++--
>  1 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
> index 78e40d2..7aad16f 100755
> --- a/contrib/fast-import/import-tars.perl
> +++ b/contrib/fast-import/import-tars.perl
> @@ -109,12 +109,48 @@ foreach my $tar_file (@ARGV)
>  		$have_top_dir = 0 if $top_dir ne $1;
>  	}
>  
> +	# Optionally read a commit message from <filename.tar>.msg
> +	my $commit_msg = "Imported from $tar_file.";
> +	if (open MSG, '<', "${tar_file}.msg")
> +	{
> +		$commit_msg = '';
> +		while (<MSG>)
> +		{
> +			$commit_msg .= $_;
> +		}
> +		close MSG;
> +	}
> +
> +	# Optionally read a committer from <filename.tar>.committer
> +	# (first line is name, second line is e-mail address).
> +	my $this_committer_name = $committer_name;
> +	my $this_committer_email = $committer_email;
> +	if (open COMMITTER, '<', "${tar_file}.committer")
> +	{
> +		($this_committer_name, $this_committer_email) = <COMMITTER>;
> +		chomp $this_committer_name;
> +		chomp $this_committer_email;
> +		close COMMITTER;
> +	}
> +
> +	# Optionally read an author from <filename.tar>.author
> +	# (first line is name, second line is e-mail address).
> +	my $this_author_name = $author_name;
> +	my $this_author_email = $author_email;
> +	if (open AUTHOR, '<', "${tar_file}.author")
> +	{
> +		($this_author_name, $this_author_email) = <AUTHOR>;
> +		chomp $this_author_name;
> +		chomp $this_author_email;
> +		close AUTHOR;
> +	}
> +
>   

It's not necessary to duplicate code like that.

Also I wonder if there isn't a nicer interface for users.  Why not allow
the file to specify From:, Committer: etc as header lines

	# Optionally read a commit message from <filename.tar>.msg
	my $commit_msg = "Imported from $tar_file.";
	my ($committer, $commit_date, $author, $author_date);
	if (open MSG, '<', "${tar_file}.desc")
	{
		my $state = "header";
		$commit_msg = '';
		my $last_val;
		while (<MSG>)
		{
			if ($state eq "header") {
				if (m{^([A-Z][\w\-]+): (.*)}) {
					my ($header, $value) = $1;
					$last_val = ($header eq "Date" ? \$author_date :
						$header eq "From" ? \$author :
						$header eq "Subject" ? \$commit_msg :
						$header eq "Commit-Date" ? \$commit_date :
						$header eq "Committer" ? \$committer :
						undef );
					if ($last_val) {
						$$last_val = $value;
					}
					else {
						warn "ignoring header '$header' in ${tar_file}.desc line $.\n";
					}
				}
				elsif (m{^\s+(.+)}) {
					if ($last_val) {
						$$last_val .= " $1";
					}
				}
				elsif (m{^\s*$}) {
					$commit_msg .= ($commit_msg ? "\n" : "") . "\n";
					$state = "body";
					next;
				}
			}
			if ($state eq "body") {
				$commit_msg .= $_;
			}
		}
		close MSG;
	}

	($this_committer_name, $this_committer_email) =
		choose_email($committer, $committer_name, $committer_email);
	($this_author_name, $this_author_email) =
		choose_email($author, $author_name, $author_email);

	sub choose_email {
		my ($spec_combined, $def_name, $def_email) = @_;
		return ($def_name, $def_email) unless $spec_combined;
		if ($spec_combined =~ m{^([^<]+) <([^@]+@[^@]+)>$})) {
			($1, $2);
		}
		elsif ($spec_combined =~ m{^([^@]+@[^@]+) \((.*)\)$}) {
			($2, $1);
		}
		else {
			warn "Couldn't parse e-mail address '$spec_combined'";
			($def_name, $def_email);
		}
	}

Something like that, anyway...

Sam



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

  parent reply	other threads:[~2009-08-23 21:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-23 20:34 [PATCH] import-tars: Allow per-tar author and commit message Peter Krefting
2009-08-23 21:24 ` Nanako Shiraishi
2009-08-23 21:46 ` Sam Vilain [this message]
2009-08-24 17:07   ` Peter Krefting
2009-08-24 18:54     ` Junio C Hamano
2009-08-25 18:52       ` Peter Krefting
2009-08-25 19:21         ` Junio C Hamano
2009-08-26  9:17           ` Peter Krefting

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=4A91B8BB.1030906@vilain.net \
    --to=sam@vilain.net \
    --cc=git@vger.kernel.org \
    --cc=peter@softwolves.pp.se \
    /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 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).