[pacman-dev] [PATCHv4 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.4
In the old pacsearch, packages were identified uniquely by pkgfields[1], which contained pkgname+pkgver. Since commit 4d13558 pkgver is stored in pkgfields[2], and packages have been identified with pkgfields[1] only. Because of that packages with a different version would appear once only. This fixes the regression by identifying packages with both pkgfields[1] and pkgfields[2]. 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 71e0107..d3d461f 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.4
Package are processed in the same order as pacman output, so there is no real need to sort. This makes the code simpler and faster. The only difference is that local packages will always be printed at the end. Previously, they were printed before multilib for instance. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index d3d461f..91cf364 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -81,24 +81,25 @@ 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 = (); +my @pkglist = (); my $syncout = `pacman -Ss '@ARGV'`; # split each sync search entry into its own array entry @@ -108,8 +109,6 @@ if ($#syncpkgs >= 0) { chomp($syncpkgs[$#syncpkgs]); } -# 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; @@ -121,10 +120,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; + push (@pkglist, \@pkgfields); } my $queryout = `pacman -Qs '@ARGV'`; @@ -145,20 +144,12 @@ 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 ]; + push (@pkglist, \@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"; +foreach (@pkglist) { + print_pkg (@{$_}); } #vim: set noet: -- 1.8.5.4
We include the leading space in the match for 'group' and 'installed'. This allows us to remove the conditions when printing. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 91cf364..0ab840e 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 = (); @@ -110,8 +107,10 @@ if ($#syncpkgs >= 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"; @@ -135,15 +134,16 @@ 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 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]"; push (@pkglist, \@pkgfields); } } -- 1.8.5.4
On 14/02/14 22:18, Pierre Neidhardt wrote:
We include the leading space in the match for 'group' and 'installed'. This allows us to remove the conditions when printing.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> ---
I'm guessing patches 1 to 4 have not changed. I had pulled the old versions onto my patchqueue branch and am feeling too lazy to check. In the future, only resubmit the ones that have changed. We have patchwork to keep track of the rest. Allan
On 14-02-15 11:15:24, Allan McRae wrote:
On 14/02/14 22:18, Pierre Neidhardt wrote:
We include the leading space in the match for 'group' and 'installed'. This allows us to remove the conditions when printing.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> ---
I'm guessing patches 1 to 4 have not changed. I had pulled the old versions onto my patchqueue branch and am feeling too lazy to check.
Right, changes start from patch 5.
In the future, only resubmit the ones that have changed. We have patchwork to keep track of the rest.
Allan
Didn't know that, thanks for telling me. -- Pierre Neidhardt "I'd love to go out with you, but I'm taking punk totem pole carving."
Previously only one pattern was allowed. $ pacsearch foo bar Search for packages containing 'foo bar'. $ pacman -Ss foo bar Search for packages containing both 'foo' and 'bar'. Note that removing the quotes from the call was not enough since $ pacsearch 'foo|bar' would then fail. Note the use of '--' to indicate the end of option parsing. This way we ensure that input will always be valid and we need not input checks anymore. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 0ab840e..18d4641 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -92,61 +92,46 @@ sub print_pkg { print "$MAGENTA"; } print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]$BLUE$v[3]$CYAN$v[4]$RESET\n"; - print "$v[5]\n"; + print "$v[5]"; } my %allpkgs = (); my @pkglist = (); -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 -if ($#syncpkgs >= 0) { - chomp($syncpkgs[$#syncpkgs]); -} - -foreach $_ (@syncpkgs) { +open (my $syncout, '-|', 'pacman', '-Ss', '--', @ARGV) or exit 1; +while ( readline($syncout) ) { # 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"; - next; - } + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; + my $desc = readline($syncout); # 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]; + $pkgfields[5] = $desc; # 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; push (@pkglist, \@pkgfields); } +close ($syncout); -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 -if ($#querypkgs >= 0) { - chomp ($querypkgs[$#querypkgs]); -} - -foreach $_ (@querypkgs) { +open (my $queryout, '-|', 'pacman', '-Qs', '--', @ARGV) or exit 1; +while ( readline($queryout) ) { # 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]; + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; + my $desc = readline($queryout); # 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[5] = $desc; push (@pkglist, \@pkgfields); } } +close ($queryout); foreach (@pkglist) { print_pkg (@{$_}); -- 1.8.5.4
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 55 +++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 18d4641..a89328d 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -95,46 +95,31 @@ sub print_pkg { print "$v[5]"; } -my %allpkgs = (); -my @pkglist = (); - -open (my $syncout, '-|', 'pacman', '-Ss', '--', @ARGV) or exit 1; -while ( readline($syncout) ) { - # 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 = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; - my $desc = readline($syncout); - # 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]; - $pkgfields[5] = $desc; - # 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; - push (@pkglist, \@pkgfields); -} -close ($syncout); - -open (my $queryout, '-|', 'pacman', '-Qs', '--', @ARGV) or exit 1; -while ( readline($queryout) ) { - # 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 = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; - my $desc = readline($queryout); - # 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 +sub list_pkg { + my $db = shift; + open (my $out, '-|', 'pacman', $db, '--', @ARGV) or exit 1; + my @pkglist = (); + while ( readline($out) ) { + # 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 = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; + my $desc = readline($out); + # since 'group' and 'installed' are optional, we should fill it in if + # necessary $pkgfields[3] = "" if not defined $pkgfields[3]; - $pkgfields[4] = " [$LC_INSTALLED]"; + $pkgfields[4] = "" if not defined $pkgfields[4]; $pkgfields[5] = $desc; push (@pkglist, \@pkgfields); } + close ($out); + return @pkglist; } -close ($queryout); -foreach (@pkglist) { - print_pkg (@{$_}); -} +my @sync = list_pkg('-Ss', @ARGV); +my %allpkgs = map {$_->[1] . $_->[2] => 1} @sync; +my @query = grep { not $allpkgs{$_->[1] . $_->[2]}} list_pkg('-Qs', @ARGV); +$_->[4] = " [$LC_INSTALLED]" foreach @query; +print_pkg (@{$_}) foreach (@sync, @query); #vim: set noet: -- 1.8.5.4
participants (2)
-
Allan McRae
-
Pierre Neidhardt