@matheusbsbs / matheus-bagliano / commits / 648ee55009
Fork 0

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>

Robin Rosenberg committed Oct 31, 2007 at 23:12 UTC 648ee5500920b49a5ee5822076104b9304ec97c8
2 files changed +44 -17
Documentation/git-cvsexportcommit.txt
+17 -5
@@ -8,7 +8,7 @@ git-cvsexportcommit - Export a single commit to a CVS checkout
8
9 SYNOPSIS
10 --------
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
12
13
14 DESCRIPTION
@@ -16,8 +16,9 @@ DESCRIPTION
16 Exports a commit from GIT to a CVS checkout, making it easier
17 to merge patches from a git repository into a CVS repository.
18
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.
22
23 It does its best to do the safe thing, it will check that the files are
24 unchanged and up to date in the CVS checkout, and it will not autocommit
@@ -61,6 +62,11 @@ OPTIONS
62 -u::
63 Update affected files from CVS repository before attempting export.
64
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 +
70 -v::
71 Verbose.
72
@@ -76,6 +82,12 @@ $ git-cvsexportcommit -v <commit-sha1>
82 $ cvs commit -F .msg <files>
83 ------------
84
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 +
91 Merge pending patches into CVS automatically -- only if you really know what you are doing::
92 +
93 ------------
@@ -86,11 +98,11 @@ $ git-cherry cvshead myhead | sed -n 's/^+ //p' | xargs -l1 git-cvsexportcommit
98
99 Author
100 ------
89 -Written by Martin Langhoff <martin@catalyst.net.nz>
101 +Written by Martin Langhoff <martin@catalyst.net.nz> and others.
102
103 Documentation
104 --------------
93 -Documentation by Martin Langhoff <martin@catalyst.net.nz>
105 +Documentation by Martin Langhoff <martin@catalyst.net.nz> and others.
106
107 GIT
108 ---
git-cvsexportcommit.perl
+27 -12
@@ -1,28 +1,42 @@
1 #!/usr/bin/perl -w
2
3 -# Known limitations:
4 -# - does not propagate permissions
5 -# - error handling has not been extensively tested
6 -#
7 -
3 use strict;
4 use Getopt::Std;
5 use File::Temp qw(tempdir);
6 use Data::Dumper;
7 use File::Basename qw(basename dirname);
8
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);
10
20 -getopts('uhPpvcfam:d:');
11 +getopts('uhPpvcfam:d:w:');
12
13 $opt_h && usage();
14
15 die "Need at least one commit identifier!" unless @ARGV;
16
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 +
40 my @cvs;
41 if ($opt_d) {
42 @cvs = ('cvs', '-d', $opt_d);
@@ -274,6 +288,7 @@ if ($dirtypatch) {
288 print "You'll need to apply the patch in .cvsexportcommit.diff manually\n";
289 print "using a patch program. After applying the patch and resolving the\n";
290 print "problems you may commit using:";
291 + print "\n cd \"$opt_w\"" if $opt_w;
292 print "\n $cmd\n\n";
293 exit(1);
294 }
@@ -301,7 +316,7 @@ sleep(1);
316
317 sub usage {
318 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
320 END
321 exit(1);
322 }