[sysadmin-bin: 65/168] Fix pre-receive-check-po to handle branch creation



commit 67bf84802757fedff3752fe0126222efcf05e7ed
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Thu Mar 19 23:18:13 2009 -0400

    Fix pre-receive-check-po to handle branch creation
    
    Don't use git-diff-tree when a branch is created - use
    git-ls-tree to find the files in the new branch instead.

 pre-receive-check-po |  154 +++++++++++++++++++++++++++++---------------------
 1 files changed, 90 insertions(+), 64 deletions(-)
---
diff --git a/pre-receive-check-po b/pre-receive-check-po
index e6db14b..503154d 100755
--- a/pre-receive-check-po
+++ b/pre-receive-check-po
@@ -1,58 +1,33 @@
 #!/bin/bash
 
-check_pos() {
-    oldrev=$1
-    newrev=$2
-    refname=$3
-
-    branchname=${refname#refs/heads/}
-    if [ "$branchname" = "$refname" ] ; then
-        # not a branch update
-	return
-    fi
-
-    branch_message=
-    if [ "x$branchname" != "master" ] ; then
-	branch_message=" (When updating branch '$branchname'.)"
-    fi
-
-    git diff-tree -r $oldrev $newrev | (
-	while read srcmode destmode srcsha destsha status srcpath destpath ; do
-	    if [ $status = 'D' ] ; then
-		continue # deleted
-	    fi
-
-            # destpath only present for copies/renames
-	    if [ x"$destpath" = x ] ; then
-		destpath=$srcpath
-	    fi
-
-	    case "$destpath" in
-		*.po)
-		    ;;
-		*)
-		    continue
-		    ;;
-	    esac
-
-	    basename=`basename $destpath`
-
-	    # Strip colon from the source mode
-	    srcmode=${srcmode#:}
-
-	    # gettext-0.14.6 on git.gnome.org isn't new enough to handle
-            # features such as msgctx
-            # dash_c="-c"
-            dash_c=
-
-	    # Parse the file and check for errors
-	    result=`git cat-file blob "$newrev:$destpath" | msgfmt $dash_c -o /dev/null - 2>&1`
-	    if [ $? -gt 0 ]; then
-		cat <<EOF >&2
-
+check_po() {
+    rev=$1
+    path=$2
+    mode=$3
+
+    case "$path" in
+	*.po)
+	    ;;
+	*)
+	    return
+	    ;;
+    esac
+
+    basename=`basename $path`
+
+    # gettext-0.14.6 on git.gnome.org isn't new enough to handle
+    # features such as msgctx
+    # dash_c="-c"
+    dash_c=
+
+    # Parse the file and check for errors
+    result=`git cat-file blob "$rev:$path" | msgfmt $dash_c -o /dev/null - 2>&1`
+    if [ $? -gt 0 ]; then
+	cat <<EOF >&2
+---
 The following translation (.po) file appears to be invalid.$branch_message
 
-$destpath
+$path
 
 The results of the validation follow. Please correct the errors on the line numbers mentioned and try to push again.
 
@@ -68,18 +43,18 @@ git add $basename
 git commit --amend
 
 If you have any further problems or questions, please contact the GNOME Translation Project mailing list <gnome-i18n gnome org>. Thank you.
-
+---
 EOF
-		exit 1
-	    fi
-
-	    # Check for the absence of an executable flag
-	    if expr "$destmode" : ".*\([1357]..\|[1357].\|[1357]\)$" > /dev/null 2>& 1; then
-		cat <<EOF >&2
+	exit 1
+    fi
 
+     # Check for the absence of an executable flag
+    if expr "$mode" : ".*\([1357]..\|[1357].\|[1357]\)$" > /dev/null 2>& 1; then
+	cat <<EOF >&2
+---
 The following translation file appears to have its executable flag set.$branch_message
 
-$destpath
+$path
 
 Translation files should not be executable. Please remove the flag and try to push again. The following commands may help:
 
@@ -88,12 +63,63 @@ git add $basename
 git commit --amend
 
 If you have any further problems or questions, please contact the GNOME Translation Project mailing list <gnome-i18n gnome org>. Thank you.
-
+---
 EOF
-		exit 1
-	    fi
-	done
-   )
+	exit 1
+    fi
+}
+
+check_pos() {
+    oldrev=$1
+    newrev=$2
+    refname=$3
+
+    branchname=${refname#refs/heads/}
+    if [ "$branchname" = "$refname" ] ; then
+        # not a branch update
+	return
+    fi
+
+    branch_message=
+    if [ "x$branchname" != "master" ] ; then
+	branch_message=" (When updating branch '$branchname'.)"
+    fi
+
+    if expr $newrev : "^0\+$" > /dev/null 2>&1; then
+        # Branch deletion, nothing to check
+	return 0
+    fi
+
+    if expr $oldrev : "^0\+$" > /dev/null 2>&1; then
+	# Branch creation
+	git ls-tree -r $newrev | (
+	    while read mode objtype sha path ; do
+		if [ $objtype = blob ] ; then
+		    check_po $newrev $path $mode
+		fi
+	    done
+	)
+    else
+	# Branch update
+	git diff-tree -r $oldrev $newrev | (
+	    while read srcmode destmode srcsha destsha status srcpath destpath ; do
+		if [ $status = 'D' ] ; then
+		    continue # deleted
+		fi
+
+		# destpath only present for copies/renames
+		if [ x"$destpath" = x ] ; then
+		    destpath=$srcpath
+		fi
+
+		# Strip colon from the source mode
+		srcmode=${srcmode#:}
+
+		check_po $newrev $destpath $destmode
+	    done
+	)
+    fi
+
 }
 
 if [ $# = 3 ] ; then



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]