[pacman-dev] [PATCH 1/6] pacsearch: removed useless comment
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 21043d4..71e0107 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -138,7 +138,6 @@ if ($#querypkgs >= 0) { foreach $_ (@querypkgs) { # we grab the following fields: repo, name, ver, group, installed, and desc my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))? ?(\[.*\])?\n(.*)$/s; - # my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s; # skip any non-matching line next if not defined $pkgfields[1]; # check if the package was listed in the sync out -- 1.8.5.3
Previously the different positional arguments formed a single pattern containing spaces. Now each argument is a different pattern to match. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 71e0107..8e05a1a 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -100,7 +100,7 @@ sub to_color { my %allpkgs = (); -my $syncout = `pacman -Ss '@ARGV'`; +my $syncout = `pacman -Ss @ARGV`; # split each sync search entry into its own array entry my @syncpkgs = split(/\n^(?=\w)/m, $syncout); # remove the extra \n from the last desc entry @@ -127,7 +127,7 @@ foreach $_ (@syncpkgs) { $allpkgs{$pkgfields[1]} = [ @pkgfields ]; } -my $queryout = `pacman -Qs '@ARGV'`; +my $queryout = `pacman -Qs @ARGV`; # split each querysearch entry into its own array entry my @querypkgs = split(/\n^(?=\w)/m, $queryout); # remove the extra \n from the last desc entry -- 1.8.5.3
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Previously the different positional arguments formed a single pattern containing spaces. Now each argument is a different pattern to match.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
See commit 380f062be. This breaks patterns like 'foo|bar'
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 71e0107..8e05a1a 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -100,7 +100,7 @@ sub to_color {
my %allpkgs = ();
-my $syncout = `pacman -Ss '@ARGV'`; +my $syncout = `pacman -Ss @ARGV`; # split each sync search entry into its own array entry my @syncpkgs = split(/\n^(?=\w)/m, $syncout); # remove the extra \n from the last desc entry @@ -127,7 +127,7 @@ foreach $_ (@syncpkgs) { $allpkgs{$pkgfields[1]} = [ @pkgfields ]; }
-my $queryout = `pacman -Qs '@ARGV'`; +my $queryout = `pacman -Qs @ARGV`; # split each querysearch entry into its own array entry my @querypkgs = split(/\n^(?=\w)/m, $queryout); # remove the extra \n from the last desc entry -- 1.8.5.3
On 14-02-03 07:36:32, Andrew Gregory wrote:
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Previously the different positional arguments formed a single pattern containing spaces. Now each argument is a different pattern to match.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
See commit 380f062be. This breaks patterns like 'foo|bar'
Right. Any idea how to solve this dilemma?
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 71e0107..8e05a1a 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -100,7 +100,7 @@ sub to_color {
my %allpkgs = ();
-my $syncout = `pacman -Ss '@ARGV'`; +my $syncout = `pacman -Ss @ARGV`; # split each sync search entry into its own array entry my @syncpkgs = split(/\n^(?=\w)/m, $syncout); # remove the extra \n from the last desc entry @@ -127,7 +127,7 @@ foreach $_ (@syncpkgs) { $allpkgs{$pkgfields[1]} = [ @pkgfields ]; }
-my $queryout = `pacman -Qs '@ARGV'`; +my $queryout = `pacman -Qs @ARGV`; # split each querysearch entry into its own array entry my @querypkgs = split(/\n^(?=\w)/m, $queryout); # remove the extra \n from the last desc entry -- 1.8.5.3
-- Pierre Neidhardt "A raccoon tangled with a 23,000 volt line today. The results blacked out 1400 homes and, of course, one raccoon." -- Steel City News
On 02/03/14 at 02:23pm, Pierre Neidhardt wrote:
On 14-02-03 07:36:32, Andrew Gregory wrote:
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Previously the different positional arguments formed a single pattern containing spaces. Now each argument is a different pattern to match.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
See commit 380f062be. This breaks patterns like 'foo|bar'
Right. Any idea how to solve this dilemma?
Yes, don't run pacman in a shell, use open.
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 71e0107..8e05a1a 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -100,7 +100,7 @@ sub to_color {
my %allpkgs = ();
-my $syncout = `pacman -Ss '@ARGV'`; +my $syncout = `pacman -Ss @ARGV`; # split each sync search entry into its own array entry my @syncpkgs = split(/\n^(?=\w)/m, $syncout); # remove the extra \n from the last desc entry @@ -127,7 +127,7 @@ foreach $_ (@syncpkgs) { $allpkgs{$pkgfields[1]} = [ @pkgfields ]; }
-my $queryout = `pacman -Qs '@ARGV'`; +my $queryout = `pacman -Qs @ARGV`; # split each querysearch entry into its own array entry my @querypkgs = split(/\n^(?=\w)/m, $queryout); # remove the extra \n from the last desc entry -- 1.8.5.3
-- Pierre Neidhardt
"A raccoon tangled with a 23,000 volt line today. The results blacked out 1400 homes and, of course, one raccoon." -- Steel City News
On 14-02-03 11:06:03, Andrew Gregory wrote:
On 02/03/14 at 02:23pm, Pierre Neidhardt wrote:
On 14-02-03 07:36:32, Andrew Gregory wrote:
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Previously the different positional arguments formed a single pattern containing spaces. Now each argument is a different pattern to match.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
See commit 380f062be. This breaks patterns like 'foo|bar'
Right. Any idea how to solve this dilemma?
Yes, don't run pacman in a shell, use open.
OK, I just gave it a try and it works flawlessly now. The code is even shorter and faster. I'll re-commit the patches very soon. -- Pierre Neidhardt
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 8e05a1a..5ca2cfd 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -124,7 +124,7 @@ foreach $_ (@syncpkgs) { # add a last field that indicates original order push (@pkgfields, $cnt++); # add each sync pkg by name/ver to a hash table for quick lookup - $allpkgs{$pkgfields[1]} = [ @pkgfields ]; + $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; } my $queryout = `pacman -Qs @ARGV`; @@ -141,14 +141,14 @@ foreach $_ (@querypkgs) { # skip any non-matching line next if not defined $pkgfields[1]; # check if the package was listed in the sync out - if (not exists $allpkgs{$pkgfields[1]}) { + if (not exists $allpkgs{$pkgfields[1] . $pkgfields[2]}) { # since 'group' is optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "[$LC_INSTALLED]"; # add a last field that indicates original order (after sync) push (@pkgfields, $cnt++); # add our local-only package to the hash - $allpkgs{$pkgfields[1]} = [ @pkgfields ]; + $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; } } -- 1.8.5.3
Package are processed in the same order as pacman output, so there is no need to sort, we can print directly. This makes the code simpler and faster. The only difference is that local packages will always be printed at the end. Previously, they were printe before multilib for instance. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 5ca2cfd..d1a19d6 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -81,21 +81,21 @@ if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") { # localization my $LC_INSTALLED = `gettext pacman installed`; -# Color a "repo/pkgname pkgver (groups) [installed]" line. -# We try to stick to pacman colors. -sub to_color { +# Print a "repo/pkgname pkgver (groups) [installed]" line. +# We stick to pacman colors. +sub print_pkg { my @v = @_; - my $line = "$RESET$BOLD"; + print "$RESET$BOLD"; if ( "$v[0]" eq "local" ) { - $line .= "$RED"; + print "$RED"; } else { - $line .= "$MAGENTA"; + print "$MAGENTA"; } - $line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; - $line .= " $BLUE$v[3]" if $v[3] ne ""; - $line .= " $CYAN$v[4]" if $v[4] ne ""; - $line .= " $RESET"; - return $line; + print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; + print " $BLUE$v[3]" if $v[3] ne ""; + print " $CYAN$v[4]" if $v[4] ne ""; + print " $RESET\n"; + print " $v[5]\n"; } my %allpkgs = (); @@ -121,10 +121,10 @@ foreach $_ (@syncpkgs) { # since 'group' and 'installed' are optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "" if not defined $pkgfields[4]; - # add a last field that indicates original order - push (@pkgfields, $cnt++); - # add each sync pkg by name/ver to a hash table for quick lookup - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + # Add each sync pkg by name/ver to a hash table. + # Any value is good since we only check for existence. + $allpkgs{$pkgfields[1] . $pkgfields[2]} = 1; + print_pkg(@pkgfields); } my $queryout = `pacman -Qs @ARGV`; @@ -145,20 +145,8 @@ foreach $_ (@querypkgs) { # since 'group' is optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "[$LC_INSTALLED]"; - # add a last field that indicates original order (after sync) - push (@pkgfields, $cnt++); - # add our local-only package to the hash - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + print_pkg(@pkgfields); } } -# sort by original order (the last field) and print -foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) { - my @v = @{$allpkgs{$_}}; - my $line = to_color(@v); - # print colorized "repo/pkgname pkgver ..." string with possible installed text - print "$line\n"; - print "$v[5]\n"; -} - #vim: set noet: -- 1.8.5.3
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Package are processed in the same order as pacman output, so there is no need to sort, we can print directly. This makes the code simpler and faster.
The only difference is that local packages will always be printed at the end. Previously, they were printe before multilib for instance.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-)
This will cause a large delay between printing sync and local results on first runs.
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 5ca2cfd..d1a19d6 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -81,21 +81,21 @@ if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") { # localization my $LC_INSTALLED = `gettext pacman installed`;
-# Color a "repo/pkgname pkgver (groups) [installed]" line. -# We try to stick to pacman colors. -sub to_color { +# Print a "repo/pkgname pkgver (groups) [installed]" line. +# We stick to pacman colors. +sub print_pkg { my @v = @_; - my $line = "$RESET$BOLD"; + print "$RESET$BOLD"; if ( "$v[0]" eq "local" ) { - $line .= "$RED"; + print "$RED"; } else { - $line .= "$MAGENTA"; + print "$MAGENTA"; } - $line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; - $line .= " $BLUE$v[3]" if $v[3] ne ""; - $line .= " $CYAN$v[4]" if $v[4] ne ""; - $line .= " $RESET"; - return $line; + print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; + print " $BLUE$v[3]" if $v[3] ne ""; + print " $CYAN$v[4]" if $v[4] ne ""; + print " $RESET\n"; + print " $v[5]\n"; }
my %allpkgs = (); @@ -121,10 +121,10 @@ foreach $_ (@syncpkgs) { # since 'group' and 'installed' are optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "" if not defined $pkgfields[4]; - # add a last field that indicates original order - push (@pkgfields, $cnt++); - # add each sync pkg by name/ver to a hash table for quick lookup - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + # Add each sync pkg by name/ver to a hash table. + # Any value is good since we only check for existence. + $allpkgs{$pkgfields[1] . $pkgfields[2]} = 1; + print_pkg(@pkgfields); }
my $queryout = `pacman -Qs @ARGV`; @@ -145,20 +145,8 @@ foreach $_ (@querypkgs) { # since 'group' is optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "[$LC_INSTALLED]"; - # add a last field that indicates original order (after sync) - push (@pkgfields, $cnt++); - # add our local-only package to the hash - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + print_pkg(@pkgfields); } }
-# sort by original order (the last field) and print -foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) { - my @v = @{$allpkgs{$_}}; - my $line = to_color(@v); - # print colorized "repo/pkgname pkgver ..." string with possible installed text - print "$line\n"; - print "$v[5]\n"; -} - #vim: set noet: -- 1.8.5.3
On 14-02-03 07:34:22, Andrew Gregory wrote:
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
Package are processed in the same order as pacman output, so there is no need to sort, we can print directly. This makes the code simpler and faster.
The only difference is that local packages will always be printed at the end. Previously, they were printe before multilib for instance.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-)
This will cause a large delay between printing sync and local results on first runs.
Well, "large" is very relative... Anyhow, this is overall faster than previously. I don't think that having a hang between both searches in the middle instead of the beginning matters much.
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 5ca2cfd..d1a19d6 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -81,21 +81,21 @@ if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") { # localization my $LC_INSTALLED = `gettext pacman installed`;
-# Color a "repo/pkgname pkgver (groups) [installed]" line. -# We try to stick to pacman colors. -sub to_color { +# Print a "repo/pkgname pkgver (groups) [installed]" line. +# We stick to pacman colors. +sub print_pkg { my @v = @_; - my $line = "$RESET$BOLD"; + print "$RESET$BOLD"; if ( "$v[0]" eq "local" ) { - $line .= "$RED"; + print "$RED"; } else { - $line .= "$MAGENTA"; + print "$MAGENTA"; } - $line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; - $line .= " $BLUE$v[3]" if $v[3] ne ""; - $line .= " $CYAN$v[4]" if $v[4] ne ""; - $line .= " $RESET"; - return $line; + print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; + print " $BLUE$v[3]" if $v[3] ne ""; + print " $CYAN$v[4]" if $v[4] ne ""; + print " $RESET\n"; + print " $v[5]\n"; }
my %allpkgs = (); @@ -121,10 +121,10 @@ foreach $_ (@syncpkgs) { # since 'group' and 'installed' are optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "" if not defined $pkgfields[4]; - # add a last field that indicates original order - push (@pkgfields, $cnt++); - # add each sync pkg by name/ver to a hash table for quick lookup - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + # Add each sync pkg by name/ver to a hash table. + # Any value is good since we only check for existence. + $allpkgs{$pkgfields[1] . $pkgfields[2]} = 1; + print_pkg(@pkgfields); }
my $queryout = `pacman -Qs @ARGV`; @@ -145,20 +145,8 @@ foreach $_ (@querypkgs) { # since 'group' is optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; $pkgfields[4] = "[$LC_INSTALLED]"; - # add a last field that indicates original order (after sync) - push (@pkgfields, $cnt++); - # add our local-only package to the hash - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ]; + print_pkg(@pkgfields); } }
-# sort by original order (the last field) and print -foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) { - my @v = @{$allpkgs{$_}}; - my $line = to_color(@v); - # print colorized "repo/pkgname pkgver ..." string with possible installed text - print "$line\n"; - print "$v[5]\n"; -} - #vim: set noet: -- 1.8.5.3
-- Pierre Neidhardt "For three days after death hair and fingernails continue to grow but phone calls taper off." -- Johnny Carson
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index d1a19d6..e16b78a 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -136,8 +136,9 @@ if ($#querypkgs >= 0) { } foreach $_ (@querypkgs) { - # we grab the following fields: repo, name, ver, group, installed, and desc - my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))? ?(\[.*\])?\n(.*)$/s; + # We grab the same field as before, even the "installed" which is always + # empty for local searches. This allows us to reserve a cell in @pkgfields. + my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))?()?\n(.*)$/s; # skip any non-matching line next if not defined $pkgfields[1]; # check if the package was listed in the sync out -- 1.8.5.3
We include the leading space in the match for 'group' and 'installed'. This allows us to remove the conditions when printing. Shorter and faster. (Even though it is a tiny detail.) Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index e16b78a..2be62c6 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -91,11 +91,8 @@ sub print_pkg { } else { print "$MAGENTA"; } - print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; - print " $BLUE$v[3]" if $v[3] ne ""; - print " $CYAN$v[4]" if $v[4] ne ""; - print " $RESET\n"; - print " $v[5]\n"; + print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]$BLUE$v[3]$CYAN$v[4]$RESET\n"; + print "$v[5]\n"; } my %allpkgs = (); @@ -111,8 +108,10 @@ if ($#syncpkgs >= 0) { # counter var for packages, used here and in the query loop too my $cnt = 0; foreach $_ (@syncpkgs) { - # we grab the following fields: repo, name, ver, group, installed, and desc - my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))? ?(\[.*\])?\n(.*)$/s; + # We grab the following fields: repo, name, ver, group, installed, and + # desc. We grab leading space for 'group' and 'installed' so that we do not + # need to test if non-empty when printing. + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?\n(.*)$/s; if(not @pkgfields) { # skip any non-matching line and just print it for the user print $_, "\n"; @@ -138,14 +137,14 @@ if ($#querypkgs >= 0) { foreach $_ (@querypkgs) { # We grab the same field as before, even the "installed" which is always # empty for local searches. This allows us to reserve a cell in @pkgfields. - my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))?()?\n(.*)$/s; + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?()?\n(.*)$/s; # skip any non-matching line next if not defined $pkgfields[1]; # check if the package was listed in the sync out if (not exists $allpkgs{$pkgfields[1] . $pkgfields[2]}) { # since 'group' is optional, we should fill it in if necessary $pkgfields[3] = "" if not defined $pkgfields[3]; - $pkgfields[4] = "[$LC_INSTALLED]"; + $pkgfields[4] = " [$LC_INSTALLED]"; print_pkg(@pkgfields); } } -- 1.8.5.3
participants (2)
-
Andrew Gregory
-
Pierre Neidhardt