git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] fix update-hook-example to work with packed tag references
@ 2008-06-25  8:26 Dmitry Potapov
  2008-06-25  8:26 ` [PATCH 2/2] update-hook-example: optionally allow non-fast-forward Dmitry Potapov
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Potapov @ 2008-06-25  8:26 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Dmitry Potapov

The update-hook-example used 'test -f' to check the tag present, which
does not work if the checked reference is packed. This check has been
changed to use 'git rev-parse $tag' instead.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
 Documentation/howto/update-hook-example.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Documentation/howto/update-hook-example.txt b/Documentation/howto/update-hook-example.txt
index 88765b5..a8d3bae 100644
--- a/Documentation/howto/update-hook-example.txt
+++ b/Documentation/howto/update-hook-example.txt
@@ -68,7 +68,7 @@ function info {
 # - Branches should only be fast-forwarded.
 case "$1" in
   refs/tags/*)
-    [ -f "$GIT_DIR/$1" ] &&
+    git rev-parse --verify -q "$1" &&
     deny >/dev/null "You can't overwrite an existing tag"
     ;;
   refs/heads/*)
-- 
1.5.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] update-hook-example: optionally allow non-fast-forward
  2008-06-25  8:26 [PATCH 1/2] fix update-hook-example to work with packed tag references Dmitry Potapov
@ 2008-06-25  8:26 ` Dmitry Potapov
  2008-06-25 20:04   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Potapov @ 2008-06-25  8:26 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Dmitry Potapov

Sometimes it is desirable to have non-fast-forward branches in a
shared repository. A typical example of that is the 'pu' branch.
This patch extends the format of allowed-users and allow-groups
files by using the '+' sign at the beginning as the mark that
non-fast-forward pushes are permitted to the branch.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
 Documentation/howto/update-hook-example.txt |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/Documentation/howto/update-hook-example.txt b/Documentation/howto/update-hook-example.txt
index a8d3bae..e1e2889 100644
--- a/Documentation/howto/update-hook-example.txt
+++ b/Documentation/howto/update-hook-example.txt
@@ -65,7 +65,7 @@ function info {
 
 # Implement generic branch and tag policies.
 # - Tags should not be updated once created.
-# - Branches should only be fast-forwarded.
+# - Branches should only be fast-forwarded unless their pattern starts with '+'
 case "$1" in
   refs/tags/*)
     git rev-parse --verify -q "$1" &&
@@ -80,7 +80,7 @@ case "$1" in
       mb=$(git-merge-base "$2" "$3")
       case "$mb,$2" in
         "$2,$mb") info "Update is fast-forward" ;;
-        *)        deny >/dev/null  "This is not a fast-forward update." ;;
+        *)        noff=y; info "This is not a fast-forward update.";;
       esac
     fi
     ;;
@@ -98,8 +98,9 @@ info "The user is: '$username'"
 if [ -f "$allowed_users_file" ]; then
   rc=$(cat $allowed_users_file | grep -v '^#' | grep -v '^$' |
     while read head_pattern user_patterns; do
-      matchlen=$(expr "$1" : "$head_pattern")
-      if [ "$matchlen" == "${#1}" ]; then
+      matchlen=$(expr "$1" : "${head_pattern#+}")
+      allow_noff=$(expr substr "$head_pattern" 1 1)
+      if [ "$matchlen" = "${#1}" -a \( -z "$noff" -o "$allow_noff" = '+' \) ]; then
         info "Found matching head pattern: '$head_pattern'"
         for user_pattern in $user_patterns; do
           info "Checking user: '$username' against pattern: '$user_pattern'"
@@ -127,8 +128,9 @@ info "'$groups'"
 if [ -f "$allowed_groups_file" ]; then
   rc=$(cat $allowed_groups_file | grep -v '^#' | grep -v '^$' |
     while read head_pattern group_patterns; do
-      matchlen=$(expr "$1" : "$head_pattern")
-      if [ "$matchlen" == "${#1}" ]; then
+      matchlen=$(expr "$1" : "${head_pattern#+}")
+      allow_noff=$(expr substr "$head_pattern" 1 1)
+      if [ "$matchlen" = "${#1}" -a \( -z "$noff" -o "$allow_noff" = '+' \) ]; then
         info "Found matching head pattern: '$head_pattern'"
         for group_pattern in $group_patterns; do
           for groupname in $groups; do
@@ -159,6 +161,7 @@ allowed-groups, to describe which heads can be pushed into by
 whom.  The format of each file would look like this:
 
         refs/heads/master	junio
+        +refs/heads/pu		junio
         refs/heads/cogito$	pasky
         refs/heads/bw/.*	linus
         refs/heads/tmp/.*	.*
@@ -166,7 +169,8 @@ whom.  The format of each file would look like this:
 
 With this, Linus can push or create "bw/penguin" or "bw/zebra"
 or "bw/panda" branches, Pasky can do only "cogito", and JC can
-do master branch and make versioned tags.  And anybody can do
-tmp/blah branches.
+do master and pu branches and make versioned tags.  And anybody
+can do tmp/blah branches. The '+' sign at the pu record means
+that JC can make non-fast-forward pushes on it.
 
 ------------
-- 
1.5.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] update-hook-example: optionally allow non-fast-forward
  2008-06-25  8:26 ` [PATCH 2/2] update-hook-example: optionally allow non-fast-forward Dmitry Potapov
@ 2008-06-25 20:04   ` Junio C Hamano
  2008-06-25 23:14     ` [PATCH v2] " Dmitry Potapov
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2008-06-25 20:04 UTC (permalink / raw)
  To: Dmitry Potapov; +Cc: git

Dmitry Potapov <dpotapov@gmail.com> writes:

> Sometimes it is desirable to have non-fast-forward branches in a
> shared repository. A typical example of that is the 'pu' branch.
> This patch extends the format of allowed-users and allow-groups
> files by using the '+' sign at the beginning as the mark that
> non-fast-forward pushes are permitted to the branch.

Thanks.  1/2 queued for 'maint' (as it was an obvious fix) to be included
in 1.5.6.1, but not this one that is a feature enhancement even though it
is in docs.

> Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>

>    rc=$(cat $allowed_users_file | grep -v '^#' | grep -v '^$' |
>      while read head_pattern user_patterns; do
> -      matchlen=$(expr "$1" : "$head_pattern")
> -      if [ "$matchlen" == "${#1}" ]; then
> +      matchlen=$(expr "$1" : "${head_pattern#+}")
> +      allow_noff=$(expr substr "$head_pattern" 1 1)
> +      if [ "$matchlen" = "${#1}" -a \( -z "$noff" -o "$allow_noff" = '+' \) ]; then

"expr substr"?  Please don't.

    cf. http://www.opengroup.org/onlinepubs/000095399/utilities/expr.html

I'd probably write this part like so:

	... pipe ... |
	while read heads users
        do
        	# does this rule apply to us?
        	head_pattern=${heads#+}
                matchlen=$(expr "$1" : "$head_pattern")
                test "$matchlen" = ${#1} || continue

                # if non-ff, $heads must be with the '+' prefix
                test -n "$noff" &&
                test "z$head_pattern" = "z$heads" && continue

                ... Ok this is good.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] update-hook-example: optionally allow non-fast-forward
  2008-06-25 20:04   ` Junio C Hamano
@ 2008-06-25 23:14     ` Dmitry Potapov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Potapov @ 2008-06-25 23:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Sometimes it is desirable to have non-fast-forward branches in a
shared repository. A typical example of that is the 'pu' branch.
This patch extends the format of allowed-users and allow-groups
files by using the '+' sign at the beginning as the mark that
non-fast-forward pushes are permitted to the branch.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---

On Wed, Jun 25, 2008 at 01:04:56PM -0700, Junio C Hamano wrote:
> 
> I'd probably write this part like so:
<snip>

Thank you for advice. I have corrected the patch.

 Documentation/howto/update-hook-example.txt |   75 ++++++++++++++++-----------
 1 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/Documentation/howto/update-hook-example.txt b/Documentation/howto/update-hook-example.txt
index a8d3bae..7f430a0 100644
--- a/Documentation/howto/update-hook-example.txt
+++ b/Documentation/howto/update-hook-example.txt
@@ -65,7 +65,7 @@ function info {
 
 # Implement generic branch and tag policies.
 # - Tags should not be updated once created.
-# - Branches should only be fast-forwarded.
+# - Branches should only be fast-forwarded unless their pattern starts with '+'
 case "$1" in
   refs/tags/*)
     git rev-parse --verify -q "$1" &&
@@ -80,7 +80,7 @@ case "$1" in
       mb=$(git-merge-base "$2" "$3")
       case "$mb,$2" in
         "$2,$mb") info "Update is fast-forward" ;;
-        *)        deny >/dev/null  "This is not a fast-forward update." ;;
+        *)        noff=y; info "This is not a fast-forward update.";;
       esac
     fi
     ;;
@@ -97,19 +97,25 @@ info "The user is: '$username'"
 
 if [ -f "$allowed_users_file" ]; then
   rc=$(cat $allowed_users_file | grep -v '^#' | grep -v '^$' |
-    while read head_pattern user_patterns; do
-      matchlen=$(expr "$1" : "$head_pattern")
-      if [ "$matchlen" == "${#1}" ]; then
-        info "Found matching head pattern: '$head_pattern'"
-        for user_pattern in $user_patterns; do
-          info "Checking user: '$username' against pattern: '$user_pattern'"
-          matchlen=$(expr "$username" : "$user_pattern")
-          if [ "$matchlen" == "${#username}" ]; then
-            grant "Allowing user: '$username' with pattern: '$user_pattern'"
-          fi
-        done
-        deny "The user is not in the access list for this branch"
-      fi
+    while read heads user_patterns; do
+      #  does this rule apply to us?
+      head_pattern=${heads#+}
+      matchlen=$(expr "$1" : "${head_pattern#+}")
+      test "$matchlen" = ${#1} || continue
+
+      # if non-ff, $heads must be with the '+' prefix
+      test -n "$noff" &&
+      test "$head_pattern" = "$heads" && continue
+
+      info "Found matching head pattern: '$head_pattern'"
+      for user_pattern in $user_patterns; do
+        info "Checking user: '$username' against pattern: '$user_pattern'"
+        matchlen=$(expr "$username" : "$user_pattern")
+        if [ "$matchlen" == "${#username}" ]; then
+          grant "Allowing user: '$username' with pattern: '$user_pattern'"
+        fi
+      done
+      deny "The user is not in the access list for this branch"
     done
   )
   case "$rc" in
@@ -127,20 +133,27 @@ info "'$groups'"
 if [ -f "$allowed_groups_file" ]; then
   rc=$(cat $allowed_groups_file | grep -v '^#' | grep -v '^$' |
     while read head_pattern group_patterns; do
-      matchlen=$(expr "$1" : "$head_pattern")
-      if [ "$matchlen" == "${#1}" ]; then
-        info "Found matching head pattern: '$head_pattern'"
-        for group_pattern in $group_patterns; do
-          for groupname in $groups; do
-            info "Checking group: '$groupname' against pattern: '$group_pattern'"
-            matchlen=$(expr "$groupname" : "$group_pattern")
-            if [ "$matchlen" == "${#groupname}" ]; then
-              grant "Allowing group: '$groupname' with pattern: '$group_pattern'"
-            fi
-          done
+
+      #  does this rule apply to us?
+      head_pattern=${heads#+}
+      matchlen=$(expr "$1" : "${head_pattern#+}")
+      test "$matchlen" = ${#1} || continue
+
+      # if non-ff, $heads must be with the '+' prefix
+      test -n "$noff" &&
+      test "$head_pattern" = "$heads" && continue
+
+      info "Found matching head pattern: '$head_pattern'"
+      for group_pattern in $group_patterns; do
+        for groupname in $groups; do
+          info "Checking group: '$groupname' against pattern: '$group_pattern'"
+          matchlen=$(expr "$groupname" : "$group_pattern")
+          if [ "$matchlen" == "${#groupname}" ]; then
+            grant "Allowing group: '$groupname' with pattern: '$group_pattern'"
+          fi
         done
-        deny "None of the user's groups are in the access list for this branch"
-      fi
+      done
+      deny "None of the user's groups are in the access list for this branch"
     done
   )
   case "$rc" in
@@ -159,6 +172,7 @@ allowed-groups, to describe which heads can be pushed into by
 whom.  The format of each file would look like this:
 
         refs/heads/master	junio
+        +refs/heads/pu		junio
         refs/heads/cogito$	pasky
         refs/heads/bw/.*	linus
         refs/heads/tmp/.*	.*
@@ -166,7 +180,8 @@ whom.  The format of each file would look like this:
 
 With this, Linus can push or create "bw/penguin" or "bw/zebra"
 or "bw/panda" branches, Pasky can do only "cogito", and JC can
-do master branch and make versioned tags.  And anybody can do
-tmp/blah branches.
+do master and pu branches and make versioned tags.  And anybody
+can do tmp/blah branches. The '+' sign at the pu record means
+that JC can make non-fast-forward pushes on it.
 
 ------------
-- 
1.5.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-25 23:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-25  8:26 [PATCH 1/2] fix update-hook-example to work with packed tag references Dmitry Potapov
2008-06-25  8:26 ` [PATCH 2/2] update-hook-example: optionally allow non-fast-forward Dmitry Potapov
2008-06-25 20:04   ` Junio C Hamano
2008-06-25 23:14     ` [PATCH v2] " Dmitry Potapov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).