git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Add -k option to cvsexportcommit to squash CVS keywords
@ 2009-05-28 13:36 Alex Bennee
  2009-05-31 20:28 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Bennee @ 2009-05-28 13:36 UTC (permalink / raw
  To: git

My CVS repo is converted by parsecvs and although I don't often mess
around in the headers I did hit a problem when exporting some commits
that had removed some lines which would have had an expanded
$Revision$ in a code string.

Rather than make it default behaviour I've added a quick filter to
cvsexportcommit so I don't have to go back to patching and committing
those commits by ahdn :-)


>From a1a9477d6e332617526aaab488602552b77832d9 Mon Sep 17 00:00:00 2001
From: Alex Bennee <alex@bennee.com>
Date: Thu, 28 May 2009 14:31:51 +0100
Subject: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords

Depending on how your CVS->GIT conversion went you will have some
unexpanded CVS keywords in your
GIT repo. If any of your git commits touch these lines then the patch
application will fail. This
patch addresses that by filtering files before applying the patch
---
 Documentation/git-cvsexportcommit.txt |    3 +++
 git-cvsexportcommit.perl              |   31 +++++++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-cvsexportcommit.txt
b/Documentation/git-cvsexportcommit.txt
index 2da8588..b328dd4 100644
--- a/Documentation/git-cvsexportcommit.txt
+++ b/Documentation/git-cvsexportcommit.txt
@@ -63,6 +63,9 @@ OPTIONS
 -u::
 	Update affected files from CVS repository before attempting export.

+-k::
+	Filter CVS keywords (like $Revision$) before applying patch.
+	
 -w::
 	Specify the location of the CVS checkout to use for the export. This
 	option does not require GIT_DIR to be set before execution if the
diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index 6d9f0ef..dd41b0c 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -8,9 +8,9 @@ use File::Basename qw(basename dirname);
 use File::Spec;
 use Git;

-our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m,
$opt_d, $opt_u, $opt_w, $opt_W);
+our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m,
$opt_d, $opt_u, $opt_w, $opt_W, $opt_k);

-getopts('uhPpvcfam:d:w:W');
+getopts('uhPpvcfkam:d:w:W');

 $opt_h && usage();

@@ -266,9 +266,32 @@ foreach my $f (@files) {
 	$dirty = 1;
 	warn "File $f not up to date but has status '$cvsstat{$f}' in your
CVS checkout!\n";
     }
+
+    # Depending on how your GIT tree got imported some of the CVS
+    # expansion keywords would have been squashed. This will break
+    # application of the patch if you touched any lines that had them.
+    if ($opt_k)
+    {
+	my $orig_file ="$f.orig";
+	rename $f, $orig_file;
+	open(FILTER_IN, "<$orig_file") or die "Cannot open $orig_file\n";
+	open(FILTER_OUT, ">$f") or die "Cannot open $f\n";
+	while (<FILTER_IN>)
+	{
+	    my $line = $_;
+	    $line =~ s#\$Revision:[ \.\d]+ \$#\$Revision\$#;
+	    $line =~ s#\$Id: [^\$]+\$#\$Id\$#;
+
+	    print FILTER_OUT $line;
+	}
+	close FILTER_IN;
+	close FILTER_OUT;
+    }
 }
+
 if ($dirty) {
-    if ($opt_f) {	warn "The tree is not clean -- forced merge\n";
+    if ($opt_f) {
+	warn "The tree is not clean -- forced merge\n";
 	$dirty = 0;
     } else {
 	die "Exiting: your CVS tree is not clean for this merge.";
@@ -370,7 +393,7 @@ sleep(1);

 sub usage {
 	print STDERR <<END;
-Usage: GIT_DIR=/path/to/.git git cvsexportcommit [-h] [-p] [-v] [-c]
[-f] [-u] [-w cvsworkdir] [-m msgprefix] [ parent ] commit
+Usage: GIT_DIR=/path/to/.git git cvsexportcommit [-h] [-p] [-v] [-c]
[-f] [-u] [-k] [-w cvsworkdir] [-m msgprefix] [ parent ] commit
 END
 	exit(1);
 }
-- 
1.6.0.2.95.g72d40



-- 
Alex, homepage: http://www.bennee.com/~alex/
CV: http://www.bennee.com/~alex/cv.php

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

* Re: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords
  2009-05-28 13:36 [PATCH] Add -k option to cvsexportcommit to squash CVS keywords Alex Bennee
@ 2009-05-31 20:28 ` Junio C Hamano
  2009-06-01  6:57   ` Alex Bennee
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2009-05-31 20:28 UTC (permalink / raw
  To: Alex Bennee; +Cc: git

Alex Bennee <kernel-hacker@bennee.com> writes:

> My CVS repo is converted by parsecvs and although I don't often mess
> around in the headers I did hit a problem when exporting some commits
> that had removed some lines which would have had an expanded
> $Revision$ in a code string.
>
> Rather than make it default behaviour I've added a quick filter to
> cvsexportcommit so I don't have to go back to patching and committing
> those commits by ahdn :-)
>
>
> From a1a9477d6e332617526aaab488602552b77832d9 Mon Sep 17 00:00:00 2001

Thanks.

You would want to put all the commentary up to here below the "---" line,
if you want to give an introductory text that is not part of your proposed
commit log message.

> From: Alex Bennee <alex@bennee.com>
> Date: Thu, 28 May 2009 14:31:51 +0100
> Subject: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords

You generally do not want these three lines, unless the "From: " your
e-mail shows is different from the name and e-mail of the real author of
the patch.

I presume you would want alex-at-bennee-dot-com in the commit, so in this
case it might be Ok, but then it may be more straightforward to use that
name on the "From: " line of your e-mail to begin with, but on the other
hand, you have a commit as kernel-dash-hacker-at-the-same-domain in our
history already.  If you prefer the latter, you do not need any of the
above three lines (the subject is the same as your e-mail "Subject: "
anyway).

> Depending on how your CVS->GIT conversion went you will have some
> unexpanded CVS keywords in your
> GIT repo. If any of your git commits touch these lines then the patch
> application will fail. This
> patch addresses that by filtering files before applying the patch
> ---

The message is wrapped in a funny way, and it lacks sign-off.

Isn't it "expanded" (not "unexpanded") keyword the problem you are trying
to address?  "By filtering files" in what way?  I can guess "filtering them
back to unexpanded form", but please do not make me guess.

> diff --git a/Documentation/git-cvsexportcommit.txt
> b/Documentation/git-cvsexportcommit.txt
> index 2da8588..b328dd4 100644
> --- a/Documentation/git-cvsexportcommit.txt
> +++ b/Documentation/git-cvsexportcommit.txt
> @@ -63,6 +63,9 @@ OPTIONS
>  -u::
>  	Update affected files from CVS repository before attempting export.
>
> +-k::
> +	Filter CVS keywords (like $Revision$) before applying patch.
> +	

"Filter in what way" applies here as well.

Is it really sufficient to unmunge "$Revision$? and "$Id"?  What about
"$Date$", for example?

> @@ -266,9 +266,32 @@ foreach my $f (@files) {
>  	$dirty = 1;
>  	warn "File $f not up to date but has status '$cvsstat{$f}' in your
> CVS checkout!\n";
>      }
> +
> +    # Depending on how your GIT tree got imported some of the CVS
> +    # expansion keywords would have been squashed. This will break
> +    # application of the patch if you touched any lines that had them.

I am not quite getting this comment.  "Squashed" sounds like "$Revision$"
without expansion instead of "$Revision: 1.4 $"; I thought the issue you
are addressing is that the automated change that comes from the CVS side
to the expanded keyword gets in the way, i.e. if these always were
"squashed", then you would not have to fight with spurious conflicts.

> +    if ($opt_k)
> +    {

This open brace come on the same line as "if", like "if (...) {" to match
the style of the surrounding code.

> +	my $orig_file ="$f.orig";
> +	rename $f, $orig_file;
> +	open(FILTER_IN, "<$orig_file") or die "Cannot open $orig_file\n";
> +	open(FILTER_OUT, ">$f") or die "Cannot open $f\n";
> +	while (<FILTER_IN>)
> +	{
> +	    my $line = $_;
> +	    $line =~ s#\$Revision:[ \.\d]+ \$#\$Revision\$#;
> +	    $line =~ s#\$Id: [^\$]+\$#\$Id\$#;

When there is no '/' in substitution or pattern, it is _far_ easier to
read if you used the standard s/foo/bar/, not custom s#foo#bar#.

Can "$Revision:" immediately be followed by a digit while "$Id:" must
always be followed by a whitespace?  I doubt it.

Why isn't this something like:

	$line =~ s/\$(Revision|Id|Date|....):[^\$]+\$/\$\1\$/g;

or even (not bothering to enumerate the possible set of keywords):

	$line =~ s/\$([A-Z][a-z]+):[^\$]+\$/\$\1\$/g;

> +	    print FILTER_OUT $line;
> +	}
> +	close FILTER_IN;
> +	close FILTER_OUT;
> +    }
>  }
> +
>  if ($dirty) {
> -    if ($opt_f) {	warn "The tree is not clean -- forced merge\n";
> +    if ($opt_f) {
> +	warn "The tree is not clean -- forced merge\n";

This may be a good change, but is distracting, and does not have anything
to do with what you are doing with this patch.

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

* Re: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords
  2009-05-31 20:28 ` Junio C Hamano
@ 2009-06-01  6:57   ` Alex Bennee
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Bennee @ 2009-06-01  6:57 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

2009/5/31 Junio C Hamano <gitster@pobox.com>:
> Alex Bennee <kernel-hacker@bennee.com> writes:
>
>> <snip>
>>
>>
>> From a1a9477d6e332617526aaab488602552b77832d9 Mon Sep 17 00:00:00 2001
>
> Thanks.
>
> You would want to put all the commentary up to here below the "---" line,
> if you want to give an introductory text that is not part of your proposed
> commit log message.

I'm not sure I quite follow. The email is an email with description
above followed by the output of git-format-patch -1. Or should the
email commentary be part of the commit commentary? Should I have just
fired the commit at the mailing list direct from the command line?

>
>> From: Alex Bennee <alex@bennee.com>
>> Date: Thu, 28 May 2009 14:31:51 +0100
>> Subject: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords
>
> You generally do not want these three lines, unless the "From: " your
> e-mail shows is different from the name and e-mail of the real author of
> the patch.
>
> I presume you would want alex-at-bennee-dot-com in the commit, so in this
> case it might be Ok, but then it may be more straightforward to use that
> name on the "From: " line of your e-mail to begin with, but on the other
> hand, you have a commit as kernel-dash-hacker-at-the-same-domain in our
> history already.  If you prefer the latter, you do not need any of the
> above three lines (the subject is the same as your e-mail "Subject: "
> anyway).

Hmmm yes. My actual email is as referenced, kernel-hacker is the alias
I use for my mailing list activity. If people have questions they wish
to email me directly about I would assume the master email makes the
best option for the commit message?

>
>> Depending on how your CVS->GIT conversion went you will have some
>> unexpanded CVS keywords in your
>> GIT repo. If any of your git commits touch these lines then the patch
>> application will fail. This
>> patch addresses that by filtering files before applying the patch
>> ---
>
> The message is wrapped in a funny way, and it lacks sign-off.

Arrgh. It looks like the Google mail client has futzed with it. Trying
to get inline patches not munged by mail clients seems to be an
exercise in frustration. Usually I would create an attachment which
would then stay unmolested, however inline is the preferred posting
style for the list.

I'll resend with a sign-off.

>
> Isn't it "expanded" (not "unexpanded") keyword the problem you are trying
> to address?  "By filtering files" in what way?  I can guess "filtering them
> back to unexpanded form", but please do not make me guess.

The files in the CVS tree will have expanded keywords, in the GIT tree
they will be in the unexpanded state. This patch will return the files
in the working CVS tree to the unexpanded state so the patch from the
GIT tree applies cleanly.

I'll try and re-word to make it clearer.

>
>> diff --git a/Documentation/git-cvsexportcommit.txt
>> b/Documentation/git-cvsexportcommit.txt
>> index 2da8588..b328dd4 100644
>> --- a/Documentation/git-cvsexportcommit.txt
>> +++ b/Documentation/git-cvsexportcommit.txt
>> @@ -63,6 +63,9 @@ OPTIONS
>>  -u::
>>       Update affected files from CVS repository before attempting export.
>>
>> +-k::
>> +     Filter CVS keywords (like $Revision$) before applying patch.
>> +
>
> "Filter in what way" applies here as well.
>
> Is it really sufficient to unmunge "$Revision$? and "$Id"?  What about
> "$Date$", for example?

You're right. Lazily I had only hit the previous cases in the actual
problem files I had. I'll have a dig in the manual and add the rest.

>
>> @@ -266,9 +266,32 @@ foreach my $f (@files) {
>>       $dirty = 1;
>>       warn "File $f not up to date but has status '$cvsstat{$f}' in your
>> CVS checkout!\n";
>>      }
>> +
>> +    # Depending on how your GIT tree got imported some of the CVS
>> +    # expansion keywords would have been squashed. This will break
>> +    # application of the patch if you touched any lines that had them.
>
> I am not quite getting this comment.  "Squashed" sounds like "$Revision$"
> without expansion instead of "$Revision: 1.4 $"; I thought the issue you
> are addressing is that the automated change that comes from the CVS side
> to the expanded keyword gets in the way, i.e. if these always were
> "squashed", then you would not have to fight with spurious conflicts.
>
>> +    if ($opt_k)
>> +    {
>
> This open brace come on the same line as "if", like "if (...) {" to match
> the style of the surrounding code.
>
>> +     my $orig_file ="$f.orig";
>> +     rename $f, $orig_file;
>> +     open(FILTER_IN, "<$orig_file") or die "Cannot open $orig_file\n";
>> +     open(FILTER_OUT, ">$f") or die "Cannot open $f\n";
>> +     while (<FILTER_IN>)
>> +     {
>> +         my $line = $_;
>> +         $line =~ s#\$Revision:[ \.\d]+ \$#\$Revision\$#;
>> +         $line =~ s#\$Id: [^\$]+\$#\$Id\$#;
>
> When there is no '/' in substitution or pattern, it is _far_ easier to
> read if you used the standard s/foo/bar/, not custom s#foo#bar#.

I'd used # as there where \'s to escape some of the meta-characters
and I find large numbers of \/'s hard to follow.

>
> Can "$Revision:" immediately be followed by a digit while "$Id:" must
> always be followed by a whitespace?  I doubt it.
>
> Why isn't this something like:
>
>        $line =~ s/\$(Revision|Id|Date|....):[^\$]+\$/\$\1\$/g;
>
> or even (not bothering to enumerate the possible set of keywords):
>
>        $line =~ s/\$([A-Z][a-z]+):[^\$]+\$/\$\1\$/g;

I bow to your superior regex formulation ;-)

I'll resend in a bit.

-- 
Alex, homepage: http://www.bennee.com/~alex/
CV: http://www.bennee.com/~alex/cv.php

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

end of thread, other threads:[~2009-06-01  6:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-28 13:36 [PATCH] Add -k option to cvsexportcommit to squash CVS keywords Alex Bennee
2009-05-31 20:28 ` Junio C Hamano
2009-06-01  6:57   ` Alex Bennee

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).