Skip to contentSkip to conversation

import-tars: Allow per-tar author and commit message.

PATCH In review Peter Krefting 4 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 import-tars: Allow per-tar author and commit message.

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

---
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(-)
contrib/fast-import/import-tars.perl +39 -3
index 78e40d2..7aad16f 100755
@@ -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;
+	}
+
 	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
Signature · 1 line
1.6.3.3
#1 lore raw

Quoting Peter Krefting <[email protected]>

Quoted 8 lines

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

Instead of requiring the user to have millions of separate files, how about reading a single metainfo file that may look like this?

[file "git-1.0.0.tar"]
message = "Commit log message for the first revision" author = "A U Thor <[email protected]>"

[file "git-1.0.1.tar"]
message = "Commit log message for the first maintenance revision" author = "F I Xer <[email protected]>"

and give the name of that metainfo file from the command line? The message may be awkward to put in the metainfo file itself, and it might be easier to refer to the name of a file that is outside the metainfo file itself, but the point is that doing so will both reduce the clutter in your folders, and will give people an option to avoid accidentally reading from random files in the same folder as the tar files that unfortunately have names that ends with the suffixes you randomly chose in this patch.

Signature · 2 lines
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
#2 lore raw
In reply to Peter Krefting
Quoted 55 lines · Peter Krefting

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

---
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(-)
contrib/fast-import/import-tars.perl +27 -0
index 78e40d2..7aad16f 100755
@@ -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;

contrib/fast-import/import-tars.perl foreach my $tar_file (@ARGV) · line 148

Quoted 10 lines
contrib/fast-import/import-tars.perl +9 -0
+	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

Quoted 13 lines
contrib/fast-import/import-tars.perl +3 -3
 	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

#3 lore raw

Nanako Shiraishi:

Quoted 1 line

Instead of requiring the user to have millions of separate files, how about reading a single metainfo file that may look like this?

The advantage of having one (or more) files per tarball is that I can use the shell's tab completion to make sure I spell the name of the archive correctly. And that it makes it a lot easier to parse.

Sam Vilain:

Quoted 2 lines

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

Good idea. My initial patch was simple, just using the .msg file to add a message. Then I needed to have a different author for one commit, so I added the .author file. Then came the changes that are in the current import-tars that separates author and committer, hence the .committer file. Somewhere along there it became a bit too complex.

Parsing the .msg file for (optional) committer and author info is probably better. I'll update the patch.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#4 lore raw
Quoted 10 lines · Peter Krefting

Nanako Shiraishi:

Quoted 2 lines

Instead of requiring the user to have millions of separate files, how about reading a single metainfo file that may look like this?

The advantage of having one (or more) files per tarball is that I can use the shell's tab completion to make sure I spell the name of the archive correctly. And that it makes it a lot easier to parse.

Quoted 6 lines

Sam Vilain:

Quoted 2 lines

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

Good idea.

That sounds like a sensible thing to do.

I however am a bit uneasy to see that the patch didn't seem to (and the rerolled one does not seem to, either) allow any way to forbid reading of the .msg files, other than an obvious workaround of running "find | xargs rm" beforehand. Unlike your "import-directories" that is a brand new program without any existing users, you are touching code that other people have already used, and you do not want to change the behaviour for them only because they happen to have unrelated files in the same directory.

#5 lore raw

Junio C Hamano:

Quoted 1 line

Unlike your "import-directories" that is a brand new program without any existing users, you are touching code that other people have already used, and you do not want to change the behaviour for them only because they happen to have unrelated files in the same directory.

Indeed. Not that it is likely that one have stray filetar.gz.msg files just laying around, but I'll add a command line switch to enable the new functinality. That sounds like the most reasonable way to go, leaving the old usage completely unaffected by the change.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#6 lore raw
Quoted 8 lines · Peter Krefting

Junio C Hamano:

Quoted 5 lines

Unlike your "import-directories" that is a brand new program without any existing users, you are touching code that other people have already used, and you do not want to change the behaviour for them only because they happen to have unrelated files in the same directory.

Quoted 4 lines

Indeed. Not that it is likely that one have stray filetar.gz.msg files just laying around, but I'll add a command line switch to enable the new functinality. That sounds like the most reasonable way to go, leaving the old usage completely unaffected by the change.

And the switch could be "--metainfo=<ext>", so that people can choose to use other extensions, e.g. with "--metainfo=info" file.tar.info would be read for descriptions.

#7 lore raw

Junio C Hamano:

Quoted 1 line

And the switch could be "--metainfo=<ext>", so that people can choose to use other extensions, e.g. with "--metainfo=info" file.tar.info would be read for descriptions.

That's a good idea. I just made a simple "-m" switch to enable the new code. I'll change it into a "--metainfo" and post an updated patch later.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/