[pacman-dev] [PATCH v4 2/2] pacman: rework the UI of -F

2019-05-29 Thread morganamilo
Reworks the UI of -F according to FS#47949

In short -F replaces both -Fs and -Fo.

Searching for an exact path (target contains "/"), causes the output to
switch to the old -Fo output. Otherwise the old -Fs output is used.

Also strip the leading "/" from targets like how -Qo does.
---

Docs changed and wip title removed.

 doc/pacman.8.asciidoc |  14 ++---
 src/pacman/files.c| 125 --
 src/pacman/pacman.c   |  19 +--
 3 files changed, 53 insertions(+), 105 deletions(-)

diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
index fe95178d..68b62a90 100644
--- a/doc/pacman.8.asciidoc
+++ b/doc/pacman.8.asciidoc
@@ -488,14 +488,8 @@ File Options (apply to '-F')[[FO]]
 *-l, \--list*::
List the files owned by the queried package.
 
-*-s, \--search*::
-   Search package file names for matching strings.
-
 *-x, --regex*::
-   Treat arguments to '--search' as regular expressions.
-
-*-o, \--owns*::
-   Search for packages that own a particular file.
+   Interpret each query as a regular expression.
 
 *-q, \--quiet*::
Show less information for certain file operations. This is useful when
@@ -503,9 +497,9 @@ File Options (apply to '-F')[[FO]]
'--machinereadable' instead.
 
 *--machinereadable*::
-   Use a machine readable output format for '--list', '--search' and
-   '--owns'. The format is 'repository\0pkgname\0pkgver\0path\n' with '\0'
-   being the NULL character and '\n' a linefeed.
+   Print each match in a machine readable output format. The format is
+   'repository\0pkgname\0pkgver\0path\n' with '\0' being the NULL character
+   and '\n' a linefeed.
 
 Handling Config Files[[HCF]]
 
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 26f96a67..74d06815 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -58,53 +58,7 @@ static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, 
char *filename)
alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
-static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
-   int ret = 0;
-   alpm_list_t *t;
-
-   for(t = targets; t; t = alpm_list_next(t)) {
-   char *filename = t->data;
-   int found = 0;
-   alpm_list_t *s;
-   size_t len = strlen(filename);
-
-   while(len > 1 && filename[0] == '/') {
-   filename++;
-   len--;
-   }
-
-   for(s = syncs; s; s = alpm_list_next(s)) {
-   alpm_list_t *p;
-   alpm_db_t *repo = s->data;
-   alpm_list_t *packages = alpm_db_get_pkgcache(repo);
-
-   for(p = packages; p; p = alpm_list_next(p)) {
-   alpm_pkg_t *pkg = p->data;
-   alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
-
-   if(alpm_filelist_contains(files, filename)) {
-   if(config->op_f_machinereadable) {
-   
print_line_machinereadable(repo, pkg, filename);
-   } else if(!config->quiet) {
-   print_owned_by(repo, pkg, 
filename);
-   } else {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   }
-
-   found = 1;
-   }
-   }
-   }
-
-   if(!found) {
-   ret++;
-   }
-   }
-
-   return 0;
-}
-
-static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
char *exact_file)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
const colstr_t *colstr = >colstr;
@@ -117,6 +71,12 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg)
}
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
+   } else if(exact_file != NULL) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_owned_by(repo, pkg, filename);
+   }
} else {
alpm_list_t *ml;
printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo),
@@ -143,6 +103,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_list_t *s;
int found = 0;
regex_t reg;
+   size_t len = strlen(targ);
+   char 

Re: [pacman-dev] [PATCH v3 2/2] wip: pacman: rework the UI of -F

2019-05-29 Thread Allan McRae
On 29/5/19 7:30 am, morganamilo wrote:
> Reworks the UI of -F according to FS#47949
> 
> In short -F replaces both -Fs and -Fo.
> 
> Searching for an exact path (target contains "/"), causes the output to
> switch to the old -Fo output. Otherwise the old -Fs output is used.
> 
> Also strip the leading "/" from targets like how -Qo does.
> 
> TODO: docs
> ---
>  src/pacman/files.c  | 125 +---
>  src/pacman/pacman.c |  17 +-
>  2 files changed, 49 insertions(+), 93 deletions(-)
> 

This patch looks good to me.  Happy to apply with updated docs.

A