{"thread":{"id":"43225","subject":"Re: Set permissions of each new file before \"cvs add\"ing it.","startedAt":"2006-12-03T19:51:27Z","lastAt":"2006-12-04T16:51:49Z","messageCount":5,"participants":["Robin Rosenberg","Junio C Hamano","Jim Meyering"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"297876","messageId":"87ac24zrk0.fsf@rho.meyering.net","threadId":"43225","inReplyTo":null,"subject":"Set permissions of each new file before \"cvs add\"ing it.","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2006-12-03T19:51:27Z","receivedAt":"2006-12-03T19:51:27Z","isPatch":false,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Without the following patch, git-cvsexportcommit would fail to propagate\npermissions of files added in git to the CVS repository.  I.e., when I\nadded an executable script in coreutils' git repo, then tried to propagate\nthat addition to the mirroring CVS repository, the script ended up added\nnot executable there.\n\nSigned-off-by: Jim Meyering <jim@meyering.net>\n---\n git-cvsexportcommit.perl |   19 +++++++++++++++++++\n 1 files changed, 19 insertions(+), 0 deletions(-)\n\ndiff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl\nindex 7bac16e..f819eb2 100755\n--- a/git-cvsexportcommit.perl\n+++ b/git-cvsexportcommit.perl\n@@ -268,6 +268,7 @@ if (($? >> 8) == 2) {\n }\n\n foreach my $f (@afiles) {\n+    set_new_file_permissions($f);\n     if (grep { $_ eq $f } @bfiles) {\n       system('cvs', 'add','-kb',$f);\n     } else {\n@@ -342,3 +343,21 @@ sub safe_pipe_capture {\n     }\n     return wantarray ? @output : join('',@output);\n }\n+\n+# For any file we want to add to cvs, we must first set its permissions\n+# properly, *before* the \"cvs add ...\" command.  Otherwise, it is impossible\n+# to change the permission of the file in the CVS repository using only cvs\n+# commands.  This should be fixed in cvs-1.12.14.\n+sub set_new_file_permissions {\n+    my ($file) = @_;\n+    # Given input like this:\n+    # ba45154d8e9f5f49f46c8c2c2d8a554db7c3465f ...\n+    # :000000 100755 0000000... b595dc6... A  tests/du/one-file-system\n+    # extract the three octal permission digits:\n+    my $cmd = 'git-whatchanged --max-count=1 --pretty=oneline -- $f'\n+      . q! | sed -n '2s/^:00* [0-7][0-7][0-7]\\([0-7][0-7][0-7]\\) .*/\\1/p'!;\n+    my $perm = `$cmd`;\n+\n+    chmod oct($perm), $file\n+      or die \"failed to set permissions of \\\"$file\\\": $!\\n\";\n+}\n--\n"},{"id":"294310","messageId":"7vbqmktmb7.fsf@assigned-by-dhcp.cox.net","threadId":"43225","inReplyTo":"87ac24zrk0.fsf@rho.meyering.net","subject":"Re: Set permissions of each new file before \"cvs add\"ing it.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-04T02:41:16Z","receivedAt":"2006-12-04T02:41:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jim Meyering <jim@meyering.net> writes:\n\n> Without the following patch, git-cvsexportcommit would fail to propagate\n> permissions of files added in git to the CVS repository.  I.e., when I\n> added an executable script in coreutils' git repo, then tried to propagate\n> that addition to the mirroring CVS repository, the script ended up added\n> not executable there.\n\nThanks.  But...\n\n> +# For any file we want to add to cvs, we must first set its permissions\n> +# properly, *before* the \"cvs add ...\" command.  Otherwise, it is impossible\n> +# to change the permission of the file in the CVS repository using only cvs\n> +# commands.  This should be fixed in cvs-1.12.14.\n> +sub set_new_file_permissions {\n> +    my ($file) = @_;\n> +    # Given input like this:\n> +    # ba45154d8e9f5f49f46c8c2c2d8a554db7c3465f ...\n> +    # :000000 100755 0000000... b595dc6... A  tests/du/one-file-system\n> +    # extract the three octal permission digits:\n> +    my $cmd = 'git-whatchanged --max-count=1 --pretty=oneline -- $f'\n> +      . q! | sed -n '2s/^:00* [0-7][0-7][0-7]\\([0-7][0-7][0-7]\\) .*/\\1/p'!;\n> +    my $perm = `$cmd`;\n> +\n> +    chmod oct($perm), $file\n> +      or die \"failed to set permissions of \\\"$file\\\": $!\\n\";\n> +}\n\nWhy sed in a Perl script ;-)?\n"},{"id":"297346","messageId":"7v64cstm0x.fsf@assigned-by-dhcp.cox.net","threadId":"43225","inReplyTo":"7vbqmktmb7.fsf@assigned-by-dhcp.cox.net","subject":"Re: Set permissions of each new file before \"cvs add\"ing it.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-04T02:47:26Z","receivedAt":"2006-12-04T02:47:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Jim Meyering <jim@meyering.net> writes:\n>\n>> Without the following patch, git-cvsexportcommit would fail to propagate\n>> permissions of files added in git to the CVS repository...\n> ...\n> Why sed in a Perl script ;-)?\n\nThat is,...\n\n-- >8 --\n\ndiff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl\nindex 7bac16e..7f70501 100755\n--- a/git-cvsexportcommit.perl\n+++ b/git-cvsexportcommit.perl\n@@ -116,6 +116,7 @@ if ($opt_a) {\n close MSG;\n \n my (@afiles, @dfiles, @mfiles, @dirs);\n+my (%amodes);\n my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);\n #print @files;\n $? && die \"Error in git-diff-tree\";\n@@ -124,6 +125,7 @@ foreach my $f (@files) {\n     my @fields = split(m!\\s+!, $f);\n     if ($fields[4] eq 'A') {\n         my $path = $fields[5];\n+\t$amodes[$path] = $fields[1];\n \tpush @afiles, $path;\n         # add any needed parent directories\n \t$path = dirname $path;\n@@ -268,6 +270,7 @@ if (($? >> 8) == 2) {\n }\n \n foreach my $f (@afiles) {\n+    set_new_file_permissions($f, $amodes[$f]);\n     if (grep { $_ eq $f } @bfiles) {\n       system('cvs', 'add','-kb',$f);\n     } else {\n@@ -342,3 +345,13 @@ sub safe_pipe_capture {\n     }\n     return wantarray ? @output : join('',@output);\n }\n+\n+# For any file we want to add to cvs, we must first set its permissions\n+# properly, *before* the \"cvs add ...\" command.  Otherwise, it is impossible\n+# to change the permission of the file in the CVS repository using only cvs\n+# commands.  This should be fixed in cvs-1.12.14.\n+sub set_new_file_permissions {\n+    my ($file, $perm) = @_;\n+    chmod oct($perm), $file\n+      or die \"failed to set permissions of \\\"$file\\\": $!\\n\";\n+}\n"},{"id":"296918","messageId":"87y7poxfgl.fsf@rho.meyering.net","threadId":"43225","inReplyTo":"7v64cstm0x.fsf@assigned-by-dhcp.cox.net","subject":"Re: Set permissions of each new file before \"cvs add\"ing it.","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2006-12-04T07:55:38Z","receivedAt":"2006-12-04T07:55:38Z","isPatch":false,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Junio C Hamano <junkio@cox.net> writes:\n>\n>> Jim Meyering <jim@meyering.net> writes:\n>>\n>>> Without the following patch, git-cvsexportcommit would fail to propagate\n>>> permissions of files added in git to the CVS repository...\n>> ...\n>> Why sed in a Perl script ;-)?\n\nYeah, yeah, I was rushed.\nThere are existing uses of `git-ls-tree ... | cut ...` :-)\n\nAhh.  Your approach is better.\n\nYour patch works fine (once I changed $amodes[] to $amodes{}).\n> +my (%amodes);\n...\n> +\t$amodes[$path] = $fields[1];\n...\n> +    set_new_file_permissions($f, $amodes[$f]);\n\nI tested it with the following script.\nNew patch below.\n\nThank you!\n\n--------------------------------------------\n#!/bin/sh\nrm -rf g c m\nmkdir g c\ntop=`pwd`\ncvs_repo=$top/c\n(\n  cd g\n  git-init-db\n  touch a\n  git-add a\n  git-commit -m.\n  echo foo > f\n  chmod a+x f\n  git-add f\n  git-commit -m.\n)\ncvs -Q -d $cvs_repo init\nmkdir $cvs_repo/m\ncvs -Q -f -q -d $cvs_repo co m\ncd m\nfail=0\nexport GIT_DIR=$top/g/.git\ngit-cvsexportcommit -c -p -v HEAD\ntest -x f || fail=1\nrm -f f a\ncvs -Q up\ntest -x f || fail=1\ntest -x a && fail=1\nexit $fail\n--------------------------------\nHere's the patch I tested:\n\nFrom: Jim Meyering <jim@meyering.net>\nDate: Mon, 4 Dec 2006 08:44:08 +0100\nSubject: Set permissions of each new file before \"cvs add\"ing it.\nOtherwise, an executable script in git would end up being\nchecked into the CVS repository without the execute bit.\n\nSigned-off-by: Jim Meyering <jim@meyering.net>\n---\n git-cvsexportcommit.perl |   13 +++++++++++++\n 1 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl\nindex 7bac16e..c9d1d88 100755\n--- a/git-cvsexportcommit.perl\n+++ b/git-cvsexportcommit.perl\n@@ -116,6 +116,7 @@ if ($opt_a) {\n close MSG;\n\n my (@afiles, @dfiles, @mfiles, @dirs);\n+my %amodes;\n my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);\n #print @files;\n $? && die \"Error in git-diff-tree\";\n@@ -124,6 +125,7 @@ foreach my $f (@files) {\n     my @fields = split(m!\\s+!, $f);\n     if ($fields[4] eq 'A') {\n         my $path = $fields[5];\n+\t$amodes{$path} = $fields[1];\n \tpush @afiles, $path;\n         # add any needed parent directories\n \t$path = dirname $path;\n@@ -268,6 +270,7 @@ if (($? >> 8) == 2) {\n }\n\n foreach my $f (@afiles) {\n+    set_new_file_permissions($f, $amodes{$f});\n     if (grep { $_ eq $f } @bfiles) {\n       system('cvs', 'add','-kb',$f);\n     } else {\n@@ -342,3 +345,13 @@ sub safe_pipe_capture {\n     }\n     return wantarray ? @output : join('',@output);\n }\n+\n+# For any file we want to add to cvs, we must first set its permissions\n+# properly, *before* the \"cvs add ...\" command.  Otherwise, it is impossible\n+# to change the permission of the file in the CVS repository using only cvs\n+# commands.  This should be fixed in cvs-1.12.14.\n+sub set_new_file_permissions {\n+    my ($file, $perm) = @_;\n+    chmod oct($perm), $file\n+      or die \"failed to set permissions of \\\"$file\\\": $!\\n\";\n+}\n--\n"},{"id":"294075","messageId":"200612041751.49652.robin.rosenberg.lists@dewire.com","threadId":"43225","inReplyTo":"87ac24zrk0.fsf@rho.meyering.net","subject":"Re: Set permissions of each new file before \"cvs add\"ing it.","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2006-12-04T16:51:49Z","receivedAt":"2006-12-04T16:51:49Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"söndag 03 december 2006 20:51 skrev Jim Meyering:\n> Without the following patch, git-cvsexportcommit would fail to propagate\n> permissions of files added in git to the CVS repository.  I.e., when I\n> added an executable script in coreutils' git repo, then tried to propagate\n> that addition to the mirroring CVS repository, the script ended up added\n> not executable there.\n\nThe patch to cvsexportcommit I sent a couple of weeks ago fixes the execution \nbit, along with most other flaws. Jounio had some objections that I haven't \nfixed yet. Hacking the Eclipse plugin was much more fun :)\n\nI added this test case just to verify it on top of my previous patch. \n\n-- robin\n\ndiff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh\nindex 75b9f38..63eafc8 100755\n--- a/t/t9200-git-cvsexportcommit.sh\n+++ b/t/t9200-git-cvsexportcommit.sh\n@@ -195,4 +195,19 @@ test_expect_success \\\n       ! git-cvsexportcommit -c $id\n       )'\n\n+test_expect_success \\\n+     'Retain execute bit' \\\n+     'mkdir G &&\n+      echo executeon >G/on &&\n+      chmod +x G/on &&\n+      echo executeoff >G/off &&\n+      git add G/on &&\n+      git add G/off &&\n+      git commit -a -m \"Execute test\" &&\n+      (cd \"$CVSWORK\" &&\n+      git-cvsexportcommit -c HEAD\n+      test -x G/on &&\n+      ! test -x G/off\n+      )'\n+\n"}]}