Set permissions of each new file before "cvs add"ing it.
söndag 03 december 2006 20:51 skrev Jim Meyering:
Quoted 5 lines
Without the following patch, git-cvsexportcommit would fail to propagate permissions of files added in git to the CVS repository. I.e., when I added an executable script in coreutils' git repo, then tried to propagate that addition to the mirroring CVS repository, the script ended up added not executable there.
The patch to cvsexportcommit I sent a couple of weeks ago fixes the execution bit, along with most other flaws. Jounio had some objections that I haven't fixed yet. Hacking the Eclipse plugin was much more fun :)
I added this test case just to verify it on top of my previous patch.
-- robin
t/t9200-git-cvsexportcommit.sh +15 -0
@@ -195,4 +195,19 @@ test_expect_success \ ! git-cvsexportcommit -c $id )' +test_expect_success \ + 'Retain execute bit' \ + 'mkdir G && + echo executeon >G/on && + chmod +x G/on && + echo executeoff >G/off && + git add G/on && + git add G/off && + git commit -a -m "Execute test" && + (cd "$CVSWORK" && + git-cvsexportcommit -c HEAD + test -x G/on && + ! test -x G/off + )' +
Quoted 5 lines · Jim Meyering
Without the following patch, git-cvsexportcommit would fail to propagate permissions of files added in git to the CVS repository. I.e., when I added an executable script in coreutils' git repo, then tried to propagate that addition to the mirroring CVS repository, the script ended up added not executable there.
Thanks. But...
Quoted 7 lines
git-cvsexportcommit.perl +7
-0+# For any file we want to add to cvs, we must first set its permissions +# properly, *before* the "cvs add ..." command. Otherwise, it is impossible +# to change the permission of the file in the CVS repository using only cvs +# commands. This should be fixed in cvs-1.12.14. +sub set_new_file_permissions { + my ($file) = @_; + # Given input like this:
git-cvsexportcommit.perl sub safe_pipe_capture { · line 363
Quoted 10 lines
git-cvsexportcommit.perl +10
-0+ # ba45154d8e9f5f49f46c8c2c2d8a554db7c3465f ... + # :000000 100755 0000000... b595dc6... A tests/du/one-file-system + # extract the three octal permission digits: + my $cmd = 'git-whatchanged --max-count=1 --pretty=oneline -- $f' + . q! | sed -n '2s/^:00* [0-7][0-7][0-7]\([0-7][0-7][0-7]\) .*/\1/p'!; + my $perm = `$cmd`; + + chmod oct($perm), $file + or die "failed to set permissions of \"$file\": $!\n"; +}
Why sed in a Perl script ;-)?
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Jim Meyering
Without the following patch, git-cvsexportcommit would fail to propagate permissions of files added in git to the CVS repository...
...
Why sed in a Perl script ;-)?
Yeah, yeah, I was rushed.
There are existing uses of git-ls-tree ... | cut ... :-)
Ahh. Your approach is better.
Your patch works fine (once I changed $amodes[] to $amodes{}).
Quoted 1 line
+my (%amodes);
...
Quoted 1 line
(quoted diff) +1
-0+ $amodes[$path] = $fields[1];
...
Quoted 1 line
+
set_new_file_permissions($f, $amodes[$f]);
I tested it with the following script.
New patch below.
Thank you!
--------------------------------------------
#!/bin/sh
rm -rf g c m
mkdir g c
top=pwd
cvs_repo=$top/c
(
cd g
git-init-db
touch a
git-add a
git-commit -m.
echo foo > f
chmod a+x f
git-add f
git-commit -m.
)
cvs -Q -d $cvs_repo init
mkdir $cvs_repo/m
cvs -Q -f -q -d $cvs_repo co m
cd m
fail=0
export GIT_DIR=$top/g/.git
git-cvsexportcommit -c -p -v HEAD
test -x f || fail=1
rm -f f a
cvs -Q up
test -x f || fail=1
test -x a && fail=1
exit $fail
--------------------------------
Here's the patch I tested:
From: Jim Meyering <[email protected]>
Date: Mon, 4 Dec 2006 08:44:08 +0100
Subject: Set permissions of each new file before "cvs add"ing it. Otherwise, an executable script in git would end up being checked into the CVS repository without the execute bit.
--- git-cvsexportcommit.perl | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
git-cvsexportcommit.perl +13 -0
@@ -116,6 +116,7 @@ if ($opt_a) { close MSG; my (@afiles, @dfiles, @mfiles, @dirs); +my %amodes; my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit); #print @files; $? && die "Error in git-diff-tree";
@@ -124,6 +125,7 @@ foreach my $f (@files) { my @fields = split(m!\s+!, $f); if ($fields[4] eq 'A') { my $path = $fields[5]; + $amodes{$path} = $fields[1]; push @afiles, $path; # add any needed parent directories $path = dirname $path;
@@ -268,6 +270,7 @@ if (($? >> 8) == 2) { } foreach my $f (@afiles) { + set_new_file_permissions($f, $amodes{$f}); if (grep { $_ eq $f } @bfiles) { system('cvs', 'add','-kb',$f); } else {
@@ -342,3 +345,13 @@ sub safe_pipe_capture { } return wantarray ? @output : join('',@output); } + +# For any file we want to add to cvs, we must first set its permissions +# properly, *before* the "cvs add ..." command. Otherwise, it is impossible +# to change the permission of the file in the CVS repository using only cvs +# commands. This should be fixed in cvs-1.12.14. +sub set_new_file_permissions { + my ($file, $perm) = @_; + chmod oct($perm), $file + or die "failed to set permissions of \"$file\": $!\n"; +}
--
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Jim Meyering
Without the following patch, git-cvsexportcommit would fail to propagate permissions of files added in git to the CVS repository...
...
Why sed in a Perl script ;-)?
That is,...
-- >8 --
git-cvsexportcommit.perl +13 -0
@@ -116,6 +116,7 @@ if ($opt_a) { close MSG; my (@afiles, @dfiles, @mfiles, @dirs); +my (%amodes); my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit); #print @files; $? && die "Error in git-diff-tree";
@@ -124,6 +125,7 @@ foreach my $f (@files) { my @fields = split(m!\s+!, $f); if ($fields[4] eq 'A') { my $path = $fields[5]; + $amodes[$path] = $fields[1]; push @afiles, $path; # add any needed parent directories $path = dirname $path;
@@ -268,6 +270,7 @@ if (($? >> 8) == 2) { } foreach my $f (@afiles) { + set_new_file_permissions($f, $amodes[$f]); if (grep { $_ eq $f } @bfiles) { system('cvs', 'add','-kb',$f); } else {
@@ -342,3 +345,13 @@ sub safe_pipe_capture { } return wantarray ? @output : join('',@output); } + +# For any file we want to add to cvs, we must first set its permissions +# properly, *before* the "cvs add ..." command. Otherwise, it is impossible +# to change the permission of the file in the CVS repository using only cvs +# commands. This should be fixed in cvs-1.12.14. +sub set_new_file_permissions { + my ($file, $perm) = @_; + chmod oct($perm), $file + or die "failed to set permissions of \"$file\": $!\n"; +}
Without the following patch, git-cvsexportcommit would fail to propagate permissions of files added in git to the CVS repository. I.e., when I added an executable script in coreutils' git repo, then tried to propagate that addition to the mirroring CVS repository, the script ended up added not executable there.
--- git-cvsexportcommit.perl | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
git-cvsexportcommit.perl +19 -0
@@ -268,6 +268,7 @@ if (($? >> 8) == 2) { } foreach my $f (@afiles) { + set_new_file_permissions($f); if (grep { $_ eq $f } @bfiles) { system('cvs', 'add','-kb',$f); } else {
@@ -342,3 +343,21 @@ sub safe_pipe_capture { } return wantarray ? @output : join('',@output); } + +# For any file we want to add to cvs, we must first set its permissions +# properly, *before* the "cvs add ..." command. Otherwise, it is impossible +# to change the permission of the file in the CVS repository using only cvs +# commands. This should be fixed in cvs-1.12.14. +sub set_new_file_permissions { + my ($file) = @_; + # Given input like this: + # ba45154d8e9f5f49f46c8c2c2d8a554db7c3465f ... + # :000000 100755 0000000... b595dc6... A tests/du/one-file-system + # extract the three octal permission digits: + my $cmd = 'git-whatchanged --max-count=1 --pretty=oneline -- $f' + . q! | sed -n '2s/^:00* [0-7][0-7][0-7]\([0-7][0-7][0-7]\) .*/\1/p'!; + my $perm = `$cmd`; + + chmod oct($perm), $file + or die "failed to set permissions of \"$file\": $!\n"; +}
--