Skip to content

Commit 4a6b9bb

Browse files
corecodeJunio C Hamano
authored andcommitted
Allow passing of an alternative CVSROOT via -d.
This is necessary if using CVS in an asymmetric fashion, i.e. when the CVSROOT you are checking out from differs from the CVSROOT you have to commit to. Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent d2cd696 commit 4a6b9bb

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

Documentation/git-cvsexportcommit.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-cvsexportcommit - Export a single commit to a CVS checkout
88

99
SYNOPSIS
1010
--------
11-
'git-cvsexportcommit' [-h] [-v] [-c] [-P] [-p] [-a] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID
11+
'git-cvsexportcommit' [-h] [-v] [-c] [-P] [-p] [-a] [-d cvsroot] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID
1212

1313

1414
DESCRIPTION
@@ -43,6 +43,11 @@ OPTIONS
4343
Add authorship information. Adds Author line, and Committer (if
4444
different from Author) to the message.
4545

46+
-d::
47+
Set an alternative CVSROOT to use. This corresponds to the CVS
48+
-d parameter. Usually users will not want to set this, except
49+
if using CVS in an asymmetric fashion.
50+
4651
-f::
4752
Force the merge even if the files are not up to date.
4853

git-cvsexportcommit.perl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
die "GIT_DIR is not defined or is unreadable";
1616
}
1717

18-
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m );
18+
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d);
1919

20-
getopts('hPpvcfam:');
20+
getopts('hPpvcfam:d:');
2121

2222
$opt_h && usage();
2323

2424
die "Need at least one commit identifier!" unless @ARGV;
2525

26+
my @cvs;
27+
if ($opt_d) {
28+
@cvs = ('cvs', '-d', $opt_d);
29+
} else {
30+
@cvs = ('cvs');
31+
}
32+
2633
# setup a tempdir
2734
our ($tmpdir, $tmpdirname) = tempdir('git-cvsapplycommit-XXXXXX',
2835
TMPDIR => 1,
@@ -160,7 +167,7 @@
160167
my $p = $1;
161168
next if (grep { $_ eq $p } @dirs);
162169
}
163-
my @status = grep(m/^File/, safe_pipe_capture('cvs', '-q', 'status' ,$f));
170+
my @status = grep(m/^File/, safe_pipe_capture(@cvs, '-q', 'status' ,$f));
164171
if (@status > 1) { warn 'Strange! cvs status returned more than one line?'};
165172
if (-d dirname $f and $status[0] !~ m/Status: Unknown$/
166173
and $status[0] !~ m/^File: no file /) {
@@ -173,7 +180,7 @@
173180
foreach my $f (@files) {
174181
next if grep { $_ eq $f } @afiles;
175182
# TODO:we need to handle removed in cvs
176-
my @status = grep(m/^File/, safe_pipe_capture('cvs', '-q', 'status' ,$f));
183+
my @status = grep(m/^File/, safe_pipe_capture(@cvs, '-q', 'status' ,$f));
177184
if (@status > 1) { warn 'Strange! cvs status returned more than one line?'};
178185
unless ($status[0] =~ m/Status: Up-to-date$/) {
179186
$dirty = 1;
@@ -194,17 +201,17 @@
194201
print "Patch applied successfully. Adding new files and directories to CVS\n";
195202
my $dirtypatch = 0;
196203
foreach my $d (@dirs) {
197-
if (system('cvs','add',$d)) {
204+
if (system(@cvs,'add',$d)) {
198205
$dirtypatch = 1;
199206
warn "Failed to cvs add directory $d -- you may need to do it manually";
200207
}
201208
}
202209

203210
foreach my $f (@afiles) {
204211
if (grep { $_ eq $f } @bfiles) {
205-
system('cvs', 'add','-kb',$f);
212+
system(@cvs, 'add','-kb',$f);
206213
} else {
207-
system('cvs', 'add', $f);
214+
system(@cvs, 'add', $f);
208215
}
209216
if ($?) {
210217
$dirtypatch = 1;
@@ -213,7 +220,7 @@
213220
}
214221

215222
foreach my $f (@dfiles) {
216-
system('cvs', 'rm', '-f', $f);
223+
system(@cvs, 'rm', '-f', $f);
217224
if ($?) {
218225
$dirtypatch = 1;
219226
warn "Failed to cvs rm -f $f -- you may need to do it manually";
@@ -223,7 +230,7 @@
223230
print "Commit to CVS\n";
224231
print "Patch title (first comment line): $title\n";
225232
my @commitfiles = map { unless (m/\s/) { '\''.$_.'\''; } else { $_; }; } (@files);
226-
my $cmd = "cvs commit -F .msg @commitfiles";
233+
my $cmd = join(' ', @cvs)." commit -F .msg @commitfiles";
227234

228235
if ($dirtypatch) {
229236
print "NOTE: One or more hunks failed to apply cleanly.\n";
@@ -236,7 +243,7 @@
236243

237244
if ($opt_c) {
238245
print "Autocommit\n $cmd\n";
239-
print safe_pipe_capture('cvs', 'commit', '-F', '.msg', @files);
246+
print safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files);
240247
if ($?) {
241248
die "Exiting: The commit did not succeed";
242249
}

0 commit comments

Comments
 (0)