@matheusbsbs / matheus-bagliano / commits / 3f0f756b83
Fork 0

Make cvsexportcommit create parent directories as needed.

This is a quick port of my initial patch for 1.0.7, that I had forgotten to post. Possibly needs some testing before applying to master. Signed-off-by: Yann Dirson <ydirson@altern.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Yann Dirson committed May 27, 2006 at 18:39 UTC 3f0f756b839c5f426fcd85c2b5d09164392b8bf6
1 file changed +32 -5
git-cvsexportcommit.perl
+32 -5
@@ -2,7 +2,6 @@
2
3 # Known limitations:
4 # - cannot add or remove binary files
5 -# - cannot add parent directories when needed
5 # - does not propagate permissions
6 # - tells "ready for commit" even when things could not be completed
7 # (eg addition of a binary file)
@@ -11,7 +10,7 @@ use strict;
10 use Getopt::Std;
11 use File::Temp qw(tempdir);
12 use Data::Dumper;
14 -use File::Basename qw(basename);
13 +use File::Basename qw(basename dirname);
14
15 unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){
16 die "GIT_DIR is not defined or is unreadable";
@@ -91,7 +90,7 @@ close MSG;
90 `git-cat-file commit $commit | sed -e '1,/^\$/d' >> .msg`;
91 $? && die "Error extracting the commit message";
92
94 -my (@afiles, @dfiles, @mfiles);
93 +my (@afiles, @dfiles, @mfiles, @dirs);
94 my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);
95 #print @files;
96 $? && die "Error in git-diff-tree";
@@ -99,7 +98,14 @@ foreach my $f (@files) {
98 chomp $f;
99 my @fields = split(m!\s+!, $f);
100 if ($fields[4] eq 'A') {
102 - push @afiles, $fields[5];
101 + my $path = $fields[5];
102 + push @afiles, $path;
103 + # add any needed parent directories
104 + $path = dirname $path;
105 + while (!-d $path and ! grep { $_ eq $path } @dirs) {
106 + unshift @dirs, $path;
107 + $path = dirname $path;
108 + }
109 }
110 if ($fields[4] eq 'M') {
111 push @mfiles, $fields[5];
@@ -114,13 +120,21 @@ undef @files; # don't need it anymore
120
121 # check that the files are clean and up to date according to cvs
122 my $dirty;
123 +foreach my $d (@dirs) {
124 + if (-e $d) {
125 + $dirty = 1;
126 + warn "$d exists and is not a directory!\n";
127 + }
128 +}
129 foreach my $f (@afiles) {
130 # This should return only one value
131 my @status = grep(m/^File/, safe_pipe_capture('cvs', '-q', 'status' ,$f));
132 if (@status > 1) { warn 'Strange! cvs status returned more than one line?'};
121 - unless ($status[0] =~ m/Status: Unknown$/) {
133 + if (-d dirname $f and $status[0] !~ m/Status: Unknown$/
134 + and $status[0] !~ m/^File: no file /) {
135 $dirty = 1;
136 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";
137 + warn "Status was: $status\n";
138 }
139 }
140 foreach my $f (@mfiles, @dfiles) {
@@ -146,6 +160,19 @@ if ($dirty) {
160 ###
161
162
163 +print "Creating new directories\n";
164 +foreach my $d (@dirs) {
165 + unless (mkdir $d) {
166 + warn "Could not mkdir $d: $!";
167 + $dirty = 1;
168 + }
169 + `cvs add $d`;
170 + if ($?) {
171 + $dirty = 1;
172 + warn "Failed to cvs add directory $d -- you may need to do it manually";
173 + }
174 +}
175 +
176 print "'Patching' binary files\n";
177
178 my @bfiles = grep(m/^Binary/, safe_pipe_capture('git-diff-tree', '-p', $parent, $commit));