Re: [pacman-dev] [PATCH v2] wip: pacman: rework the UI of -F
On Sat, 20 Apr 2019 at 19:38, morganamilo wrote: > > Reworks the UI of -F according to FS#47949 > > In short -F replaces both -Fs and -Fo. > --regex/-x has been replaced with --search/-s. > --oneline/-o can be used to change the output format to match the old -Fo > > Signed-off-by: morganamilo > --- > > v1: > This patch is WIP. Functional changes made, > documentation still needs to be changed. > > Additionally I think > https://bugs.archlinux.org/task/47949#comment143477 > Is a good idea and I will probably be included in v2 > > v2: > added --oneline/-o > > diff --git a/src/pacman/conf.h b/src/pacman/conf.h > index f45ed436..523b54a5 100644 > --- a/src/pacman/conf.h > +++ b/src/pacman/conf.h > @@ -90,8 +90,8 @@ typedef struct __config_t { > unsigned short op_s_search; > unsigned short op_s_upgrade; > > - unsigned short op_f_regex; > unsigned short op_f_machinereadable; > + unsigned short op_f_oneline; > > unsigned short group; > unsigned short noask; > @@ -200,6 +200,7 @@ enum { > OP_SEARCH, > OP_REGEX, > OP_MACHINEREADABLE, > + OP_ONELINE, > OP_UNREQUIRED, > OP_UPGRADES, > OP_SYSUPGRADE, > diff --git a/src/pacman/files.c b/src/pacman/files.c > index 3ebd9b9b..905e16ed 100644 > --- a/src/pacman/files.c > +++ b/src/pacman/files.c > @@ -49,54 +49,13 @@ static void dump_pkg_machinereadable(alpm_db_t *db, > alpm_pkg_t *pkg) > } > } > > -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) { > - const colstr_t *colstr = > &config->colstr; > - printf(_("%s is owned by > %s%s/%s%s %s%s%s\n"), filename, > - colstr->repo, > alpm_db_get_name(repo), colstr->title, > - > alpm_pkg_get_name(pkg), colstr->version, > - > alpm_pkg_get_version(pkg), colstr->nocolor); > - } 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_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, char *filename) > +{ > + const colstr_t *colstr = &config->colstr; > + printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename, > + colstr->repo, alpm_db_get_name(db), colstr->title, > + alpm_pkg_get_name(pkg), colstr->version, > + alpm_pkg_get_version(pkg), colstr->nocolor); > } > > static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg) > @@ -110,6 +69,12 @@ static void print_match(alpm_list_t *match, alpm_db_t > *repo, alpm_pkg_t *pkg) > char *filename = ml->data; > print_line_machinereadable(repo, pkg, filename); > } > + } else if(config->op_f_oneline) { > + alpm_list_t *ml; > + for(ml = match; ml; ml = alpm_list_next(ml)) { > + char *filename = ml->data; > + print_owned_by(repo, pkg, filename); > + } > } else if(config->quiet) { > printf("%s/%s\n", alpm_db_get_name(repo), > alpm_pkg_get_name(pkg)); > } else { > @@ -138,6
[pacman-dev] [PATCH v2] wip: pacman: rework the UI of -F
Reworks the UI of -F according to FS#47949 In short -F replaces both -Fs and -Fo. --regex/-x has been replaced with --search/-s. --oneline/-o can be used to change the output format to match the old -Fo Signed-off-by: morganamilo --- v1: This patch is WIP. Functional changes made, documentation still needs to be changed. Additionally I think https://bugs.archlinux.org/task/47949#comment143477 Is a good idea and I will probably be included in v2 v2: added --oneline/-o diff --git a/src/pacman/conf.h b/src/pacman/conf.h index f45ed436..523b54a5 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -90,8 +90,8 @@ typedef struct __config_t { unsigned short op_s_search; unsigned short op_s_upgrade; - unsigned short op_f_regex; unsigned short op_f_machinereadable; + unsigned short op_f_oneline; unsigned short group; unsigned short noask; @@ -200,6 +200,7 @@ enum { OP_SEARCH, OP_REGEX, OP_MACHINEREADABLE, + OP_ONELINE, OP_UNREQUIRED, OP_UPGRADES, OP_SYSUPGRADE, diff --git a/src/pacman/files.c b/src/pacman/files.c index 3ebd9b9b..905e16ed 100644 --- a/src/pacman/files.c +++ b/src/pacman/files.c @@ -49,54 +49,13 @@ static void dump_pkg_machinereadable(alpm_db_t *db, alpm_pkg_t *pkg) } } -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) { - const colstr_t *colstr = &config->colstr; - printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename, - colstr->repo, alpm_db_get_name(repo), colstr->title, - alpm_pkg_get_name(pkg), colstr->version, - alpm_pkg_get_version(pkg), colstr->nocolor); - } 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_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, char *filename) +{ + const colstr_t *colstr = &config->colstr; + printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename, + colstr->repo, alpm_db_get_name(db), colstr->title, + alpm_pkg_get_name(pkg), colstr->version, + alpm_pkg_get_version(pkg), colstr->nocolor); } static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg) @@ -110,6 +69,12 @@ static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg) char *filename = ml->data; print_line_machinereadable(repo, pkg, filename); } + } else if(config->op_f_oneline) { + alpm_list_t *ml; + for(ml = match; ml; ml = alpm_list_next(ml)) { + char *filename = ml->data; + print_owned_by(repo, pkg, filename); + } } else if(config->quiet) { printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); } else { @@ -138,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 *exact_file = strchr(targ, '/'); + + if(exa