From: Alex Bennee <kernel-hacker@bennee.com>
To: git@vger.kernel.org
Subject: [PATCH] Add -k option to cvsexportcommit to squash CVS keywords
Date: Thu, 28 May 2009 14:36:34 +0100 [thread overview]
Message-ID: <b2cdc9f30905280636p404525e2u6f3eb21700b6da66@mail.gmail.com> (raw)
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
next reply other threads:[~2009-05-28 13:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-28 13:36 Alex Bennee [this message]
2009-05-31 20:28 ` [PATCH] Add -k option to cvsexportcommit to squash CVS keywords Junio C Hamano
2009-06-01 6:57 ` Alex Bennee
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=b2cdc9f30905280636p404525e2u6f3eb21700b6da66@mail.gmail.com \
--to=kernel-hacker@bennee.com \
--cc=git@vger.kernel.org \
/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).