Git development
 help / color / mirror / Atom feed
* [PATCH 1/2] t7005-editor: Use $SHELL_PATH in the editor scripts
From: Johannes Sixt @ 2009-03-25 20:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

The test sets up various shell scripts and uses them as commit message
editors.  On Windows, we need a shebang line in order to recognize the
files as executable shell scripts.  This adds it.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 This one and the next patch can go on top of js/windows-tests.
 Or you again pull from

   git://repo.or.cz/git/mingw/j6t.git for-junio

 -- Hannes

 t/t7005-editor.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
index 2f8404a..e83bc8f 100755
--- a/t/t7005-editor.sh
+++ b/t/t7005-editor.sh
@@ -7,6 +7,7 @@ test_description='GIT_EDITOR, core.editor, and stuff'
 for i in GIT_EDITOR core_editor EDITOR VISUAL vi
 do
 	cat >e-$i.sh <<-EOF
+	#!$SHELL_PATH
 	echo "Edited by $i" >"\$1"
 	EOF
 	chmod +x e-$i.sh
-- 
1.6.2.1.224.g2225f

^ permalink raw reply related

* [PATCH 2/2] t7502-commit: Skip SIGTERM test on Windows
From: Johannes Sixt @ 2009-03-25 20:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <200903252131.26561.j6t@kdbg.org>

The implementation of exec on Windows is just a rough approximation of the
POSIX behavior. In particular, no real process "overlay" happens (a new
process is spawned instead and the parent process waits until the child
terminates). In particular, the process ID cannot be taken by the exec'd
process. But there is one test in t7502-commit.sh that depends on this.
We have to skip it on Windows.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 t/t7502-commit.sh |    2 +-
 t/test-lib.sh     |    2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index ad42c78..56cd866 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -234,7 +234,7 @@ cat >.git/FAKE_EDITOR <<EOF
 # kill -TERM command added below.
 EOF
 
-test_expect_success 'a SIGTERM should break locks' '
+test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
 	echo >>negative &&
 	! "$SHELL_PATH" -c '\''
 	  echo kill -TERM $$ >> .git/FAKE_EDITOR
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 8de5ee1..2979e8e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -697,10 +697,12 @@ case $(uname -s) in
 	}
 	# no POSIX permissions
 	# backslashes in pathspec are converted to '/'
+	# exec does not inherit the PID
 	;;
 *)
 	test_set_prereq POSIXPERM
 	test_set_prereq BSLASHPSPEC
+	test_set_prereq EXECKEEPSPID
 	;;
 esac
 
-- 
1.6.2.1.224.g2225f

^ permalink raw reply related

* Re: [PATCH 4/5] Draft of API for git-vcs-*, transport.c code to use it.
From: Daniel Barkalow @ 2009-03-25 20:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7vskl1xuez.fsf@gitster.siamese.dyndns.org>

On Wed, 25 Mar 2009, Junio C Hamano wrote:

> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> > On Wed, 25 Mar 2009, Junio C Hamano wrote:
> >
> >> Suppose a project used to use subversion, but it migrated to git (not an
> >> unheard-of scenario these days, I hope).  The git repository now is the
> >> authoritative one, all the development happens on this side.
> >> 
> >> But in order to help:
> >> 
> >>  - people who have established their workflow to follow the project
> >>    (e.g. not necessarily contributing anything back, but just doing
> >>    regular "svn update");
> >> 
> >>  - people who have leftover local changes from the subversion days; and
> >> 
> >>  - other project infrastracture (e.g. trac) that the project hasn't
> >>    managed to interface to the new git repository yet;
> >> 
> >> the project decides to keep feeding recent updates to the subversion
> >> repository that used to be authoritative, even though it is now declared
> >> read-only (i.e. the only update comes from the git end).
> >
> > Actually, this is easy: just configure the git repo to not fetch anything 
> > from the no-longer-authoritative subversion repository. git-vcs-svn would 
> > waste a bunch of time reimporting what it exported, but it wouldn't 
> > actually do anything with it (since it doesn't even have tracking refs to 
> > update). It could, of course, be optimized to avoid reimporting if it 
> > doesn't need to.
> 
> I am afraid that won't fly; my comment that started this subthread was not
> about your "import" but was about your "export" part.  It is about sending
> the git branch to the other end, which is allowed to rewrite what we send
> and force us to modify our history.

It can rewrite what we send, but if we're not reimporting it, we don't 
care what it's done. All we care about is that when we ignore the 
rewriting, git-vcs-* can still export more changes from our version of the 
history.

That is, if we push X, which gets rewritten to X' (but we ignore that), 
and we then push Y, whose parent is X (not X'), a high-quality git-vcs 
backend will be reliably able to accept the second push, just as if we'd 
created a Y' based on X'. And by "high-quality", I mean some testable 
capability with a better name.

	-Daniel
*This .sig left intentionally blank*

^ permalink raw reply

* Re: reverting initial commit
From: Sverre Rabbelier @ 2009-03-25 20:40 UTC (permalink / raw)
  To: Giuseppe Bilotta; +Cc: git
In-Reply-To: <gqe1kf$pg1$1@ger.gmane.org>

Heya,

On Wed, Mar 25, 2009 at 20:45, Giuseppe Bilotta
<giuseppe.bilotta@gmail.com> wrote:
> I wish there was a way to tell rebase -i to go back to the first commit,
> inclusive, but the two or three times I've tried hacking at it I never
> managed to come to anything useful 8-/

Wasn't --root added to rebase -i recently?

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply

* [PATCH] fast-export: Avoid dropping files from commits
From: newren @ 2009-03-25 20:55 UTC (permalink / raw)
  To: git; +Cc: Johannes.Schindelin, gitster, Elijah Newren

From: Elijah Newren <newren@gmail.com>

When exporting a subset of commits on a branch that do not go back to a
root commit (e.g. master~2..master), we still want each exported commit to
have the same files in the exported tree as in the original tree.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin-fast-export.c  |    3 ++-
 t/t9301-fast-export.sh |    7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index fdf4ae9..34a419c 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -221,7 +221,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
 	if (message)
 		message += 2;
 
-	if (commit->parents) {
+	if (commit->parents &&
+	    get_object_mark(&commit->parents->item->object) != 0) {
 		parse_commit(commit->parents->item);
 		diff_tree_sha1(commit->parents->item->tree->object.sha1,
 			       commit->tree->object.sha1, "", &rev->diffopt);
diff --git a/t/t9301-fast-export.sh b/t/t9301-fast-export.sh
index 86c3760..b860626 100755
--- a/t/t9301-fast-export.sh
+++ b/t/t9301-fast-export.sh
@@ -8,6 +8,9 @@ test_description='git fast-export'
 
 test_expect_success 'setup' '
 
+	echo break it > file0 &&
+	git add file0 &&
+	test_tick &&
 	echo Wohlauf > file &&
 	git add file &&
 	test_tick &&
@@ -57,8 +60,8 @@ test_expect_success 'fast-export master~2..master' '
 		(cd new &&
 		 git fast-import &&
 		 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
-		 git diff master..partial &&
-		 git diff master^..partial^ &&
+		 git diff --exit-code master partial &&
+		 git diff --exit-code master^ partial^ &&
 		 test_must_fail git rev-parse partial~2)
 
 '
-- 
1.6.0.6

^ permalink raw reply related

* Re: reverting initial commit
From: Eric Raible @ 2009-03-25 21:06 UTC (permalink / raw)
  To: git
In-Reply-To: <gqe1kf$pg1$1@ger.gmane.org>

Giuseppe Bilotta <giuseppe.bilotta <at> gmail.com> writes:

> Actually, rebase --interactive cannot be used to amend the first commit.
> This is something that has hit me a couple of times when I realised, after
> the second or third commit, that I needed to fix the first one. I found
> the fastest way in this case to be to just format-patch all but the first
> commit, reset --hard to the first commit, amend, and git am what I format-
> patched.
> 
> I wish there was a way to tell rebase -i to go back to the first commit,
> inclusive, but the two or three times I've tried hacking at it I never
> managed to come to anything useful 8-/

I like to be able to rebase -i back to the first commit as well,
which is why I generally start off with:

git init && git commit --allow-empty -m'initial commit'

- Eric

^ permalink raw reply

* [PATCH] git-filter-branch: avoid collisions with variables in eval'ed commands
From: newren @ 2009-03-25 21:13 UTC (permalink / raw)
  To: git; +Cc: Johannes.Schindelin, gitster, pasky, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Avoid using simple variable names like 'i', since user commands are eval'ed
and may clash with and overwrite our values.

Signed-off-by: Elijah Newren <newren@gmail.com>
---

I discovered this a few months ago, but apparently never got around to
sending it earlier.  Anyway, without this patch in a repository with a
file called 'world' I see the following behavior:

$ git filter-branch --tree-filter '
   for i in $(find . -type f); do
     if ( file $i | grep "\btext\b" > /dev/null ); then
       perl -i -ple "s/\\\$(Id|Date|Source|Header|CVSHeader|Author|Revision):[^\
\$]*\\$/\\$\1\\$/" $i;
     fi;
   done ' -- --all

Rewrite 7a78604e90b9debfaa6a755019b5d3df541abcba (1/6)/usr/bin/git-filter-branch
: line 249: ./world+1: syntax error: operand expected (error token is "./world+1
")


In case anyone is wondering: This isn't the right way to nuke CVS keywords.
It's a good start, but it'll miss a few files (particularly with older
versions of the 'file' program) due to some types such as 'FORTRAN program
source' not containing 'text'.  Also, it's incredibly slow to the point
that I dropped filter-branch entirely and wrote a 'git_fast_filter' helper
(serving as a pipe between fast-export and fast-import) that I'll soon be
making available.

 git-filter-branch.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 20f6f51..5da63b1 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -272,10 +272,10 @@ test $commits -eq 0 && die "Found nothing to rewrite"
 
 # Rewrite the commits
 
-i=0
+git_filter_branch_count=0
 while read commit parents; do
-	i=$(($i+1))
-	printf "\rRewrite $commit ($i/$commits)"
+	git_filter_branch_count=$(($git_filter_branch_count+1))
+	printf "\rRewrite $commit ($git_filter_branch_count/$commits)"
 
 	case "$filter_subdir" in
 	"")
-- 
1.6.0.6

^ permalink raw reply related

* Re: reverting initial commit
From: Giuseppe Bilotta @ 2009-03-25 21:22 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: git
In-Reply-To: <fabb9a1e0903251340x637a21dav6e304aa6d2825958@mail.gmail.com>

On Wed, Mar 25, 2009 at 9:40 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> Heya,
>
> On Wed, Mar 25, 2009 at 20:45, Giuseppe Bilotta
> <giuseppe.bilotta@gmail.com> wrote:
>> I wish there was a way to tell rebase -i to go back to the first commit,
>> inclusive, but the two or three times I've tried hacking at it I never
>> managed to come to anything useful 8-/
>
> Wasn't --root added to rebase -i recently?

>From reading the manpage I assumed it could only be used to put the
stuff on top of something else (the --onto requirement). Or did I miss
something along the way?


-- 
Giuseppe "Oblomov" Bilotta

^ permalink raw reply

* [PATCH] Correct missing SP characters in grammar comment at top of fast-import.c
From: newren @ 2009-03-25 21:22 UTC (permalink / raw)
  To: git; +Cc: spearce, gitster, Elijah Newren

From: Elijah Newren <newren@gmail.com>


Signed-off-by: Elijah Newren <newren@gmail.com>
---

Some point after discovering this 'bug', I noticed that the documentation
in Documentation/git-fast-import.txt was accurate, so I added a comment at
the top of the file pointing people at that document, as I suspect it is
more likely to be kept up to date.  If my assumption is wrong, or would
prefer different wording, I'm all ears.

 fast-import.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index beeac0d..db44da3 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1,4 +1,5 @@
 /*
+(See Documentation/git-fast-import.txt for maintained documentation.)
 Format of STDIN stream:
 
   stream ::= cmd*;
@@ -18,8 +19,8 @@ Format of STDIN stream:
 
   new_commit ::= 'commit' sp ref_str lf
     mark?
-    ('author' sp name '<' email '>' when lf)?
-    'committer' sp name '<' email '>' when lf
+    ('author' sp name sp '<' email '>' sp when lf)?
+    'committer' sp name sp '<' email '>' sp when lf
     commit_msg
     ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
     ('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
@@ -43,7 +44,7 @@ Format of STDIN stream:
 
   new_tag ::= 'tag' sp tag_str lf
     'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
-    ('tagger' sp name '<' email '>' when lf)?
+    ('tagger' sp name sp '<' email '>' sp when lf)?
     tag_msg;
   tag_msg ::= data;
 
-- 
1.6.0.6

^ permalink raw reply related

* Re: [PATCH] git-filter-branch: avoid collisions with variables in eval'ed commands
From: Petr Baudis @ 2009-03-25 21:24 UTC (permalink / raw)
  To: newren; +Cc: git, Johannes.Schindelin, gitster
In-Reply-To: <1238015581-12801-1-git-send-email-newren@gmail.com>

On Wed, Mar 25, 2009 at 03:13:01PM -0600, newren@gmail.com wrote:
> From: Elijah Newren <newren@gmail.com>
> 
> Avoid using simple variable names like 'i', since user commands are eval'ed
> and may clash with and overwrite our values.
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>

Almost-acked-by: Petr Baudis <pasky@suse.cz>

But:

>-i=0
>+git_filter_branch_count=0

Why branch_count? It counts commits, not branches, doesn't it?


> I discovered this a few months ago, but apparently never got around to
> sending it earlier.  Anyway, without this patch in a repository with a
> file called 'world' I see the following behavior:

Some hints:

> $ git filter-branch --tree-filter '
>    for i in $(find . -type f); do

This won't work right if your filenames contain $IFS.

>      if ( file $i | grep "\btext\b" > /dev/null ); then

if [[ "$(file $i)" == *text* ]] might run noticeably faster (though is
slightly less precise). Having a filename-keyed cache of file types even
more so.

>        perl -i -ple "s/\\\$(Id|Date|Source|Header|CVSHeader|Author|Revision):[^\
> \$]*\\$/\\$\1\\$/" $i;

Using '\'' instead of " could save you quite a few backslashes in net
count.

>      fi;
>    done ' -- --all

-- 
				Petr "Pasky" Baudis
The average, healthy, well-adjusted adult gets up at seven-thirty
in the morning feeling just terrible. -- Jean Kerr

^ permalink raw reply

* Re: [PATCH] Correct missing SP characters in grammar comment at top of fast-import.c
From: Shawn O. Pearce @ 2009-03-25 21:26 UTC (permalink / raw)
  To: newren; +Cc: git, gitster
In-Reply-To: <1238016133-13509-1-git-send-email-newren@gmail.com>

newren@gmail.com wrote:
> From: Elijah Newren <newren@gmail.com>
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>

Acked-by: Shawn O. Pearce <spearce@spearce.org>

> Some point after discovering this 'bug', I noticed that the documentation
> in Documentation/git-fast-import.txt was accurate, so I added a comment at
> the top of the file pointing people at that document, as I suspect it is
> more likely to be kept up to date.  If my assumption is wrong, or would
> prefer different wording, I'm all ears.

Good catch.  The grammar at the top of the file should be more
accurate than the documentation you point to.  This was just a
thinko when I wrote the grammar out in the header.


> diff --git a/fast-import.c b/fast-import.c
> index beeac0d..db44da3 100644
> --- a/fast-import.c
> +++ b/fast-import.c
> @@ -1,4 +1,5 @@
>  /*
> +(See Documentation/git-fast-import.txt for maintained documentation.)
>  Format of STDIN stream:
>  
>    stream ::= cmd*;
> @@ -18,8 +19,8 @@ Format of STDIN stream:
>  
>    new_commit ::= 'commit' sp ref_str lf
>      mark?
> -    ('author' sp name '<' email '>' when lf)?
> -    'committer' sp name '<' email '>' when lf
> +    ('author' sp name sp '<' email '>' sp when lf)?
> +    'committer' sp name sp '<' email '>' sp when lf
>      commit_msg
>      ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
>      ('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
> @@ -43,7 +44,7 @@ Format of STDIN stream:
>  
>    new_tag ::= 'tag' sp tag_str lf
>      'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
> -    ('tagger' sp name '<' email '>' when lf)?
> +    ('tagger' sp name sp '<' email '>' sp when lf)?
>      tag_msg;
>    tag_msg ::= data;
>  
> -- 
> 1.6.0.6
> 

-- 
Shawn.

^ permalink raw reply

* Use alternate GIT servers to share traffic
From: Thomas Koch @ 2009-03-25 20:45 UTC (permalink / raw)
  To: git

Hi,

we host a public GIT repository on our high availability company
cluster. Cloning the repo causes a trafic volume of 326 MB. We'd like to
avoid that much trafic while still leaving the GIT repo where it is.

I could imagine the following conversation between the GIT client and
server:

Client: Wanna clone!
Server: You're welcome. Please note, that while I serve the most current
state, you can get objects much faster from my collegue Server
CHEAPHOST.
Client: Thank you. Will take all the objects I can get from CHEAPHOST
and come back if I should need anything else!

The enduser should not need to specify anything, but only the regular
git clone EXPENSIVEHOST line.

Your thoughts?

Best regards,
-- 
Thomas Koch, http://www.koch.ro
YMC AG, http://www.ymc.ch

^ permalink raw reply

* Re: [PATCH] git-filter-branch: avoid collisions with variables in  eval'ed commands
From: Elijah Newren @ 2009-03-25 21:33 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git, Johannes.Schindelin, gitster
In-Reply-To: <20090325212403.GU8940@machine.or.cz>

Hi,

On Wed, Mar 25, 2009 at 3:24 PM, Petr Baudis <pasky@suse.cz> wrote:
> On Wed, Mar 25, 2009 at 03:13:01PM -0600, newren@gmail.com wrote:
>> From: Elijah Newren <newren@gmail.com>
>>
>> Avoid using simple variable names like 'i', since user commands are eval'ed
>> and may clash with and overwrite our values.
>>
>> Signed-off-by: Elijah Newren <newren@gmail.com>
>
> Almost-acked-by: Petr Baudis <pasky@suse.cz>
>
> But:
>
>>-i=0
>>+git_filter_branch_count=0
>
> Why branch_count? It counts commits, not branches, doesn't it?

Oh, I was just changing i->git_filter_branch_i, then thought as long
as it was long I might as well use a word instead of "i".  Didn't
think about the combined meaning.  How about
"git_filter_branch_commit_count"?  Maybe a double underscore between
the "namespace" and the "variable"?

>> I discovered this a few months ago, but apparently never got around to
>> sending it earlier.  Anyway, without this patch in a repository with a
>> file called 'world' I see the following behavior:
>
> Some hints:
>
>> $ git filter-branch --tree-filter '
>>    for i in $(find . -type f); do
>
> This won't work right if your filenames contain $IFS.

Yeah, luckily for me, my repository didn't have any filenames with
whitespace.  :-)

>>      if ( file $i | grep "\btext\b" > /dev/null ); then
>
> if [[ "$(file $i)" == *text* ]] might run noticeably faster (though is
> slightly less precise). Having a filename-keyed cache of file types even
> more so.
>
>>        perl -i -ple "s/\\\$(Id|Date|Source|Header|CVSHeader|Author|Revision):[^\
>> \$]*\\$/\\$\1\\$/" $i;
>
> Using '\'' instead of " could save you quite a few backslashes in net
> count.

Cool, thanks for the tips.

^ permalink raw reply

* [PATCH/RFC 0/7] Restricting repository access (Was: [BUG?] How to make a shared/restricted repo?)
From: Johan Herland @ 2009-03-25 21:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7v63hybaqd.fsf@gitster.siamese.dyndns.org>

On Wednesday 25 March 2009, Junio C Hamano wrote:
> Johan Herland <johan@herland.net> writes:
> > On Wednesday 25 March 2009, Junio C Hamano wrote:
> >> You might like to try a patch like this (untested).
> >>
> >>  path.c |   17 +++++------------
> >>  1 files changed, 5 insertions(+), 12 deletions(-)
> >
> > Thanks!
> >
> > This works much better :)
> >
> > However, there are still some questions/issues:
> >
> > - t1301-shared-repo.sh fails:
> >     Oops, .git/HEAD is not 0664 but -rw-rw---- [...]
> >     * FAIL 3: shared=1 does not clear bits preset by umask 022
> >   (I guess this is expected, as your patch changes the assumptions)
>
> I'd rather say the patch breaks people's expectations.

I thought some more about the current semantics, and came up with this
patch series, which replaces your original suggestion.

In short, I leave the core.sharedRepository semantics as is (i.e. it is
only used to _loosen_ repository permissions), and introduce a new
variable - core.restrictedRepository - that takes care of _tightening_
repository permissions. Its value is a permission mask that is applied
to the file mode in adjust_shared_perm()

The patch series is based on recent 'next', and the testsuite passes
after each individual patch.

Here is a short rundown of the individual patches:

1. Clarify existing documentation to reflect the current semantics of
   core.sharedRepository and "git init --shared". Even if the rest of
   the series is rejected, I hope this can make it in some form.

2. Minor cleanup in path.c:adjust_shared_perm(). This is pretty much
   your original patch with any functional changes removed.

3. Introduce core.restrictedRepository. Adds git_config_perm_mask()
   for parsing the config value, and changes adjust_shared_perm() to
   apply the permission mask. Includes documentation of the new config
   variable.

4. Add "--restricted" to "git init". Heavily modeled on the existing
   "--shared" option. Includes documentation of the new option.

5. Add tests for the functionality introduced in #3 and #4.

6. Apply adjusted repository permissions in "git init" when copying
   templates into the new repo.

7. Apply restricted permissions to loose objects and pack files. This
   ensures that loose objects and pack files do not get permissions
   that are more liberal than the rest of the repository.


Have fun!

...Johan


Johan Herland (7):
  Clarify documentation on permissions in shared repositories
  Cleanup: Remove unnecessary if-else clause
  Introduce core.restrictedRepository for restricting repository
    permissions
  git-init: Introduce --restricted for restricting repository access
  Add tests for "core.restrictedRepository" and "git init --restricted"
  git-init: Apply correct mode bits to template files in
    shared/restricted repo
  Apply restricted permissions to loose objects and pack files

 Documentation/config.txt   |   41 ++++++++++++-
 Documentation/git-init.txt |   50 +++++++++++++++--
 builtin-init-db.c          |   31 +++++++++-
 cache.h                    |    8 +++
 environment.c              |    1 +
 fast-import.c              |    4 +-
 http-push.c                |    2 +-
 http-walker.c              |    2 +-
 index-pack.c               |    4 +-
 path.c                     |   22 +++----
 setup.c                    |   36 ++++++++++++
 sha1_file.c                |    2 +-
 t/t0001-init.sh            |   24 +++++++-
 t/t1304-restricted-repo.sh |  132 ++++++++++++++++++++++++++++++++++++++++++++
 14 files changed, 323 insertions(+), 36 deletions(-)
 create mode 100755 t/t1304-restricted-repo.sh

^ permalink raw reply

* [PATCH/RFC 1/7] Clarify documentation on permissions in shared repositories
From: Johan Herland @ 2009-03-25 21:37 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

The "core.sharedRepository" config variable (and, by extension, the
"--shared" argument to "git init") can be used to loosen repository
permissions for users with a safe umask, but it can not be used to
tighten repository permissions for users with a more lenient umask.

This patch updates the documentation to clarify the current behaviour.

Signed-off-by: Johan Herland <johan@herland.net>
---
 Documentation/config.txt   |   15 +++++++++++----
 Documentation/git-init.txt |   12 ++++++++----
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 089569a..d5befd5 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -294,10 +294,17 @@ core.sharedRepository::
 	repository will be readable by all users, additionally to being
 	group-shareable. When 'umask' (or 'false'), git will use permissions
 	reported by umask(2). When '0xxx', where '0xxx' is an octal number,
-	files in the repository will have this mode value. '0xxx' will override
-	user's umask value, and thus, users with a safe umask (0077) can use
-	this option. Examples: '0660' is equivalent to 'group'. '0640' is a
-	repository that is group-readable but not group-writable.
+	files in the repository will have (at least) this mode value. '0xxx'
+	will override a safer umask value, and thus, users with a safe umask
+	(0077) can use this option to loosen the repository permissions.
+	Examples: '0660' is equivalent to 'group'. '0640' is a repository
+	that is group-readable but not group-writable (unless umask allows
+	group-writability).
+	Note: Even when not set to 'umask' (or 'false') this option is still
+	combined with the umask to produce the actual mode value. For
+	example, if umask is 0022, setting 'group' (or '0660') will not make
+	the repository non world-readable (the actual mode value will in fact
+	be '0664').
 	See linkgit:git-init[1]. False by default.
 
 core.warnAmbiguousRefs::
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index 71749c0..bddc01b 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -45,6 +45,7 @@ repository.  When specified, the config variable "core.sharedRepository" is
 set so that files and directories under `$GIT_DIR` are created with the
 requested permissions.  When not specified, git will use permissions reported
 by umask(2).
+When specified, the permissions will still be no stricter than the umask.
 
 The option can have the following values, defaulting to 'group' if no value
 is given:
@@ -58,11 +59,14 @@ is given:
  - 'all' (or 'world' or 'everybody'): Same as 'group', but make the repository
    readable by all users.
 
- - '0xxx': '0xxx' is an octal number and each file will have mode '0xxx'
+ - '0xxx': '0xxx' is an octal number and each file will have (at least) this
+   mode value.
    Any option except 'umask' can be set using this option. '0xxx' will
-   override users umask(2) value, and thus, users with a safe umask (0077)
-   can use this option. '0640' will create a repository which is group-readable
-   but not writable. '0660' is equivalent to 'group'.
+   override a safer umask(2) value (but not a more permissive umask), and
+   thus, users with a safe umask (e.g. 0077) can use this option to loosen
+   repository permissions. '0640' will create a repository which is
+   group-readable but not writable (unless umask allows group-writability).
+   '0660' is equivalent to 'group'.
 
 By default, the configuration flag receive.denyNonFastForwards is enabled
 in shared repositories, so that you cannot force a non fast-forwarding push
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 2/7] Cleanup: Remove unnecessary if-else clause
From: Johan Herland @ 2009-03-25 21:38 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

Signed-off-by: Johan Herland <johan@herland.net>
---
 path.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/path.c b/path.c
index e332b50..28e50d3 100644
--- a/path.c
+++ b/path.c
@@ -322,16 +322,10 @@ int adjust_shared_perm(const char *path)
 		return -1;
 	mode = st.st_mode;
 
-	if (shared_repository) {
-		int tweak = shared_repository;
-		if (!(mode & S_IWUSR))
-			tweak &= ~0222;
-		mode |= tweak;
-	} else {
-		/* Preserve old PERM_UMASK behaviour */
-		if (mode & S_IWUSR)
-			mode |= S_IWGRP;
-	}
+	int tweak = shared_repository;
+	if (!(mode & S_IWUSR))
+		tweak &= ~0222;
+	mode |= tweak;
 
 	if (S_ISDIR(mode)) {
 		mode |= FORCE_DIR_SET_GID;
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 3/7] Introduce core.restrictedRepository for restricting repository permissions
From: Johan Herland @ 2009-03-25 21:39 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

core.sharedRepository is only used to loosen/expand permissions (beyond the
user's umask). In order to tighten/restrict permissions (stricter than the
umask), we add a new configuration variable that serves as an additional
mask on the permissions of created files and directories.

The new config variable - core.restrictedRepository - can be set to an octal
number, interpreted as an additional mask to be applied to the permissions
of created files and directories. It can also be set to "umask" (or "false",
equivalent to "0000", i.e. no more restrictive than the user's umask), "user"
(or "true", equivalent to "0077", i.e. dropping read- and write-permissions
for group and others), or "group" (equivalent to "0007", i.e. dropping read-
and write-permissions for others). If set with no value, it defaults to
"user" (the most secure/restricted state).

Signed-off-by: Johan Herland <johan@herland.net>
---
 Documentation/config.txt |   26 ++++++++++++++++++++++++++
 cache.h                  |    7 +++++++
 environment.c            |    1 +
 path.c                   |   14 ++++++++------
 setup.c                  |   36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index d5befd5..0f2dd5c 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -305,8 +305,34 @@ core.sharedRepository::
 	example, if umask is 0022, setting 'group' (or '0660') will not make
 	the repository non world-readable (the actual mode value will in fact
 	be '0664').
+	See "core.restrictedRepository" for how to restrict repository access
+	below/within the umask.
 	See linkgit:git-init[1]. False by default.
 
+core.restrictedRepository::
+	When 'user' (or 'true'), the repository is made inaccessible to
+	anybody but the user owning the repository. When 'group', repository
+	access is restricted to the members of the repository's group.
+	When 'umask' (or 'false'), git will use permissions reported by
+	umask(2). When '0xxx', where '0xxx' is an octal number, files in the
+	repository will the specified mode bits masked off. '0xxx' will
+	override a more lenient umask value, and thus, users with a loose
+	umask (e.g. 0022) can use this option to further restrict the
+	repository permissions.
+	Examples: '0007' is equivalent to 'group'. '0077' is a repository
+	that is only accessible to the repository owner.
+	Note: Even when not set to 'umask' (or 'false') this option is still
+	combined with the umask to produce the actual mask value. For
+	example, if umask is 0077, setting 'group' (or '0007') will not make
+	the repository group-accessible (the calculated mode mask will in
+	fact be '0077', restricting access to the repository owner only).
+	See "core.sharedRepository" for how to loosen repository access
+	beyond the umask.
+	Example: To set up a group-shared repository that is inaccessible to
+	all non-members, set both "core.sharedRepository" and
+	"core.restrictedRepository" to "group".
+	False by default.
+
 core.warnAmbiguousRefs::
 	If true, git will warn you if the ref name you passed it is ambiguous
 	and might match multiple refs in the .git/refs/ tree. True by default.
diff --git a/cache.h b/cache.h
index 9cf5a13..4730f33 100644
--- a/cache.h
+++ b/cache.h
@@ -508,6 +508,7 @@ extern int prefer_symlink_refs;
 extern int log_all_ref_updates;
 extern int warn_ambiguous_refs;
 extern int shared_repository;
+extern int restricted_repository;
 extern const char *apply_default_whitespace;
 extern int zlib_compression_level;
 extern int core_compression_level;
@@ -622,7 +623,13 @@ enum sharedrepo {
 	PERM_GROUP          = 0660,
 	PERM_EVERYBODY      = 0664,
 };
+enum restrictedrepo {
+	PERM_MASK_UMASK     = 0000,
+	PERM_MASK_GROUP     = 0007,
+	PERM_MASK_USER      = 0077,
+};
 int git_config_perm(const char *var, const char *value);
+int git_config_perm_mask(const char *var, const char *value);
 int adjust_shared_perm(const char *path);
 int safe_create_leading_directories(char *path);
 int safe_create_leading_directories_const(const char *path);
diff --git a/environment.c b/environment.c
index 4696885..9591710 100644
--- a/environment.c
+++ b/environment.c
@@ -25,6 +25,7 @@ int repository_format_version;
 const char *git_commit_encoding;
 const char *git_log_output_encoding;
 int shared_repository = PERM_UMASK;
+int restricted_repository = PERM_MASK_UMASK;
 const char *apply_default_whitespace;
 int zlib_compression_level = Z_BEST_SPEED;
 int core_compression_level;
diff --git a/path.c b/path.c
index 28e50d3..093c87c 100644
--- a/path.c
+++ b/path.c
@@ -316,25 +316,27 @@ int adjust_shared_perm(const char *path)
 	struct stat st;
 	int mode;
 
-	if (!shared_repository)
+	if (!shared_repository && !restricted_repository)
 		return 0;
 	if (lstat(path, &st) < 0)
 		return -1;
 	mode = st.st_mode;
 
-	int tweak = shared_repository;
 	if (!(mode & S_IWUSR))
-		tweak &= ~0222;
-	mode |= tweak;
+		restricted_repository |= 0222;
+
+	/* add shared_repository and subtract restricted_repository */
+	mode |= shared_repository;
+	mode &= ~restricted_repository;
 
 	if (S_ISDIR(mode)) {
 		mode |= FORCE_DIR_SET_GID;
 
 		/* Copy read bits to execute bits */
-		mode |= (shared_repository & 0444) >> 2;
+		mode |= (mode & 0444) >> 2;
 	}
 
-	if ((mode & st.st_mode) != mode && chmod(path, mode) < 0)
+	if (st.st_mode != mode && chmod(path, mode) < 0)
 		return -2;
 	return 0;
 }
diff --git a/setup.c b/setup.c
index 6c2deda..97685d4 100644
--- a/setup.c
+++ b/setup.c
@@ -459,12 +459,48 @@ int git_config_perm(const char *var, const char *value)
 	return i & 0666;
 }
 
+int git_config_perm_mask(const char *var, const char *value)
+{
+	int i;
+	char *endptr;
+
+	if (value == NULL)
+		return PERM_MASK_USER;
+
+	if (!strcmp(value, "umask"))
+		return PERM_MASK_UMASK;
+	if (!strcmp(value, "group"))
+		return PERM_MASK_GROUP;
+	if (!strcmp(value, "user"))
+		return PERM_MASK_USER;
+
+	/* Parse octal numbers */
+	i = strtol(value, &endptr, 8);
+
+	/* If not an octal number, maybe true/false? */
+	if (*endptr != 0)
+		return git_config_bool(var, value) ? PERM_MASK_USER :
+			PERM_MASK_UMASK;
+
+	/* A filemode mask value was given: 0xxx */
+
+	if (i & 0700)
+		die("Problem with core.restrictedRepository filemode mask "
+		    "value (0%.3o).\nThe owner of files must always have "
+		    "read and write permissions.", i);
+
+	/* Mask filemode mask value. Should only affect r/w/x flags for g/o */
+	return i & 0077;
+}
+
 int check_repository_format_version(const char *var, const char *value, void *cb)
 {
 	if (strcmp(var, "core.repositoryformatversion") == 0)
 		repository_format_version = git_config_int(var, value);
 	else if (strcmp(var, "core.sharedrepository") == 0)
 		shared_repository = git_config_perm(var, value);
+	else if (strcmp(var, "core.restrictedrepository") == 0)
+		restricted_repository = git_config_perm_mask(var, value);
 	else if (strcmp(var, "core.bare") == 0) {
 		is_bare_repository_cfg = git_config_bool(var, value);
 		if (is_bare_repository_cfg == 1)
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 4/7] git-init: Introduce --restricted for restricting repository access
From: Johan Herland @ 2009-03-25 21:39 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

"--restricted" does for "core.restrictedRepository" what "--shared" does for
"core.sharedRepository".

Signed-off-by: Johan Herland <johan@herland.net>
---
 Documentation/config.txt   |    2 +-
 Documentation/git-init.txt |   38 +++++++++++++++++++++++++++++++++++++-
 builtin-init-db.c          |   22 ++++++++++++++++++----
 3 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 0f2dd5c..08f8068 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -331,7 +331,7 @@ core.restrictedRepository::
 	Example: To set up a group-shared repository that is inaccessible to
 	all non-members, set both "core.sharedRepository" and
 	"core.restrictedRepository" to "group".
-	False by default.
+	See linkgit:git-init[1]. False by default.
 
 core.warnAmbiguousRefs::
 	If true, git will warn you if the ref name you passed it is ambiguous
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index bddc01b..2a431c2 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -8,7 +8,7 @@ git-init - Create an empty git repository or reinitialize an existing one
 
 SYNOPSIS
 --------
-'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
+'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] [--restricted[=<permissions>]]
 
 
 OPTIONS
@@ -72,6 +72,42 @@ By default, the configuration flag receive.denyNonFastForwards is enabled
 in shared repositories, so that you cannot force a non fast-forwarding push
 into it.
 
+--restricted[={false|true|umask|group|user|0xxx}]::
+
+Specify that the git repository is to be restricted according to the given
+permission mask.  This allows you to more finely control access to the
+repository.  When specified, the config variable "core.restrictedRepository"
+is set so that files and directories under `$GIT_DIR` are created with the
+restrictions in the given mask.  When not specified, git will use permissions
+reported by umask(2). When specified, the permissions will still be no more
+lenient than the umask allows.
+
+The option can have the following values, defaulting to 'user' if no value
+is given:
+
+ - 'umask' (or 'false'): Use permissions reported by umask(2). The default,
+   when `--restricted` is not specified.
+
+ - 'group': Make the repository accessible only to members of the group
+   owning the repository.
+
+ - 'user' (or 'true'): Make the repository inaccessible to anybody but the
+   repository owner.
+
+ - '0xxx': '0xxx' is an octal number and each file will have (at least) these
+   mode bits masked off the repository permission. '0xxx' will override a
+   more lenient umask(2) value (but not a stricter/safer umask), and thus,
+   users with a lenient umask (e.g. 0022) can use this option to tighten
+   repository permissions. '0000' is equivalent to 'umask', '0007' is
+   equivalent to 'group', and '0077' is equivalent to 'user'.
+   '0027' will create a repository which is group-readable (unless overridden
+   by the current umask), but not group-writable, and inaccessible to others.
+
+You can combine `--shared` and `--restricted` to finely control the access to
+the repository. For example, specifying `--shared=group --restricted=group`
+will ensure that the repository is group-readable and group-writable, and
+also non world-readable and non world-writable.
+
 --
 
 
diff --git a/builtin-init-db.c b/builtin-init-db.c
index fc63d0f..8e7fa2d 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -19,6 +19,7 @@
 
 static int init_is_bare_repository = 0;
 static int init_shared_repository = -1;
+static int init_restricted_repository = -1;
 
 static void safe_create_dir(const char *dir, int share)
 {
@@ -29,7 +30,7 @@ static void safe_create_dir(const char *dir, int share)
 		}
 	}
 	else if (share && adjust_shared_perm(dir))
-		die("Could not make %s writable by group", dir);
+		die("Could not set proper permissions on %s", dir);
 }
 
 static void copy_templates_1(char *path, int baselen,
@@ -196,12 +197,14 @@ static int create_default_files(const char *template_path)
 	is_bare_repository_cfg = init_is_bare_repository;
 	if (init_shared_repository != -1)
 		shared_repository = init_shared_repository;
+	if (init_restricted_repository != -1)
+		restricted_repository = init_restricted_repository;
 
 	/*
 	 * We would have created the above under user's umask -- under
 	 * shared-repository settings, we would need to fix them up.
 	 */
-	if (shared_repository) {
+	if (shared_repository || restricted_repository) {
 		adjust_shared_perm(get_git_dir());
 		adjust_shared_perm(git_path("refs"));
 		adjust_shared_perm(git_path("refs/heads"));
@@ -321,11 +324,17 @@ int init_db(const char *template_dir, unsigned int flags)
 		git_config_set("core.sharedrepository", buf);
 		git_config_set("receive.denyNonFastforwards", "true");
 	}
+	if (restricted_repository) {
+		char buf[5];
+		sprintf(buf, "%04o", restricted_repository);
+		git_config_set("core.restrictedrepository", buf);
+	}
 
 	if (!(flags & INIT_DB_QUIET))
-		printf("%s%s Git repository in %s/\n",
+		printf("%s%s%s Git repository in %s/\n",
 		       reinit ? "Reinitialized existing" : "Initialized empty",
 		       shared_repository ? " shared" : "",
+		       restricted_repository ? " restricted" : "",
 		       get_git_dir());
 
 	return 0;
@@ -363,7 +372,7 @@ static int guess_repository_type(const char *git_dir)
 }
 
 static const char init_db_usage[] =
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
+"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [--restricted[=<permissions>]]";
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -391,6 +400,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 			init_shared_repository = PERM_GROUP;
 		else if (!prefixcmp(arg, "--shared="))
 			init_shared_repository = git_config_perm("arg", arg+9);
+		else if (!strcmp(arg, "--restricted"))
+			init_restricted_repository = PERM_MASK_USER;
+		else if (!prefixcmp(arg, "--restricted="))
+			init_restricted_repository =
+				git_config_perm_mask("arg", arg+13);
 		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
 			flags |= INIT_DB_QUIET;
 		else
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 5/7] Add tests for "core.restrictedRepository" and "git init --restricted"
From: Johan Herland @ 2009-03-25 21:40 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

These tests are based on - and analogous to - the existing tests for
"core.sharedRepository" and "git init --shared"

Signed-off-by: Johan Herland <johan@herland.net>
---
 t/t0001-init.sh            |   24 +++++++-
 t/t1304-restricted-repo.sh |  132 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 3 deletions(-)
 create mode 100755 t/t1304-restricted-repo.sh

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5ac0a27..639a88d 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -167,7 +167,7 @@ test_expect_success 'init with --template (blank)' '
 	! test -f template-blank/.git/info/exclude
 '
 
-test_expect_success 'init --bare/--shared overrides system/global config' '
+test_expect_success 'init --bare/--shared/--restricted overrides system/global config' '
 	(
 		HOME="`pwd`" &&
 		export HOME &&
@@ -175,13 +175,16 @@ test_expect_success 'init --bare/--shared overrides system/global config' '
 		unset GIT_CONFIG_NOGLOBAL &&
 		git config -f "$test_config" core.bare false &&
 		git config -f "$test_config" core.sharedRepository 0640 &&
+		git config -f "$test_config" core.restrictedRepository 0027 &&
 		mkdir init-bare-shared-override &&
 		cd init-bare-shared-override &&
-		git init --bare --shared=0666
+		git init --bare --shared=0644 --restricted=0022
 	) &&
 	check_config init-bare-shared-override true unset &&
-	test x0666 = \
+	test x0644 = \
 	x`git config -f init-bare-shared-override/config core.sharedRepository`
+	test x0022 = \
+	x`git config -f init-bare-shared-override/config core.restrictedRepository`
 '
 
 test_expect_success 'init honors global core.sharedRepository' '
@@ -199,4 +202,19 @@ test_expect_success 'init honors global core.sharedRepository' '
 	x`git config -f shared-honor-global/.git/config core.sharedRepository`
 '
 
+test_expect_success 'init honors global core.restrictedRepository' '
+	(
+		HOME="`pwd`" &&
+		export HOME &&
+		test_config="$HOME"/.gitconfig &&
+		unset GIT_CONFIG_NOGLOBAL &&
+		git config -f "$test_config" core.restrictedRepository 0077 &&
+		mkdir restricted-honor-global &&
+		cd restricted-honor-global &&
+		git init
+	) &&
+	test x0077 = \
+	x`git config -f restricted-honor-global/.git/config core.restrictedRepository`
+'
+
 test_done
diff --git a/t/t1304-restricted-repo.sh b/t/t1304-restricted-repo.sh
new file mode 100755
index 0000000..012cdf1
--- /dev/null
+++ b/t/t1304-restricted-repo.sh
@@ -0,0 +1,132 @@
+#!/bin/sh
+#
+# Copied and modified from t1301-shared-repo.sh
+#
+
+test_description='Test restricted repository initialization'
+
+. ./test-lib.sh
+
+# Remove a default ACL from the test dir if possible.
+setfacl -k . 2>/dev/null
+
+# User must have r/w permissions to the repo -> failure on --restricted=0600
+test_expect_success 'restricted = 0600 (faulty permission u-rw)' '
+	mkdir sub && (
+		cd sub && git init --restricted=0600
+	)
+	ret="$?"
+	rm -rf sub
+	test $ret != "0"
+'
+
+modebits () {
+	ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
+}
+
+for u in 0007 0077
+do
+	test_expect_success POSIXPERM "restricted=group does not clear bits preset by umask $u" '
+		mkdir sub && (
+			cd sub &&
+			umask $u &&
+			git init --restricted=group &&
+			test "0007" = "$(git config core.restrictedrepository)"
+		) &&
+		actual=$(ls -l sub/.git/HEAD)
+		case "$u$actual" in
+		0007-rw-rw----*)
+			: happy
+			;;
+		0077-rw-------*)
+			: happy
+			;;
+		*)
+			echo Oops, .git/HEAD is not 06x0 but $actual
+			false
+			;;
+		esac
+	'
+	rm -rf sub
+done
+
+test_expect_success 'restricted=user' '
+	mkdir sub &&
+	cd sub &&
+	git init --restricted=user &&
+	test "0077" = "$(git config core.restrictedrepository)"
+'
+
+test_expect_success POSIXPERM 'update-server-info honors core.restrictedRepository' '
+	: > a1 &&
+	git add a1 &&
+	test_tick &&
+	git commit -m a1 &&
+	umask 0277 &&
+	git update-server-info &&
+	actual="$(ls -l .git/info/refs)" &&
+	case "$actual" in
+	-r--------*)
+		: happy
+		;;
+	*)
+		echo Oops, .git/info/refs is not 0400
+		false
+		;;
+	esac
+'
+
+for u in	0000:rw-rw-rw- \
+		0002:rw-rw-r-- \
+		0007:rw-rw---- \
+		0027:rw-r----- \
+		0077:rw-------
+do
+	x=$(expr "$u" : ".*:\([rw-]*\)") &&
+	y=$(echo "$x" | sed -e "s/w/-/g") &&
+	u=$(expr "$u" : "\([0-7]*\)"); test $? -le 1 &&
+	git config core.restrictedrepository "$u" &&
+	umask 0222 &&
+	test_expect_success POSIXPERM "shared = $u ($y) ro" '
+
+		rm -f .git/info/refs &&
+		git update-server-info &&
+		actual="$(modebits .git/info/refs)" &&
+		test "x$actual" = "x-$y" || {
+			ls -lt .git/info
+			false
+		}
+	'
+
+	umask 0000 &&
+	test_expect_success POSIXPERM "shared = $u ($x) rw" '
+
+		rm -f .git/info/refs &&
+		git update-server-info &&
+		actual="$(modebits .git/info/refs)" &&
+		test "x$actual" = "x-$x" || {
+			ls -lt .git/info
+			false
+		}
+
+	'
+
+done
+
+test_expect_success POSIXPERM 'git reflog expire honors core.restrictedRepository' '
+	umask 0000
+	git config core.restrictedRepository group &&
+	git reflog expire --all &&
+	actual="$(ls -l .git/logs/refs/heads/master)" &&
+	case "$actual" in
+	-rw-rw----*)
+		: happy
+		;;
+	*)
+		echo Ooops, .git/logs/refs/heads/master is not 0660 [$actual]
+		false
+		;;
+	esac
+'
+
+test_done
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 6/7] git-init: Apply correct mode bits to template files in shared/restricted repo
From: Johan Herland @ 2009-03-25 21:41 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

Template dirs/files are copied into the new repo before the config file is
parsed. This causes them to be created with default permissions (i.e. from
umask). When "--shared" and/or "--restricted" is given, this patch teaches
git-init to initialize the global variables controlling permissions on
created files (shared_repository and/or restricted_repository) _before_
the templates are copied. They are thus created with the appropriate
permissions.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin-init-db.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 8e7fa2d..fb88f65 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -187,6 +187,15 @@ static int create_default_files(const char *template_path)
 	safe_create_dir(git_path("refs/heads"), 1);
 	safe_create_dir(git_path("refs/tags"), 1);
 
+	/*
+	 * Set up shared/restricted_repository before copying templates, so
+	 * that they are created with appropriate permissions.
+	 */
+	if (init_shared_repository != -1)
+		shared_repository = init_shared_repository;
+	if (init_restricted_repository != -1)
+		restricted_repository = init_restricted_repository;
+
 	/* First copy the templates -- we might have the default
 	 * config file there, in which case we would want to read
 	 * from it after installing.
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* [PATCH/RFC 7/7] Apply restricted permissions to loose objects and pack files
From: Johan Herland @ 2009-03-25 21:42 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano
In-Reply-To: <200903252236.03010.johan@herland.net>

Loose objects and pack files are normally created with mode 0444, but in a
repository that uses core.restrictedRepository to restrict file modes, we
further limit permissions on loose objects and pack files, according to the
restrictedRepository setting.

Signed-off-by: Johan Herland <johan@herland.net>
---
 cache.h       |    1 +
 fast-import.c |    4 ++--
 http-push.c   |    2 +-
 http-walker.c |    2 +-
 index-pack.c  |    4 ++--
 sha1_file.c   |    2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/cache.h b/cache.h
index 4730f33..82e562b 100644
--- a/cache.h
+++ b/cache.h
@@ -509,6 +509,7 @@ extern int log_all_ref_updates;
 extern int warn_ambiguous_refs;
 extern int shared_repository;
 extern int restricted_repository;
+#define PERM_SHA1_FILE (0444 & ~restricted_repository)
 extern const char *apply_default_whitespace;
 extern int zlib_compression_level;
 extern int core_compression_level;
diff --git a/fast-import.c b/fast-import.c
index beeac0d..feafe6f 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -902,8 +902,8 @@ static char *keep_pack(char *curr_index_name)
 	static const char *keep_msg = "fast-import";
 	int keep_fd;
 
-	chmod(pack_data->pack_name, 0444);
-	chmod(curr_index_name, 0444);
+	chmod(pack_data->pack_name, PERM_SHA1_FILE);
+	chmod(curr_index_name, PERM_SHA1_FILE);
 
 	keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);
 	if (keep_fd < 0)
diff --git a/http-push.c b/http-push.c
index 6ce5a1d..e33044f 100644
--- a/http-push.c
+++ b/http-push.c
@@ -748,7 +748,7 @@ static void finish_request(struct transfer_request *request)
 			aborted = 1;
 		}
 	} else if (request->state == RUN_FETCH_LOOSE) {
-		fchmod(request->local_fileno, 0444);
+		fchmod(request->local_fileno, PERM_SHA1_FILE);
 		close(request->local_fileno); request->local_fileno = -1;
 
 		if (request->curl_result != CURLE_OK &&
diff --git a/http-walker.c b/http-walker.c
index 0dbad3c..a0dd5d2 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -231,7 +231,7 @@ static void finish_object_request(struct object_request *obj_req)
 {
 	struct stat st;
 
-	fchmod(obj_req->local, 0444);
+	fchmod(obj_req->local, PERM_SHA1_FILE);
 	close(obj_req->local); obj_req->local = -1;
 
 	if (obj_req->http_code == 416) {
diff --git a/index-pack.c b/index-pack.c
index 7546822..c82e60a 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -825,7 +825,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
 			die("cannot store pack file");
 	}
 	if (from_stdin)
-		chmod(final_pack_name, 0444);
+		chmod(final_pack_name, PERM_SHA1_FILE);
 
 	if (final_index_name != curr_index_name) {
 		if (!final_index_name) {
@@ -836,7 +836,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
 		if (move_temp_to_file(curr_index_name, final_index_name))
 			die("cannot store index file");
 	}
-	chmod(final_index_name, 0444);
+	chmod(final_index_name, PERM_SHA1_FILE);
 
 	if (!from_stdin) {
 		printf("%s\n", sha1_to_hex(sha1));
diff --git a/sha1_file.c b/sha1_file.c
index a354f06..ad63fe1 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2272,7 +2272,7 @@ static void close_sha1_file(int fd)
 {
 	if (fsync_object_files)
 		fsync_or_die(fd, "sha1 file");
-	fchmod(fd, 0444);
+	fchmod(fd, PERM_SHA1_FILE);
 	if (close(fd) != 0)
 		die("unable to write sha1 file");
 }
-- 
1.6.2.1.473.g92672

^ permalink raw reply related

* Re: [TopGit PATCH] hooks/pre-commit.sh: fix it again
From: Uwe Kleine-König @ 2009-03-25 21:44 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: Petr Baudis, git, martin f krafft
In-Reply-To: <1237981384-7857-1-git-send-email-bert.wesarg@googlemail.com>

Hello,

>  if head_=$(git symbolic-ref -q HEAD); then
>  	case "$head_" in
>  		refs/heads/*)
> -			git rev-parse -q --verify "${head_/#refs\/heads/refs\/top-bases}" >/dev/null || exit 0;;
> +			git rev-parse -q --verify "${head_/refs\/heads/refs\/top-bases}" >/dev/null || exit 0;;
			git rev-parse -q --verify "refs/top-bases${head_#refs/heads}" >/dev/null || exit 0;;

should work.

But I'm too tired to make a patch now.  That probably would only result
in more crap...

Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

^ permalink raw reply

* Re: [PATCH] git-filter-branch: avoid collisions with variables in eval'ed commands
From: newren @ 2009-03-25 21:51 UTC (permalink / raw)
  To: pasky; +Cc: git, Johannes.Schindelin, gitster, Elijah Newren
In-Reply-To: <51419b2c0903251433s75775206x556fc2d65a347d7d@mail.gmail.com>

From: Elijah Newren <newren@gmail.com>

Avoid using simple variable names like 'i', since user commands are eval'ed
and may clash with and overwrite our values.

Signed-off-by: Elijah Newren <newren@gmail.com>
---

If you have a different preference for the variable name, I'd be happy to
change it (again).  All I care about is avoiding conflicts with what people
might pass in their scripts.

 git-filter-branch.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 20f6f51..b90d3df 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -272,10 +272,10 @@ test $commits -eq 0 && die "Found nothing to rewrite"
 
 # Rewrite the commits
 
-i=0
+git_filter_branch__commit_count=0
 while read commit parents; do
-	i=$(($i+1))
-	printf "\rRewrite $commit ($i/$commits)"
+	git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
+	printf "\rRewrite $commit ($git_filter_branch__commit_count/$commits)"
 
 	case "$filter_subdir" in
 	"")
-- 
1.6.0.6

^ permalink raw reply related

* [EGIT PATCH] Set a title that includes the repository path for checkout/reset dialogs
From: Robin Rosenberg @ 2009-03-25 21:52 UTC (permalink / raw)
  To: spearce; +Cc: git, Robin Rosenberg

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/egit/ui/UIText.java            |    6 ++++++
 .../ui/internal/dialogs/BranchSelectionDialog.java |    5 +++++
 .../src/org/spearce/egit/ui/uitext.properties      |    2 ++
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
index 8e3a40f..918cce1 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java
@@ -851,6 +851,12 @@
 	public static String WindowCachePreferencePage_packedGitMMAP;
 
 	/** */
+	public static String BranchSelectionDialog_TitleCheckout;
+
+	/** */
+	public static String BranchSelectionDialog_TitleReset;
+
+	/** */
 	public static String BranchSelectionDialog_OkReset;
 
 	/** */
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
index f0a8d69..cbbc384 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/BranchSelectionDialog.java
@@ -94,6 +94,11 @@ protected Composite createDialogArea(Composite base) {
 			buildResetGroup();
 		}
 
+		String rawTitle = showResetType ? UIText.BranchSelectionDialog_TitleReset
+				: UIText.BranchSelectionDialog_TitleCheckout;
+		getShell().setText(
+				NLS.bind(rawTitle, new Object[] { repo.getDirectory() }));
+
 		try {
 			fillTreeWithBranches(null);
 		} catch (IOException e) {
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
index e2e6bd3..35627ce 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties
@@ -323,6 +323,8 @@ WindowCachePreferencePage_packedGitLimit=Window cache limit:
 WindowCachePreferencePage_deltaBaseCacheLimit=Delta base cache limit:
 WindowCachePreferencePage_packedGitMMAP=Use virtual memory mapping
 
+BranchSelectionDialog_TitleCheckout=Checkout: {0}
+BranchSelectionDialog_TitleReset=Reset: {0}
 BranchSelectionDialog_BranchSuffix_Current=\ (current)
 BranchSelectionDialog_ErrorAlreadyExists=Already exists
 BranchSelectionDialog_ErrorCouldNotCreateNewRef=Could not create new ref {0}
-- 
1.6.2.1.214.ge986c

^ permalink raw reply related

* Re: [PATCH] git-filter-branch: avoid collisions with variables in eval'ed commands
From: Petr Baudis @ 2009-03-25 21:58 UTC (permalink / raw)
  To: Elijah Newren; +Cc: git, Johannes.Schindelin, gitster
In-Reply-To: <51419b2c0903251433s75775206x556fc2d65a347d7d@mail.gmail.com>

On Wed, Mar 25, 2009 at 03:33:31PM -0600, Elijah Newren wrote:
> Hi,
> 
> On Wed, Mar 25, 2009 at 3:24 PM, Petr Baudis <pasky@suse.cz> wrote:
> > On Wed, Mar 25, 2009 at 03:13:01PM -0600, newren@gmail.com wrote:
> >> From: Elijah Newren <newren@gmail.com>
> >>
> >> Avoid using simple variable names like 'i', since user commands are eval'ed
> >> and may clash with and overwrite our values.
> >>
> >> Signed-off-by: Elijah Newren <newren@gmail.com>
> >
> > Almost-acked-by: Petr Baudis <pasky@suse.cz>
> >
> > But:
> >
> >>-i=0
> >>+git_filter_branch_count=0
> >
> > Why branch_count? It counts commits, not branches, doesn't it?
> 
> Oh, I was just changing i->git_filter_branch_i, then thought as long
> as it was long I might as well use a word instead of "i".  Didn't
> think about the combined meaning.  How about
> "git_filter_branch_commit_count"?  Maybe a double underscore between
> the "namespace" and the "variable"?

Oh, I sort of thought it's "git-filter branch count", not
"git-filter-branch count". I'm dumbed down from all day spent in IKEA
I guess. :/

I'd personally just use $__git_i, $__git_commit or something, but YMMV.

-- 
				Petr "Pasky" Baudis
The average, healthy, well-adjusted adult gets up at seven-thirty
in the morning feeling just terrible. -- Jean Kerr

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox