From: Nick Woolley <nickwoolley@yahoo.co.uk>
To: git@vger.kernel.org
Subject: [PATCH] git-cvsexportcommit can't commit files which have been removed from CVS
Date: Fri, 29 May 2009 00:23:33 +0100 [thread overview]
Message-ID: <4A1F1CF5.8030002@yahoo.co.uk> (raw)
If a file X is removed from CVS, it goes into the Attic directory, and
CVS reports it as 'no file X' but with status 'Up-to-date'. This is
misinterpreted an existing file when git-cvsexportcommit tries to commit a file
with the same name as one of these. This patch attempts to correctly identify
these files, so that new files with the same name can be committed.
Added a test to t9200-git-cvsexportcommit.sh, which tests that we can
re-commit a removed filename which remains in CVS's attic. This adds a
file 'attic_gremlin' in CVS, then "removes" it, then tries to commit a
file with the same name from git.
Signed-off-by: Nick Woolley <git.wu-lee@noodlefactory.co.uk>
---
git-cvsexportcommit.perl | 49 ++++++++++++++++++++++++++++-----------
t/t9200-git-cvsexportcommit.sh | 18 ++++++++++++++
2 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index 6d9f0ef..e5e8ca9 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -225,7 +225,14 @@ if (@canstatusfiles) {
foreach my $name (keys %todo) {
my $basename = basename($name);
- $basename = "no file " . $basename if (exists($added{$basename}));
+ # CVS reports files which are "status"ed which don't exist
+ # in the current revision as "no file $basename", so we
+ # should anticipate that. Totally unknown files will have
+ # a status "Unknown". However, if they exist in the attic
+ # their status will be "Up-to-date" (this means they were
+ # added once but have been removed).
+ $basename = "no file $basename" if $added{$basename};
+
$basename =~ s/^\s+//;
$basename =~ s/\s+$//;
@@ -233,31 +240,45 @@ if (@canstatusfiles) {
$fullname{$basename} = $name;
push (@canstatusfiles2, $name);
delete($todo{$name});
- }
+ }
}
my @cvsoutput;
@cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles2);
foreach my $l (@cvsoutput) {
- chomp $l;
- if ($l =~ /^File:\s+(.*\S)\s+Status: (.*)$/) {
- if (!exists($fullname{$1})) {
- print STDERR "Huh? Status reported for unexpected file '$1'\n";
- } else {
- $cvsstat{$fullname{$1}} = $2;
- }
- }
+ chomp $l;
+ next unless
+ my ($file, $status) = $l =~ /^File:\s+(.*\S)\s+Status: (.*)$/;
+
+ my $fullname = $fullname{$file};
+ print STDERR "Huh? Status '$status' reported for unexpected file '$file'\n"
+ unless defined $fullname;
+
+ # This response means the file does not exist except in
+ # CVS's attic, so set the status accordingly
+ $status = "In-attic"
+ if $file =~ /^no file /
+ && $status eq 'Up-to-date';
+
+ $cvsstat{$fullname{$file}} = $status;
}
}
}
-# ... validate new files,
+# ... Validate new files have the correct status
foreach my $f (@afiles) {
- if (defined ($cvsstat{$f}) and $cvsstat{$f} ne "Unknown") {
- $dirty = 1;
+ next unless defined(my $stat = $cvsstat{$f});
+
+ # This means the file has never been seen before
+ next if $stat eq 'Unknown';
+
+ # This means the file has been seen before but was removed
+ next if $stat eq 'In-attic';
+
+ $dirty = 1;
warn "File $f is already known in your CVS checkout -- perhaps it has been
added by another user. Or this may indicate that it exists on a different
branch. If this is the case, use -f to force the merge.\n";
warn "Status was: $cvsstat{$f}\n";
- }
}
+
# ... validate known files.
foreach my $f (@files) {
next if grep { $_ eq $f } @afiles;
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index 56b7c06..ef1f8d2 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -317,4 +317,22 @@ test_expect_success 'use the same checkout for Git and CVS' '
'
+test_expect_success 're-commit a removed filename which remains in CVS attic' '
+
+ (cd "$CVSWORK" &&
+ echo >attic_gremlin &&
+ cvs -Q add attic_gremlin &&
+ cvs -Q ci -m "added attic_gremlin" &&
+ rm attic_gremlin &&
+ cvs -Q rm attic_gremlin &&
+ cvs -Q ci -m "removed attic_gremlin") &&
+
+ echo > attic_gremlin &&
+ git add attic_gremlin &&
+ git commit -m "Added attic_gremlin" &&
+ git cvsexportcommit -w "$CVSWORK" -c HEAD &&
+ (cd "$CVSWORK"; cvs -Q update -d) &&
+ test -f "$CVSWORK/attic_gremlin"
+'
+
test_done
next reply other threads:[~2009-05-28 23:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-28 23:23 Nick Woolley [this message]
2009-06-10 8:06 ` [PATCH] git-cvsexportcommit can't commit files which have been removed from CVS Mike Ralphson
2009-06-11 14:10 ` Nick Woolley
2009-06-11 15:45 ` Junio C Hamano
2009-06-11 15:49 ` Junio C Hamano
2009-06-11 17:04 ` Junio C Hamano
2009-06-12 6:59 ` Robin Rosenberg
2009-07-02 13:50 ` Mike Ralphson
2009-07-06 13:23 ` Nick Woolley
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=4A1F1CF5.8030002@yahoo.co.uk \
--to=nickwoolley@yahoo.co.uk \
--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).