From 1d7a760a7eb8e2541d817421b2a0c264d4a92a41 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 17 Dec 2012 06:38:26 -0900 Subject: Replace wc -l with line_count --- git-remote-gcrypt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/git-remote-gcrypt b/git-remote-gcrypt index 9373901..d38f889 100755 --- a/git-remote-gcrypt +++ b/git-remote-gcrypt @@ -143,6 +143,18 @@ filter_to() setvar "$1" "$f_result_" } +# Output the number of lines in $1 +line_count() +{ + local f_x=0 IFS= + IFS=$Newline + for f_line in $1 + do + f_x=$(($f_x + 1)) + done + xecho "$f_x" +} + ## gitception part # Fetch giturl $1, file $2 @@ -577,7 +589,7 @@ fetch_decrypt_pack() # $4 to list of packfiles to delete repack_if_needed() { - local pack_= packline_= premote_= key_= pkeep_= n_= + local pack_= packline_= premote_= key_= pkeep_= n_= m_= # $TmpPack_Encrypted set in caller @@ -593,12 +605,9 @@ repack_if_needed() pick_fields @premote_ 1,2 "$Packlist" pick_fields @pkeep_ 2 "$Keeplist" - if isnull "$pkeep_"; then - n_=$(xecho "$Packlist" | wc -l) - else - n_=$(xecho "$Packlist" | grep -v -e "$pkeep_" | wc -l) - fi - if [ $Repack_limit -gt "$n_" ]; then + n_=$(line_count "$Packlist") + m_=$(line_count "$pkeep_") + if [ $Repack_limit -gt "$(($n_ - $m_))" ]; then return fi echo_info "Repacking remote $NAME, ..." -- cgit v1.1