[pacman-dev] [PATCH] Add new -Sq / --needed option.
This patch is the result of the constatation than, during one pacman operation, the "local version is up to date. Upgrade anyway?" questions are usually all answered either by yes or by no. Yes when you want to reinstall all the targets. No when you only want to install the missing ones (either because you are installing a group, or because you are copying a pacman -S line from wiki or whatever). So instead of asking this question for every targets, it'll now be configured with a flag. Yes will be the default -S behavior, No will be achieved with the --needed flag. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> --- contrib/bash_completion | 2 ++ doc/pacman.8.txt | 3 +++ lib/libalpm/alpm.h | 5 +++-- lib/libalpm/sync.c | 17 ++++++++--------- src/pacman/callback.c | 11 ----------- src/pacman/pacman.c | 7 +++++-- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/contrib/bash_completion b/contrib/bash_completion index 6aafc9e..c392217 100644 --- a/contrib/bash_completion +++ b/contrib/bash_completion @@ -170,6 +170,7 @@ _pacman () info) mod="${mod}i" ;; list) mod="${mod}l" ;; print-uris) mod="${mod}p" ;; + needed) mod="${mod}q" ;; search) mod="${mod}s" ;; sysupgrade) mod="${mod}u" ;; upgrades) mod="${mod}u" ;; @@ -268,6 +269,7 @@ _pacman () -i --info \ -l --list \ -p --print-uris \ + -q --needed \ -s --search \ -u --sysupgrade \ -w --downloadonly \ diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 7b10bc0..a8af743 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -243,6 +243,9 @@ Sync Options[[SO]] dependencies yet to be installed. These can be piped to a file and downloaded at a later time, using a program like wget. +*-q, \--needed*:: + Only install the targets that are not already installed and up-to-date. + *-s, \--search* <'regexp'>:: This will search each package in the sync databases for names or descriptions that match `regexp`. diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index b56f575..7b3b8b0 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -280,7 +280,8 @@ typedef enum _pmtransflag_t { PM_TRANS_FLAG_DOWNLOADONLY = 0x200, PM_TRANS_FLAG_NOSCRIPTLET = 0x400, PM_TRANS_FLAG_NOCONFLICTS = 0x800, - PM_TRANS_FLAG_PRINTURIS = 0x1000 + PM_TRANS_FLAG_PRINTURIS = 0x1000, + PM_TRANS_FLAG_NEEDED = 0x2000 } pmtransflag_t; /* Transaction Events */ @@ -321,7 +322,7 @@ typedef enum _pmtransconv_t { PM_TRANS_CONV_CONFLICT_PKG = 0x04, PM_TRANS_CONV_CORRUPTED_PKG = 0x08, PM_TRANS_CONV_LOCAL_NEWER = 0x10, - PM_TRANS_CONV_LOCAL_UPTODATE = 0x20, + /* 0x20 flag can go here */ PM_TRANS_CONV_REMOVE_HOLDPKG = 0x40 } pmtransconv_t; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 16b1998..a3cd180 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -352,15 +352,14 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy local = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(spkg)); if(local) { if(alpm_pkg_compare_versions(local, spkg) == 0) { - /* spkg is NOT an upgrade, get confirmation before adding */ - if(!(trans->flags & PM_TRANS_FLAG_PRINTURIS)) { - int resp = 0; - QUESTION(trans, PM_TRANS_CONV_LOCAL_UPTODATE, local, NULL, NULL, &resp); - if(!resp) { - _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"), - alpm_pkg_get_name(local), alpm_pkg_get_version(local)); - return(0); - } + /* spkg is NOT an upgrade */ + if(trans->flags & PM_TRANS_FLAG_NEEDED) { + _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"), + alpm_pkg_get_name(local), alpm_pkg_get_version(local)); + return(0); + } else { + _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"), + alpm_pkg_get_name(local), alpm_pkg_get_version(local)); } } } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 232ca4c..dd469ec 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -305,7 +305,6 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, *response = yesno(str); break; case PM_TRANS_CONV_LOCAL_NEWER: - if(!config->op_s_downloadonly) { snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "), alpm_pkg_get_name(data1), @@ -315,16 +314,6 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, *response = 1; } break; - case PM_TRANS_CONV_LOCAL_UPTODATE: - if(!config->op_s_downloadonly) { - snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "), - alpm_pkg_get_name(data1), - alpm_pkg_get_version(data1)); - *response = yesno(str); - } else { - *response = 1; - } - break; case PM_TRANS_CONV_CORRUPTED_PKG: if(!config->noconfirm) { snprintf(str, LOG_STR_LEN, _(":: File %s is corrupted. Do you want to delete it? [Y/n] "), diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 31d31da..229fce3 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -129,6 +129,7 @@ static void usage(int op, const char * const myname) printf(_(" -i, --info view package information\n")); printf(_(" -l, --list <repo> view a list of packages in a repo\n")); printf(_(" -p, --print-uris print out URIs for given packages and their dependencies\n")); + printf(_(" -q, --needed only install outdated or not yet installed packages\n")); printf(_(" -s, --search <regex> search remote repositories for matching strings\n")); printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n")); printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n")); @@ -287,11 +288,12 @@ static int parseargs(int argc, char *argv[]) {"info", no_argument, 0, 'i'}, {"dbonly", no_argument, 0, 'k'}, {"list", no_argument, 0, 'l'}, - {"nosave", no_argument, 0, 'n'}, {"foreign", no_argument, 0, 'm'}, + {"nosave", no_argument, 0, 'n'}, {"owns", no_argument, 0, 'o'}, {"file", no_argument, 0, 'p'}, {"print-uris", no_argument, 0, 'p'}, + {"needed", no_argument, 0, 'q'}, {"root", required_argument, 0, 'r'}, {"recursive", no_argument, 0, 's'}, {"search", no_argument, 0, 's'}, @@ -314,7 +316,7 @@ static int parseargs(int argc, char *argv[]) {0, 0, 0, 0} }; - while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { + while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepqituwygz", opts, &option_index))) { alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */ if(opt < 0) { @@ -431,6 +433,7 @@ static int parseargs(int argc, char *argv[]) config->op_q_isfile = 1; config->flags |= PM_TRANS_FLAG_PRINTURIS; break; + case 'q': config->flags |= PM_TRANS_FLAG_NEEDED; break; case 'r': if(alpm_option_set_root(optarg) != 0) { pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"), -- 1.5.3.6
This patch is the result of the constatation than, during one pacman operation, the "local version is up to date. Upgrade anyway?" questions are usually all answered either by yes or by no.
Yes when you want to reinstall all the targets. No when you only want to install the missing ones (either because you are installing a group, or because you are copying a pacman -S line from wiki or whatever).
So instead of asking this question for every targets, it'll now be configured with a flag. Yes will be the default -S behavior, No will be achieved with the --needed flag.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Wow, you are really active now. Great, I like this feature. Now I will be an asshole (please don't kill me;-): 1. Personally I would have kept the current behaviour (ask for user, he may answer mixed answers), and add an option for both "answer-yes" and "answer-no". Because usually when I get this question (copy-paste from wiki ;-), my reaction is ctrl-c (<=> I want to do answer-no)... 2. This will be a contra for my -Ru patch too: This should be handled in front-end's callback.c imho (to keep libalpm as flexible as possible), and that should answer the question automatically. This is similar to ask, but new command-line options for each question-type is much clearer imho. 3. I go further: Even remove_cascade and remove_unneeded should be done in front-end. This could be an "interactive" remove-dependency-error resolving: "Removal of foo would break the bar dependency of baz." "Do you want to keep foo?" [REMOVE_UNNEDED answers yes, default answer no], if the answer was no: "Do you want to also remove baz?" [REMOVE_CASCADE answers yes, default: no]... if the answer was no: depcheck error What's more, this can be handy in case of resolvedeps, this would help pacman (== user) choose a proper satisfier. "To-be-installed foo has an unsatisfied dependency bar. Baz satisfies bar. Do you want to install baz?" [default answer: yes; optional: no <- no dependency resolve, BUT exit with error; optional: prompt to user <- user can find his favourite dependency].... Well, this mail may be a bit chaotic (random new ideas in my mind), sry. Bye ---------------------------------------------------- SZTE Egyetemi Könyvtár - http://www.bibl.u-szeged.hu This mail sent through IMP: http://horde.org/imp/
On Sat, Nov 24, 2007 at 02:55:24PM +0100, Nagy Gabor wrote:
Wow, you are really active now. Great, I like this feature.
Now I will be an asshole (please don't kill me;-): 1. Personally I would have kept the current behaviour (ask for user, he may answer mixed answers), and add an option for both "answer-yes" and "answer-no". Because usually when I get this question (copy-paste from wiki ;-), my reaction is ctrl-c (<=> I want to do answer-no)... 2. This will be a contra for my -Ru patch too: This should be handled in front-end's callback.c imho (to keep libalpm as flexible as possible), and that should answer the question automatically. This is similar to ask, but new command-line options for each question-type is much clearer imho. 3. I go further: Even remove_cascade and remove_unneeded should be done in front-end. This could be an "interactive" remove-dependency-error resolving: "Removal of foo would break the bar dependency of baz." "Do you want to keep foo?" [REMOVE_UNNEDED answers yes, default answer no], if the answer was no: "Do you want to also remove baz?" [REMOVE_CASCADE answers yes, default: no]... if the answer was no: depcheck error What's more, this can be handy in case of resolvedeps, this would help pacman (== user) choose a proper satisfier. "To-be-installed foo has an unsatisfied dependency bar. Baz satisfies bar. Do you want to install baz?" [default answer: yes; optional: no <- no dependency resolve, BUT exit with error; optional: prompt to user <- user can find his favourite dependency]....
Well, this mail may be a bit chaotic (random new ideas in my mind), sry.
Handling this in callback.c might be a good idea, I don't know. If you believe it is, please provide a patch, it'll be easier to judge it :)
Hmm, Dan merged the 'quiet' patch already, which means -q is now taken 8) Maybe we only want a long option here?
On Mon, Nov 26, 2007 at 12:30:18PM -0600, Aaron Griffin wrote:
Hmm, Dan merged the 'quiet' patch already, which means -q is now taken 8)
Maybe we only want a long option here?
Yes, that's what I chose when rebasing my patch, so it's already done :) I felt it was not necessary to resubmit the patch on the ML since it's a minor change. I just updated it in my git repo, and it's available there.
On Nov 26, 2007 12:33 PM, Xavier <shiningxc@gmail.com> wrote:
On Mon, Nov 26, 2007 at 12:30:18PM -0600, Aaron Griffin wrote:
Hmm, Dan merged the 'quiet' patch already, which means -q is now taken 8)
Maybe we only want a long option here?
Yes, that's what I chose when rebasing my patch, so it's already done :) I felt it was not necessary to resubmit the patch on the ML since it's a minor change. I just updated it in my git repo, and it's available there.
Yeah, I didn't check yet - not at home, so no gitk 8)
participants (4)
-
Aaron Griffin
-
Chantry Xavier
-
Nagy Gabor
-
Xavier