* [PATCH] cvsimport: new -R option: generate revision-to-commit mapping
@ 2010-01-31 12:43 Aaron Crane
2010-01-31 13:24 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: Aaron Crane @ 2010-01-31 12:43 UTC (permalink / raw)
To: git
Signed-off-by: Aaron Crane <git@aaroncrane.co.uk>
---
See also the thread beginning at
http://thread.gmane.org/gmane.comp.version-control.git/138079
This is my first Git submission, so I'd welcome any comments, especially
if there's something wrong with the way I'm sending this.
Documentation/git-cvsimport.txt | 15 ++++++++++++++-
git-cvsimport.perl | 20 ++++++++++++++++----
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt
index ddfcb3d..19e8c9f 100644
--- a/Documentation/git-cvsimport.txt
+++ b/Documentation/git-cvsimport.txt
@@ -13,7 +13,7 @@ SYNOPSIS
[-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
[-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
[-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
- [-r <remote>] [<CVS_module>]
+ [-r <remote>] [-R <revision-to-commit-file>] [<CVS_module>]
DESCRIPTION
@@ -157,6 +157,19 @@ It is not recommended to use this feature if you intend to
export changes back to CVS again later with
'git cvsexportcommit'.
+-R <revision-to-commit-file>::
+ Generate a file containing a mapping from CVS revision numbers to
+ newly-created Git commit IDs. The generated file will contain one
+ line for each (filename, revision) pair found by 'cvsps'; each line
+ will look like
++
+---------
+src/widget.c 1.1 1d862f173cdc7325b6fa6d2ae1cfd61fd1b512b7
+---------
++
+This option may be useful if you have CVS revision numbers stored in commit
+messages, bug-tracking systems, email archives, and the like.
+
-h::
Print a short usage message and exit.
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 4853bf7..8ef89c6 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -29,7 +29,7 @@ use IPC::Open2;
$SIG{'PIPE'}="IGNORE";
$ENV{'TZ'}="UTC";
-our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P,
$opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r);
+our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P,
$opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R);
my (%conv_author_name, %conv_author_email);
sub usage(;$) {
@@ -40,7 +40,7 @@ Usage: git cvsimport # fetch/update GIT from CVS
[-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
[-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
[-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
- [-r remote] [CVS_module]
+ [-r remote] [-R revision-to-commit-file] [CVS_module]
END
exit(1);
}
@@ -110,7 +110,7 @@ sub read_repo_config {
}
}
-my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:";
+my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:R:";
read_repo_config($opts);
Getopt::Long::Configure( 'no_ignore_case', 'bundling' );
@@ -175,6 +175,10 @@ if (@opt_M) {
push (@mergerx, map { qr/$_/ } @opt_M);
}
+open my $revision_map, '>', $opt_R
+ or die "Can't open -R file $opt_R: $!\n"
+ if defined $opt_R;
+
# Remember UTC of our starting time
# we'll want to avoid importing commits
# that are too recent
@@ -742,7 +746,7 @@ sub write_tree () {
}
my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
-my (@old,@new,@skipped,%ignorebranch);
+my (@old,@new,@skipped,%ignorebranch,@commit_revisions);
# commits that cvsps cannot place anywhere...
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
@@ -825,6 +829,11 @@ sub commit {
system('git' , 'update-ref', "$remote/$branch", $cid) == 0
or die "Cannot write branch $branch for update: $!\n";
+ if ($revision_map) {
+ print $revision_map "@$_ $cid\n" for @commit_revisions;
+ }
+ @commit_revisions = ();
+
if ($tag) {
my ($xtag) = $tag;
$xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
@@ -959,6 +968,7 @@ while (<CVS>) {
push(@skipped, $fn);
next;
}
+ push @commit_revisions, [$fn, $rev];
print "Fetching $fn v $rev\n" if $opt_v;
my ($tmpname, $size) = $cvs->file($fn,$rev);
if ($size == -1) {
@@ -981,7 +991,9 @@ while (<CVS>) {
unlink($tmpname);
} elsif ($state == 9 and
/^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
my $fn = $1;
+ my $rev = $2;
$fn =~ s#^/+##;
+ push @commit_revisions, [$fn, $rev];
push(@old,$fn);
print "Delete $fn\n" if $opt_v;
} elsif ($state == 9 and /^\s*$/) {
--
1.6.6.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cvsimport: new -R option: generate revision-to-commit mapping
2010-01-31 12:43 [PATCH] cvsimport: new -R option: generate revision-to-commit mapping Aaron Crane
@ 2010-01-31 13:24 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2010-01-31 13:24 UTC (permalink / raw)
To: Aaron Crane; +Cc: git
On Sun, Jan 31, 2010 at 12:43:44PM +0000, Aaron Crane wrote:
> Signed-off-by: Aaron Crane <git@aaroncrane.co.uk>
> ---
Please put a bit of the rationale into the commit message. Even a
sentence or two can help later on when somebody is reading the output of
"git log".
> Documentation/git-cvsimport.txt | 15 ++++++++++++++-
> git-cvsimport.perl | 20 ++++++++++++++++----
> 2 files changed, 30 insertions(+), 5 deletions(-)
A basic test would be nice. You should be able to just use your new "-R"
during the import in t9600, and then check that it generated the correct
mapping.
> +-R <revision-to-commit-file>::
> + Generate a file containing a mapping from CVS revision numbers to
> + newly-created Git commit IDs. The generated file will contain one
> + line for each (filename, revision) pair found by 'cvsps'; each line
> + will look like
Is mentioning 'cvsps' right here? cvsps doesn't know about git commit
id's.
> +open my $revision_map, '>', $opt_R
> + or die "Can't open -R file $opt_R: $!\n"
> + if defined $opt_R;
You need to use munge_user_filename here to handle relative paths. See
commit f6fdbb6.
Also, should you perhaps be appending to the file instead of truncating
it? Remember that cvsimport can be used incrementally. I wonder if it
would be better to simply have "-R" without an argument to append the
revision map to a file .git/cvs-revisions or something. And then the
user can easily pull it from there after the import.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-31 13:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-31 12:43 [PATCH] cvsimport: new -R option: generate revision-to-commit mapping Aaron Crane
2010-01-31 13:24 ` Jeff King
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).