FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-21-2011, 05:21 PM
Dan McGee
 
Default repo-add: bashify reading of .PKGINFO file

On Mon, Jun 20, 2011 at 2:46 PM, Dave Reisner <d@falconindy.com> wrote:
> grep and sed aren't needed here, and this removes the truly ugly
> manipulation of IFS. The process substituion could just as well be a
> herestring, but it breaks vim's syntax highlighting. Style over
> substance, mang.
>
> Signed-off-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Dan McGee <dan@archlinux.org>

> ---
> *scripts/repo-add.sh.in | * 19 +++++--------------
> *1 files changed, 5 insertions(+), 14 deletions(-)
>
> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> index 14506dc..3783348 100644
> --- a/scripts/repo-add.sh.in
> +++ b/scripts/repo-add.sh.in
> @@ -230,19 +230,12 @@ db_write_entry()
> * * * * * * * *_groups _licenses _replaces _depends _conflicts _provides _optdepends
> * * * * * * * *md5sum sha256sum pgpsig
>
> - * * * local OLDIFS="$IFS"
> - * * * # IFS (field separator) is only the newline character
> - * * * IFS="
> -"
> -
> * * * *# read info from the zipped package
> * * * *local line var val
> - * * * for line in $(bsdtar -xOqf "$pkgfile" .PKGINFO |
> - * * * * * * * * * * * grep -v '^#' | sed 's|(w*)s*=s*(.*)|1 2|'); do
> - * * * * * * * # bash awesomeness here- var is always one word, val is everything else
> - * * * * * * * var=${line%% *}
> - * * * * * * * val=${line#* }
> - * * * * * * * declare $var="$val"
> + * * * while read -r line; do
> + * * * * * * * [[ ${line:0:1} = '#' ]] && continue
> + * * * * * * * IFS=' =' read -r var val < <(printf '%s
' "$line")
> + * * * * * * * declare "$var=$val"
> * * * * * * * *case "$var" in
> * * * * * * * * * * * *group) * *_groups="$_groups$group
" ;;
> * * * * * * * * * * * *license) *_licenses="$_licenses$license
" ;;
> @@ -252,9 +245,7 @@ db_write_entry()
> * * * * * * * * * * * *provides) _provides="$_provides$provides
" ;;
> * * * * * * * * * * * *optdepend) _optdepends="$_optdepends$optdepend
" ;;
> * * * * * * * *esac
> - * * * done
> -
> - * * * IFS=$OLDIFS
> + * * * done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
>
> * * * *csize=$(@SIZECMD@ "$pkgfile")
>
> --
> 1.7.5.4
>
>
>
 
Old 06-24-2011, 04:09 AM
Dan McGee
 
Default repo-add: bashify reading of .PKGINFO file

On Wed, Jun 22, 2011 at 7:38 PM, Dave Reisner <d@falconindy.com> wrote:
> grep and sed aren't needed here, and this removes the truly ugly
> manipulation of IFS. The process substituion could just as well be a
> herestring, but it breaks vim's syntax highlighting. Style over
> substance, mang.
>
> Signed-off-by: Dave Reisner <d@falconindy.com>
> ---
> *scripts/repo-add.sh.in | * 21 +++++++--------------
> *1 files changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> index 4e2e4a7..01eeb84 100644
> --- a/scripts/repo-add.sh.in
> +++ b/scripts/repo-add.sh.in
> @@ -19,6 +19,8 @@
> *# * You should have received a copy of the GNU General Public License
> *# * along with this program. *If not, see <http://www.gnu.org/licenses/>.
>
> +shopt -s extglob
> +
> *# gettext initialization
> *export TEXTDOMAIN='pacman'
> *export TEXTDOMAINDIR='@localedir@'
> @@ -226,19 +228,12 @@ db_write_entry() {
> * * * * * * * *_groups _licenses _replaces _depends _conflicts _provides _optdepends
> * * * * * * * *md5sum sha256sum pgpsig
>
> - * * * local OLDIFS="$IFS"
> - * * * # IFS (field separator) is only the newline character
> - * * * IFS="
> -"
> -
> * * * *# read info from the zipped package
> * * * *local line var val
> - * * * for line in $(bsdtar -xOqf "$pkgfile" .PKGINFO |
> - * * * * * * * * * * * grep -v '^#' | sed 's|(w*)s*=s*(.*)|1 2|'); do
> - * * * * * * * # bash awesomeness here- var is always one word, val is everything else
> - * * * * * * * var=${line%% *}
> - * * * * * * * val=${line#* }
> - * * * * * * * declare $var="$val"
> + * * * while read -r line; do
> + * * * * * * * [[ ${line:0:1} = '#' ]] && continue
> + * * * * * * * IFS=' =' read -r var val < <(printf '%s
' "$line")
> + * * * * * * * declare "$var=${val//+([[:space:]])/ }" # normalize whitespace
You know how I hate same-line comments...

Given that most people don't see this +() business on a day-to-day
basis, mind extending the comment a bit and dropping 'extglob' so dumb
bash people like me know what to look for in the manpage?

> * * * * * * * *case "$var" in
> * * * * * * * * * * * *group) * *_groups="$_groups$group
" ;;
> * * * * * * * * * * * *license) *_licenses="$_licenses$license
" ;;
> @@ -248,9 +243,7 @@ db_write_entry() {
> * * * * * * * * * * * *provides) _provides="$_provides$provides
" ;;
> * * * * * * * * * * * *optdepend) _optdepends="$_optdepends$optdepend
" ;;
> * * * * * * * *esac
> - * * * done
> -
> - * * * IFS=$OLDIFS
> + * * * done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
>
> * * * *csize=$(@SIZECMD@ "$pkgfile")
>
> --
> 1.7.5.4
>
>
>
 

Thread Tools




All times are GMT. The time now is 10:27 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org