git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-svn.perl: Strip ChangeLog bits.

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2008, 21:13 UTC
Message-ID
<7v4p63dstc.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1217701021.8296.35.camel@heerbeest>
Jan Nieuwenhuizen <janneke-list@xs4all.nl> writes:
Show 10 quoted lines
> On za, 2008-08-02 at 10:36 -0700, Junio C Hamano wrote:
>
>> >   You forgot to document your option. (And possibly write a testcase.)
>> 
>> I am not sure if this is generic enough to be in git-svn.perl itself, or
>> perhaps there should be a hook make_log_entry() would call in the form of
>> some Perl scriptlet given by the user to munge $log_entry{log}, which
>> would be very specific to each project.
>
> If you're not sure, please make up your mind.

That's something you would say when I cannot decide the color of bikeshed. I do not think your change falls into that category.

We could add an ad-hoc preprocessing option like this, and keep adding more for different patterns, and at certain point we may be fed up with millions of such options and try to introduce a more generic mechanism. While doing so, the resulting code needs to support the ad-hoc ones that are added earlier, forever.

We've done that in the past with other commands (cc-suppression scheme in send-email comes to mind). It was very unpleasant.

> ...  Doing this in a single
> regexp is a bit tricky and asking a user to write a perl snippet is even
> worse, imho.

What you are saying is that a built-in one, no matter what, won't be sufficient for many projects. Unless a user writes Perl snippet to match his project's needs, the noise at the beginning of the log won't be stripped for him.

That's fine. I do not expect a single built-in transformation would fit everybody's needs. I am not asking for miracles.

But you could at least keep the door open for people who are _willing_ to write such transformation for their projects, right?

For one thing, your --cut-changelog-bits has one fixed pattern. Later people either have to come up with different option, or modify your pattern (potentially breaking your project). Neither is good.

Perhaps doing something like this a (admittedly slightly) better option? It allows you to choose from a canned set, or give a series of s/// rewriting rules (or whatever you would want to have in the custom function)..

---
 git-svn.perl |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index cf6dbbc..eaf6a56 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -66,7 +66,7 @@ my ($_stdin, $_help, $_edit,
 	$_version, $_fetch_all, $_no_rebase,
 	$_merge, $_strategy, $_dry_run, $_local,
 	$_prefix, $_no_checkout, $_url, $_verbose,
-	$_git_format);
+	$_git_format, $_clean_changelog, $_clean_log_message);
 $Git::SVN::_follow_parent = 1;
 my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                     'config-dir=s' => \$Git::SVN::Ra::config_dir,
@@ -109,9 +109,11 @@ my %cmd = (
 	fetch => [ \&cmd_fetch, "Download new revisions from SVN",
 			{ 'revision|r=s' => \$_revision,
 			  'fetch-all|all' => \$_fetch_all,
+			  'clean-changelog=s' => \$_clean_changelog,
 			   %fc_opts } ],
 	clone => [ \&cmd_clone, "Initialize and fetch revisions",
 			{ 'revision|r=s' => \$_revision,
+			  'clean-changelog=s' => \$_clean_changelog,
 			   %fc_opts, %init_opts } ],
 	init => [ \&cmd_init, "Initialize a repo for tracking" .
 			  " (requires URL argument)",
@@ -238,6 +240,33 @@ my $rv = GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version,
                        $Git::SVN::default_repo_id = $_[1] });
 exit 1 if (!$rv && $cmd && $cmd ne 'log');
 
+my %canned_changelog_cleaner =
+(
+ 'ooo' => sub {
+	 local ($_) = @_;
+	 s/(^|\n)\s*((\n|\s)*(199[0-9]|20[0-1][0-9])(-[0-9]{2}){2}\s+.*<.*>\s*\n\s+)?/$1/g;
+	 s/(^|\n)\* /\n$1/g;
+	 s/^[\n\s]*//;
+	 s/\n\s*/ /g if length ($_) < 81;
+	 "\n";
+ }
+);
+
+if (defined $_clean_changelog) {
+	if (exists $canned_changelog_cleaner{$_clean_changelog}) {
+		$_clean_log_message = $canned_changelog_cleaner{$_clean_changelog};
+	} elsif ($_clean_changelog ne '') {
+		$_clean_log_message = eval "
+			sub { local(\$_) = \@_; $_clean_changelog; return \$_; }
+		";
+		if ($@) {
+			die "$!: $_clean_changelog";
+		}
+	} else {
+		die "$_clean_changelog: unknown way to clean log message";
+	}
+}
+
 usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
@@ -2463,6 +2492,9 @@ sub make_log_entry {
 	close $un or croak $!;
 
 	$log_entry{date} = parse_svn_date($log_entry{date});
+	if ($_clean_log_message) {
+		$log_entry{log} = $_clean_log_message->($log_entry{log});
+	}
 	$log_entry{log} .= "\n";
 	my $author = $log_entry{author} = check_author($log_entry{author});
 	my ($name, $email) = defined $::users{$author} ? @{$::users{$author}}
Previous: Jan NieuwenhuizenNext: Jan Nieuwenhuizen
Message 5 of 14 in “git-svn.perl: Strip ChangeLog bits.”
  1. git-svn.perl: Strip ChangeLog bits.Jan Nieuwenhuizen, Aug 2, 2008
  2. Petr BaudisAug 2, 2008
  3. Junio C HamanoAug 2, 2008
  4. Jan NieuwenhuizenAug 2, 2008
  5. Junio C HamanoAug 2, 2008
  6. Jan NieuwenhuizenAug 3, 2008
  7. Junio C HamanoAug 3, 2008
  8. Jan NieuwenhuizenAug 4, 2008
  9. Eric WongAug 4, 2008
  10. Junio C HamanoAug 4, 2008
  11. Jan NieuwenhuizenAug 4, 2008
  12. Eric WongAug 4, 2008
  13. Jan NieuwenhuizenAug 4, 2008
  14. Jan NieuwenhuizenAug 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.