Set permissions of each new file before "cvs add"ing it.

Subsystems: the rest

2 messages, 2 authors, 2016-08-11 · open the first message on its own page

Set permissions of each new file before "cvs add"ing it.

From: Jim Meyering <hidden>
Date: 2016-08-11 20:31:58

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.

Signed-off-by: Jim Meyering <redacted>
---
 git-cvsexportcommit.perl |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index 7bac16e..f819eb2 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -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";
+}
--

Re: Set permissions of each new file before "cvs add"ing it.

From: Robin Rosenberg <hidden>
Date: 2016-08-11 19:21:59

söndag 03 december 2006 20:51 skrev 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.
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
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index 75b9f38..63eafc8 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -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
+      )'
+
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help