Skip to content

Commit 648ee55

Browse files
robinrosenberggitster
authored andcommitted
cvsexportcommit: Add switch to specify CVS workdir
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3e4bb08 commit 648ee55

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

Documentation/git-cvsexportcommit.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ git-cvsexportcommit - Export a single commit to a CVS checkout
88

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

1313

1414
DESCRIPTION
1515
-----------
1616
Exports a commit from GIT to a CVS checkout, making it easier
1717
to merge patches from a git repository into a CVS repository.
1818

19-
Execute it from the root of the CVS working copy. GIT_DIR must be defined.
20-
See examples below.
19+
Specify the name of a CVS checkout using the -w switch or execute it
20+
from the root of the CVS working copy. In the latter case GIT_DIR must
21+
be defined. See examples below.
2122

2223
It does its best to do the safe thing, it will check that the files are
2324
unchanged and up to date in the CVS checkout, and it will not autocommit
@@ -61,6 +62,11 @@ OPTIONS
6162
-u::
6263
Update affected files from CVS repository before attempting export.
6364

65+
-w::
66+
Specify the location of the CVS checkout to use for the export. This
67+
option does not require GIT_DIR to be set before execution if the
68+
current directory is within a git repository.
69+
6470
-v::
6571
Verbose.
6672

@@ -76,6 +82,12 @@ $ git-cvsexportcommit -v <commit-sha1>
7682
$ cvs commit -F .msg <files>
7783
------------
7884

85+
Merge one patch into CVS (-c and -w options). The working directory is within the Git Repo::
86+
+
87+
------------
88+
$ git-cvsexportcommit -v -c -w ~/project_cvs_checkout <commit-sha1>
89+
------------
90+
7991
Merge pending patches into CVS automatically -- only if you really know what you are doing::
8092
+
8193
------------
@@ -86,11 +98,11 @@ $ git-cherry cvshead myhead | sed -n 's/^+ //p' | xargs -l1 git-cvsexportcommit
8698

8799
Author
88100
------
89-
Written by Martin Langhoff <martin@catalyst.net.nz>
101+
Written by Martin Langhoff <martin@catalyst.net.nz> and others.
90102

91103
Documentation
92104
--------------
93-
Documentation by Martin Langhoff <martin@catalyst.net.nz>
105+
Documentation by Martin Langhoff <martin@catalyst.net.nz> and others.
94106

95107
GIT
96108
---

git-cvsexportcommit.perl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
#!/usr/bin/perl -w
22

3-
# Known limitations:
4-
# - does not propagate permissions
5-
# - error handling has not been extensively tested
6-
#
7-
83
use strict;
94
use Getopt::Std;
105
use File::Temp qw(tempdir);
116
use Data::Dumper;
127
use File::Basename qw(basename dirname);
138

14-
unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){
15-
die "GIT_DIR is not defined or is unreadable";
16-
}
17-
18-
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u);
9+
our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
1910

20-
getopts('uhPpvcfam:d:');
11+
getopts('uhPpvcfam:d:w:');
2112

2213
$opt_h && usage();
2314

2415
die "Need at least one commit identifier!" unless @ARGV;
2516

17+
if ($opt_w) {
18+
unless ($ENV{GIT_DIR}) {
19+
# Remember where our GIT_DIR is before changing to CVS checkout
20+
my $gd =`git-rev-parse --git-dir`;
21+
chomp($gd);
22+
if ($gd eq '.git') {
23+
my $wd = `pwd`;
24+
chomp($wd);
25+
$gd = $wd."/.git" ;
26+
}
27+
$ENV{GIT_DIR} = $gd;
28+
}
29+
30+
if (! -d $opt_w."/CVS" ) {
31+
die "$opt_w is not a CVS checkout";
32+
}
33+
chdir $opt_w or die "Cannot change to CVS checkout at $opt_w";
34+
}
35+
unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){
36+
die "GIT_DIR is not defined or is unreadable";
37+
}
38+
39+
2640
my @cvs;
2741
if ($opt_d) {
2842
@cvs = ('cvs', '-d', $opt_d);
@@ -274,6 +288,7 @@
274288
print "You'll need to apply the patch in .cvsexportcommit.diff manually\n";
275289
print "using a patch program. After applying the patch and resolving the\n";
276290
print "problems you may commit using:";
291+
print "\n cd \"$opt_w\"" if $opt_w;
277292
print "\n $cmd\n\n";
278293
exit(1);
279294
}
@@ -301,7 +316,7 @@
301316

302317
sub usage {
303318
print STDERR <<END;
304-
Usage: GIT_DIR=/path/to/.git ${\basename $0} [-h] [-p] [-v] [-c] [-f] [-m msgprefix] [ parent ] commit
319+
Usage: GIT_DIR=/path/to/.git ${\basename $0} [-h] [-p] [-v] [-c] [-f] [-u] [-w cvsworkdir] [-m msgprefix] [ parent ] commit
305320
END
306321
exit(1);
307322
}

0 commit comments

Comments
 (0)