xbps-repo: indent pkgs from all repos with longest pkgver found.

This commit is contained in:
Juan RP 2012-08-01 08:25:15 +02:00
parent 01c2dcaca7
commit cae219c4de
4 changed files with 50 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -31,6 +31,7 @@
struct repo_search_data {
int npatterns;
char **patterns;
void *arg;
size_t pkgver_len;
size_t maxcols;
};
@ -54,6 +55,7 @@ void release_repo_lock(char **, int);
int repo_find_files_in_packages(struct xbps_handle *, int, char **);
/* From list.c */
size_t repo_find_longest_pkgver(struct xbps_handle *);
int repo_pkg_list_cb(struct xbps_handle *,
struct xbps_rpool_index *,
void *,

View File

@ -34,6 +34,37 @@
#include "defs.h"
#include "../xbps-bin/defs.h"
static int
repo_longest_pkgver(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
size_t *len = arg, olen = 0;
(void)done;
if (*len == 0) {
*len = find_longest_pkgver(xhp, rpi->repo);
return 0;
}
olen = find_longest_pkgver(xhp, rpi->repo);
if (olen > *len)
*len = olen;
return 0;
}
size_t
repo_find_longest_pkgver(struct xbps_handle *xhp)
{
size_t len = 0;
xbps_rpool_foreach(xhp, repo_longest_pkgver, &len);
return len;
}
int
repo_pkg_list_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
@ -41,16 +72,16 @@ repo_pkg_list_cb(struct xbps_handle *xhp,
bool *done)
{
struct list_pkgver_cb lpc;
const char *repo = arg;
struct repo_search_data *rsd = arg;
(void)done;
if (repo && strcmp(rpi->uri, repo))
if (rsd->arg && strcmp(rpi->uri, rsd->arg))
return 0;
lpc.check_state = false;
lpc.state = 0;
lpc.pkgver_len = find_longest_pkgver(xhp, rpi->repo);
lpc.maxcols = get_maxcols();
lpc.pkgver_len = rsd->pkgver_len;
lpc.maxcols = rsd->maxcols;
(void)xbps_callback_array_iter(xhp, rpi->repo, list_pkgs_in_dict, &lpc);
@ -82,9 +113,6 @@ repo_search_pkgs_cb(struct xbps_handle *xhp,
struct repo_search_data *rsd = arg;
(void)done;
rsd->maxcols = get_maxcols();
rsd->pkgver_len = find_longest_pkgver(xhp, rpi->repo);
(void)xbps_callback_array_iter(xhp, rpi->repo, show_pkg_namedesc, rsd);
return 0;

View File

@ -90,7 +90,7 @@ main(int argc, char **argv)
{
struct xbps_handle xh;
struct xferstat xfer;
struct repo_search_data *rsd = NULL;
struct repo_search_data rsd;
prop_dictionary_t pkgd;
const char *rootdir, *cachedir, *conffile, *option;
int flags = 0, c, rv = 0;
@ -170,7 +170,11 @@ main(int argc, char **argv)
if (argc < 1 || argc > 2)
usage(true);
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, argv[1]);
rsd.arg = argv[1];
rsd.pkgver_len = repo_find_longest_pkgver(&xh);
rsd.maxcols = get_maxcols();
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, &rsd);
if (rv == ENOTSUP)
xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n");
@ -185,15 +189,12 @@ main(int argc, char **argv)
if (argc < 2)
usage(true);
rsd = malloc(sizeof(*rsd));
if (rsd == NULL) {
rv = ENOMEM;
goto out;
}
rsd->npatterns = argc;
rsd->patterns = argv;
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, rsd);
free(rsd);
rsd.npatterns = argc;
rsd.patterns = argv;
rsd.pkgver_len = repo_find_longest_pkgver(&xh);
rsd.maxcols = get_maxcols();
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, &rsd);
if (rv == ENOTSUP)
xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n");