[pacman-dev] [PATCH 1/6] pacsearch: removed useless comment
Signed-off-by: Pierre Neidhardt
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
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
--- 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
--- 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
--- 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
--- 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
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
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
--- 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
--- 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
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
participants (2)
-
Andrew Gregory
-
Pierre Neidhardt