git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jim Meyering <jim@meyering.net>
Date
Dec 4, 2006, 07:55 UTC
Message-ID
<87y7poxfgl.fsf@rho.meyering.net>
In-Reply-To
<7v64cstm0x.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 8 quoted lines
> Junio C Hamano <junkio@cox.net> writes:
>
>> Jim Meyering <jim@meyering.net> writes:
>>
>>> 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{}).
> +my (%amodes);
...
> +	$amodes[$path] = $fields[1];
...
> +    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 <jim@meyering.net>
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.
Signed-off-by: Jim Meyering <jim@meyering.net>
---
 git-cvsexportcommit.perl |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index 7bac16e..c9d1d88 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -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";
+}
--
Previous: Junio C HamanoNext: Robin Rosenberg
Message 4 of 5 in “Set permissions of each new file before "cvs add"ing it.”
  1. Jim MeyeringDec 3, 2006
  2. Junio C HamanoDec 4, 2006
  3. Junio C HamanoDec 4, 2006
  4. Jim MeyeringDec 4, 2006
  5. Robin RosenbergDec 4, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.