]> Nutra Git (v1) - gamesguru/git-remote-gcrypt.git/commitdiff
Simplify line_count and pick_fields
authorroot <root@localhost>
Mon, 7 Jan 2013 05:58:04 +0000 (21:58 -0800)
committerroot <root@localhost>
Mon, 7 Jan 2013 05:58:04 +0000 (21:58 -0800)
git-remote-gcrypt

index 81477e46771973a69ebb69a66c1b94c5027b8883..cb3dfeaa5c2dfcf1e54bf454cce32cdaf7232c89 100755 (executable)
@@ -85,16 +85,14 @@ append_to()
 # $2 input value
 pick_fields_1_2()
 {
-       local f_ret= f_line= f_var= f_oifs="$IFS" IFS=
-       f_var=$1
-       IFS=$Newline
-       for f_line in $2
+       local f_ret= f_one= f_two=
+       while read f_one f_two _ # from << here-document
        do
-               IFS=$f_oifs
-               set -- $f_line
-               f_ret=$f_ret"${1:-} ${2:-}"$Newline
-       done
-       setvar "$f_var" "${f_ret#$Newline}"
+               f_ret="$f_ret$f_one $f_two$Newline"
+       done <<EOF
+$2
+EOF
+       setvar "$1" "${f_ret#$Newline}"
 }
 
 # Take all lines matching $2 (full line)
@@ -118,13 +116,10 @@ filter_to()
 # Output the number of lines in $1
 line_count()
 {
-       local f_x=0 IFS=
+       local IFS=
        IFS=$Newline
-       for f_line in $1
-       do
-               f_x=$(($f_x + 1))
-       done
-       xecho "$f_x"
+       set -- $1
+       xecho "$#"
 }