[pacman-dev] [PATCH 1/4] CLI args: add pactest with an invalid combination
From: Jakob Gruber
From: Jakob Gruber
From: Jakob Gruber
The three parts (help, manpage and code) are now organized in the same
way and much easier to compare :
- specific options
- install/upgrade options for -S and -U
- transaction options for -S -R and -U
- global options
After this re-organization, it was easy to update and sync the three
components together. Duplication is also avoided.
Signed-off-by: Xavier Chantry
On 11/10/10 05:06, Xavier Chantry wrote:
The three parts (help, manpage and code) are now organized in the same way and much easier to compare : - specific options - install/upgrade options for -S and -U - transaction options for -S -R and -U - global options
After this re-organization, it was easy to update and sync the three components together. Duplication is also avoided.
Signed-off-by: Xavier Chantry
./src/pacman/pacman -D --help usage: lt-pacman {-D --database} <options>
This had actually been on my TODO list for a while so it is good to see it fixed. Overall, I think these look good. One small point: options: --asdeps mark packages as non-explicitly installed --asexplicit mark packages as explicitly installed -b, --dbpath <path> set an alternate database location -r, --root <path> set an alternate installation root -v, --verbose be verbose --arch <arch> set an alternate architecture --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation On my TODO list, I had also had removing --arch and --cachedir from -D and -Q as they are useless options there as far as I can tell. And --cachedir from -U. Slightly related, I wonder if we can shorten the description of "-k, --dbonly" and "--print" so they do not loop on an 80 width terminal. Or maybe add some line wrapping. Allan
On Mon, Oct 11, 2010 at 3:30 AM, Allan McRae
On 11/10/10 05:06, Xavier Chantry wrote:
The three parts (help, manpage and code) are now organized in the same way and much easier to compare : - specific options - install/upgrade options for -S and -U - transaction options for -S -R and -U - global options
After this re-organization, it was easy to update and sync the three components together. Duplication is also avoided.
Signed-off-by: Xavier Chantry
This had actually been on my TODO list for a while so it is good to see it fixed. Overall, I think these look good. One small point:
./src/pacman/pacman -D --help usage: lt-pacman {-D --database} <options>
options: --asdeps mark packages as non-explicitly installed --asexplicit mark packages as explicitly installed -b, --dbpath <path> set an alternate database location -r, --root <path> set an alternate installation root -v, --verbose be verbose --arch <arch> set an alternate architecture --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation On my TODO list, I had also had removing --arch and --cachedir from -D and -Q as they are useless options there as far as I can tell. And --cachedir from -U.
I hesitated about arch, but it looked like a general configuration option that would not hurt even for ops where it is not used. Same for cachedir. But also same for ignore, which is also specified in pacman.conf Jakob actually moved Ignore from just -S operation to global, which is also specified in pacman.conf I believe there is a difference between ignore and arch/cachedir : - arch/cachedir clearly have no impact on -D or -Q, they are just useless but can be mentioned - ignore/ignoregroup could have an impact on -D, -Q or -R but they don't have any, which might not be obvious That said, I am fine with moving stuff around, I will let Dan have the final vote on where arch cachedir and ignore should be.
Slightly related, I wonder if we can shorten the description of "-k, --dbonly" and "--print" so they do not loop on an 80 width terminal. Or maybe add some line wrapping.
Well I was looking at french translation, where half the description do not even fit a 100width terminal, so I don't really care :p But now that you mention dbonly, is this behavior really fine : -k, --dbonly Adds/Removes the database entry only, leaves all files in place. On an upgrade operation, the existing package and all files will be removed and the database entry for the new package will be added. I.E. when -S and -U are upgrade and not install, and they remove the existing local package, dbonly does not apply to the removal. files are actually deleted. This is quite weird for a 'dbonly' option, isn't it ? What if you want to use 'dbonly' because you modified all the package files (for example manual make install), but you just want to use and update the db entry with an arch package. There might be one case where I could actually need that. But as it is, dbonly looks quite weird and useless. the patch would just be 3 lines : diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index dfaba03..e0099fb 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -311,6 +311,9 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *tra _alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n", oldpkg->name, oldpkg->version); + if(trans->flags & PM_TRANS_FLAG_DBONLY) + goto db; + /* copy the remove skiplist over */ skip_remove = alpm_list_join(alpm_list_strdup(trans->skip_remove),alpm_list_strdup(handle->noupgrade)); @@ -345,6 +348,7 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *tra alpm_list_free(newfiles); FREELIST(skip_remove); +db: /* remove the package from the database */ _alpm_log(PM_LOG_DEBUG, "updating database\n"); _alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname); then the help and the description would also be shorter :)
On Sun, Oct 10, 2010 at 8:30 PM, Allan McRae
On 11/10/10 05:06, Xavier Chantry wrote:
The three parts (help, manpage and code) are now organized in the same way and much easier to compare : - specific options - install/upgrade options for -S and -U - transaction options for -S -R and -U - global options
After this re-organization, it was easy to update and sync the three components together. Duplication is also avoided.
Signed-off-by: Xavier Chantry
This had actually been on my TODO list for a while so it is good to see it fixed. Overall, I think these look good. One small point:
./src/pacman/pacman -D --help usage: lt-pacman {-D --database} <options>
options: --asdeps mark packages as non-explicitly installed --asexplicit mark packages as explicitly installed -b, --dbpath <path> set an alternate database location -r, --root <path> set an alternate installation root -v, --verbose be verbose --arch <arch> set an alternate architecture --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation On my TODO list, I had also had removing --arch and --cachedir from -D and -Q as they are useless options there as far as I can tell. And --cachedir from -U.
Slightly related, I wonder if we can shorten the description of "-k, --dbonly" and "--print" so they do not loop on an 80 width terminal. Or maybe add some line wrapping.
I'm not too thrilled abuot this patch for the fact that we lost alpha ordering by shortopt for sync/upgrade/remove options. This is a step backwards in my opinion. I can deal with the dbpath/root/every single op uses these things being at the bottom (and I think a blank line separating them would be good too), but the list seems very mismanaged for the main ops now. I pulled the other two patches in, but not this one. -Dan
On Tue, Oct 12, 2010 at 4:04 AM, Dan McGee
I'm not too thrilled abuot this patch for the fact that we lost alpha ordering by shortopt for sync/upgrade/remove options. This is a step backwards in my opinion.
I can deal with the dbpath/root/every single op uses these things being at the bottom (and I think a blank line separating them would be good too), but the list seems very mismanaged for the main ops now.
I pulled the other two patches in, but not this one.
usage: pacman {-S --sync} [options] [package(s)] options: --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed -c, --clean remove old packages from cache directory (-cc for all) -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -g, --groups view all members of a package group -i, --info view package information -l, --list <repo> view a list of packages in a repo -s, --search <regex> search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu allows downgrade) -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server --needed don't reinstall up to date packages --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --print only print the targets instead of performing the operation --print-format <string> specify how the targets should be printed -q, --quiet show less information for query and search --config <path> set an alternate configuration file --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists -v, --verbose be verbose --debug display debug messages -r, --root <path> set an alternate installation root -b, --dbpath <path> set an alternate database location --cachedir <dir> set an alternate package cache location --arch <arch> set an alternate architecture I don't understand why it is fine to have -q -v -r -b mixed up like that for the global section, but not have two other similar sections, which makes it much nicer to check consistency of code, --help and manpage. Isn't it nice to have that ? Maybe you can only appreciate that patch if you try checking the consistency before. Otherwise we can just do pacman -Sh | sort : --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed -b, --dbpath <path> set an alternate database location --cachedir <dir> set an alternate package cache location -c, --clean remove old packages from cache directory (-cc for all) --config <path> set an alternate configuration file --debug display debug messages -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -g, --groups view all members of a package group ignore a group upgrade (can be used more than once) --ignoregroup <grp> --ignore <pkg> ignore a package upgrade (can be used more than once) -i, --info view package information -k, --dbonly only modify database entries, not package files -l, --list <repo> view a list of packages in a repo --logfile <path> set an alternate log file --needed don't reinstall up to date packages --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print-format <string> --print only print the targets instead of performing the operation -q, --quiet show less information for query and search -r, --root <path> set an alternate installation root specify how the targets should be printed -s, --search <regex> search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu allows downgrade) -v, --verbose be verbose -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server I suppose I could do that in code, just replace all printf by addlist, sort the list at the end and print it. That way the options will always appear in the same order, no matter how they are written in the code.
On Tue, Oct 12, 2010 at 3:34 AM, Xavier Chantry
On Tue, Oct 12, 2010 at 4:04 AM, Dan McGee
wrote: I'm not too thrilled abuot this patch for the fact that we lost alpha ordering by shortopt for sync/upgrade/remove options. This is a step backwards in my opinion.
I can deal with the dbpath/root/every single op uses these things being at the bottom (and I think a blank line separating them would be good too), but the list seems very mismanaged for the main ops now.
I pulled the other two patches in, but not this one.
usage: pacman {-S --sync} [options] [package(s)] options: --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed -c, --clean remove old packages from cache directory (-cc for all) -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -g, --groups view all members of a package group -i, --info view package information -l, --list <repo> view a list of packages in a repo -s, --search <regex> search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu allows downgrade) -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server --needed don't reinstall up to date packages --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --print only print the targets instead of performing the operation --print-format <string> specify how the targets should be printed -q, --quiet show less information for query and search --config <path> set an alternate configuration file --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists -v, --verbose be verbose --debug display debug messages -r, --root <path> set an alternate installation root -b, --dbpath <path> set an alternate database location --cachedir <dir> set an alternate package cache location --arch <arch> set an alternate architecture
I don't understand why it is fine to have -q -v -r -b mixed up like that for the global section, but not have two other similar sections, which makes it much nicer to check consistency of code, --help and manpage. Isn't it nice to have that ? Maybe you can only appreciate that patch if you try checking the consistency before.
I don't know- I'm just saying it is a lot more noticeable now than it ever was before, maybe I was just too familiar with it. I'm not sure how the manpage plays into this though, I was only talking about --help.
Otherwise we can just do pacman -Sh | sort : --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed -b, --dbpath <path> set an alternate database location --cachedir <dir> set an alternate package cache location -c, --clean remove old packages from cache directory (-cc for all) --config <path> set an alternate configuration file --debug display debug messages -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -g, --groups view all members of a package group ignore a group upgrade (can be used more than once) --ignoregroup <grp> --ignore <pkg> ignore a package upgrade (can be used more than once) -i, --info view package information -k, --dbonly only modify database entries, not package files -l, --list <repo> view a list of packages in a repo --logfile <path> set an alternate log file --needed don't reinstall up to date packages --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print-format <string> --print only print the targets instead of performing the operation -q, --quiet show less information for query and search -r, --root <path> set an alternate installation root specify how the targets should be printed -s, --search <regex> search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu allows downgrade) -v, --verbose be verbose -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server
I suppose I could do that in code, just replace all printf by addlist, sort the list at the end and print it. That way the options will always appear in the same order, no matter how they are written in the code.
I thought of this but it almost seemed silly. However, it would work for the most part, right? I'm not against it. -Dan
Example with pacman -Uh : options: --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print only print the targets instead of performing the operation --print-format <string> specify how the targets should be printed -b, --dbpath <path> set an alternate database location -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -k, --dbonly add database entries, do not install or keep existing files -r, --root <path> set an alternate installation root -v, --verbose be verbose --- src/pacman/pacman.c | 110 +++++++++++++++++++++++++++----------------------- src/pacman/util.h | 1 + 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 933698e..f402eef 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -65,6 +65,8 @@ static alpm_list_t *pm_targets; */ static void usage(int op, const char * const myname) { +#define addlist(s) (list = alpm_list_add(list, s)) + alpm_list_t *list = NULL, *i; /* prefetch some strings for usage below, which moves a lot of calls * out of gettext. */ char const * const str_opt = _("options"); @@ -89,82 +91,88 @@ static void usage(int op, const char * const myname) if(op == PM_OP_REMOVE) { printf("%s: %s {-R --remove} [%s] <%s>\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); - printf(_(" -c, --cascade remove packages and all packages that depend on them\n")); - printf(_(" -k, --dbonly only remove database entries, do not remove files\n")); - printf(_(" -n, --nosave remove configuration files as well\n")); - printf(_(" -s, --recursive remove dependencies also (that won't break packages)\n" + addlist(_(" -c, --cascade remove packages and all packages that depend on them\n")); + addlist(_(" -k, --dbonly only remove database entries, do not remove files\n")); + addlist(_(" -n, --nosave remove configuration files as well\n")); + addlist(_(" -s, --recursive remove dependencies also (that won't break packages)\n" " (-ss includes explicitly installed dependencies too)\n")); - printf(_(" -u, --unneeded remove unneeded packages (that won't break packages)\n")); + addlist(_(" -u, --unneeded remove unneeded packages (that won't break packages)\n")); } else if(op == PM_OP_UPGRADE) { printf("%s: %s {-U --upgrade} [%s] <%s>\n", str_usg, myname, str_opt, str_file); printf("%s:\n", str_opt); } else if(op == PM_OP_QUERY) { printf("%s: %s {-Q --query} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); - printf(_(" -c, --changelog view the changelog of a package\n")); - printf(_(" -d, --deps list packages installed as dependencies [filter]\n")); - printf(_(" -e, --explicit list packages explicitly installed [filter]\n")); - printf(_(" -g, --groups view all members of a package group\n")); - printf(_(" -i, --info view package information (-ii for backup files)\n")); - printf(_(" -k, --check check that the files owned by the package(s) are present\n")); - printf(_(" -l, --list list the contents of the queried package\n")); - printf(_(" -m, --foreign list installed packages not found in sync db(s) [filter]\n")); - printf(_(" -o, --owns <file> query the package that owns <file>\n")); - printf(_(" -p, --file <package> query a package file instead of the database\n")); - printf(_(" -q, --quiet show less information for query and search\n")); - printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n")); - printf(_(" -t, --unrequired list packages not required by any package [filter]\n")); - printf(_(" -u, --upgrades list outdated packages [filter]\n")); + addlist(_(" -c, --changelog view the changelog of a package\n")); + addlist(_(" -d, --deps list packages installed as dependencies [filter]\n")); + addlist(_(" -e, --explicit list packages explicitly installed [filter]\n")); + addlist(_(" -g, --groups view all members of a package group\n")); + addlist(_(" -i, --info view package information (-ii for backup files)\n")); + addlist(_(" -k, --check check that the files owned by the package(s) are present\n")); + addlist(_(" -l, --list list the contents of the queried package\n")); + addlist(_(" -m, --foreign list installed packages not found in sync db(s) [filter]\n")); + addlist(_(" -o, --owns <file> query the package that owns <file>\n")); + addlist(_(" -p, --file <package> query a package file instead of the database\n")); + addlist(_(" -q, --quiet show less information for query and search\n")); + addlist(_(" -s, --search <regex> search locally-installed packages for matching strings\n")); + addlist(_(" -t, --unrequired list packages not required by any package [filter]\n")); + addlist(_(" -u, --upgrades list outdated packages [filter]\n")); } else if(op == PM_OP_SYNC) { printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); - printf(_(" -c, --clean remove old packages from cache directory (-cc for all)\n")); - printf(_(" -g, --groups view all members of a package group\n")); - printf(_(" -i, --info view package information\n")); - printf(_(" -l, --list <repo> view a list of packages in a repo\n")); - printf(_(" -q, --quiet show less information for query and search\n")); - printf(_(" -s, --search <regex> search remote repositories for matching strings\n")); - printf(_(" -u, --sysupgrade upgrade installed packages (-uu allows downgrade)\n")); - printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n")); - printf(_(" -y, --refresh download fresh package databases from the server\n")); - printf(_(" --needed don't reinstall up to date packages\n")); + addlist(_(" -c, --clean remove old packages from cache directory (-cc for all)\n")); + addlist(_(" -g, --groups view all members of a package group\n")); + addlist(_(" -i, --info view package information\n")); + addlist(_(" -l, --list <repo> view a list of packages in a repo\n")); + addlist(_(" -q, --quiet show less information for query and search\n")); + addlist(_(" -s, --search <regex> search remote repositories for matching strings\n")); + addlist(_(" -u, --sysupgrade upgrade installed packages (-uu allows downgrade)\n")); + addlist(_(" -w, --downloadonly download packages but do not install/upgrade anything\n")); + addlist(_(" -y, --refresh download fresh package databases from the server\n")); + addlist(_(" --needed don't reinstall up to date packages\n")); } else if (op == PM_OP_DATABASE) { printf("%s: %s {-D --database} <%s> <%s>\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); - printf(_(" --asdeps mark packages as non-explicitly installed\n")); - printf(_(" --asexplicit mark packages as explicitly installed\n")); + addlist(_(" --asdeps mark packages as non-explicitly installed\n")); + addlist(_(" --asexplicit mark packages as explicitly installed\n")); } switch(op) { case PM_OP_SYNC: case PM_OP_UPGRADE: - printf(_(" -f, --force force install, overwrite conflicting files\n")); - printf(_(" -k, --dbonly add database entries, do not install or keep existing files\n")); - printf(_(" --asdeps install packages as non-explicitly installed\n")); - printf(_(" --asexplicit install packages as explicitly installed\n")); - printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n")); - printf(_(" --ignoregroup <grp>\n" + addlist(_(" -f, --force force install, overwrite conflicting files\n")); + addlist(_(" -k, --dbonly add database entries, do not install or keep existing files\n")); + addlist(_(" --asdeps install packages as non-explicitly installed\n")); + addlist(_(" --asexplicit install packages as explicitly installed\n")); + addlist(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n")); + addlist(_(" --ignoregroup <grp>\n" " ignore a group upgrade (can be used more than once)\n")); /* pass through */ case PM_OP_REMOVE: - printf(_(" -d, --nodeps skip dependency checks\n")); - printf(_(" --noprogressbar do not show a progress bar when downloading files\n")); - printf(_(" --noscriptlet do not execute the install scriptlet if one exists\n")); - printf(_(" --print only print the targets instead of performing the operation\n")); - printf(_(" --print-format <string>\n" + addlist(_(" -d, --nodeps skip dependency checks\n")); + addlist(_(" --noprogressbar do not show a progress bar when downloading files\n")); + addlist(_(" --noscriptlet do not execute the install scriptlet if one exists\n")); + addlist(_(" --print only print the targets instead of performing the operation\n")); + addlist(_(" --print-format <string>\n" " specify how the targets should be printed\n")); break; } - printf(_(" -b, --dbpath <path> set an alternate database location\n")); - printf(_(" -r, --root <path> set an alternate installation root\n")); - printf(_(" -v, --verbose be verbose\n")); - printf(_(" --arch <arch> set an alternate architecture\n")); - printf(_(" --cachedir <dir> set an alternate package cache location\n")); - printf(_(" --config <path> set an alternate configuration file\n")); - printf(_(" --debug display debug messages\n")); - printf(_(" --logfile <path> set an alternate log file\n")); - printf(_(" --noconfirm do not ask for any confirmation\n")); + addlist(_(" -b, --dbpath <path> set an alternate database location\n")); + addlist(_(" -r, --root <path> set an alternate installation root\n")); + addlist(_(" -v, --verbose be verbose\n")); + addlist(_(" --arch <arch> set an alternate architecture\n")); + addlist(_(" --cachedir <dir> set an alternate package cache location\n")); + addlist(_(" --config <path> set an alternate configuration file\n")); + addlist(_(" --debug display debug messages\n")); + addlist(_(" --logfile <path> set an alternate log file\n")); + addlist(_(" --noconfirm do not ask for any confirmation\n")); } + list = alpm_list_msort(list, alpm_list_count(list), str_cmp); + for (i = list; i; i = alpm_list_next(i)) { + printf("%s", (char *)alpm_list_getdata(i)); + } + alpm_list_free(list); +#undef addlist } /** Output pacman version and copyright. diff --git a/src/pacman/util.h b/src/pacman/util.h index 2e77b0c..0308f6b 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,6 +55,7 @@ void string_display(const char *title, const char *string); void list_display(const char *title, const alpm_list_t *list); void list_display_linebreak(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *pkgs, int install); +int str_cmp(const void *s1, const void *s2); void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg); void display_optdepends(pmpkg_t *pkg); void print_packages(const alpm_list_t *packages); -- 1.7.3.1
$ pacman -Uh
options:
-b, --dbpath <path> set an alternate database location
-d, --nodeps skip dependency checks
-f, --force force install, overwrite conflicting files
-k, --dbonly only modify database entries, not package files
-r, --root <path> set an alternate installation root
-v, --verbose be verbose
--arch <arch> set an alternate architecture
--asdeps install packages as non-explicitly installed
--asexplicit install packages as explicitly installed
--cachedir <dir> set an alternate package cache location
--config <path> set an alternate configuration file
--debug display debug messages
--ignore <pkg> ignore a package upgrade (can be used more than once)
--ignoregroup <grp>
ignore a group upgrade (can be used more than once)
--logfile <path> set an alternate log file
--noconfirm do not ask for any confirmation
--noprogressbar do not show a progress bar when downloading files
--noscriptlet do not execute the install scriptlet if one exists
--print only print the targets instead of performing the operation
--print-format <string>
specify how the targets should be printed
Signed-off-by: Xavier Chantry
$ pacman -Uh options: -b, --dbpath <path> set an alternate database location -d, --nodeps skip dependency checks -f, --force force install, overwrite conflicting files -k, --dbonly only modify database entries, not package files -r, --root <path> set an alternate installation root -v, --verbose be verbose --arch <arch> set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed --cachedir <dir> set an alternate package cache location --config <path> set an alternate configuration file --debug display debug messages --ignore <pkg> ignore a package upgrade (can be used more than once) --ignoregroup <grp> ignore a group upgrade (can be used more than once) --logfile <path> set an alternate log file --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --print only print the targets instead of performing the operation --print-format <string> specify how the targets should be printed
Signed-off-by: Xavier Chantry
I like this.
+/* Used to sort the options in --help */ +static int options_cmp(const void *p1, const void *p2) +{ + const char *s1 = p1; + const char *s2 = p2; + int ret = 0; + + /* First skip all spaces in both strings */ + while(isspace((unsigned char)*s1)) + s1++; + while(isspace((unsigned char)*s2)) + s2++; + /* If we compare a long option (--abcd) and a short one (-a), + * the short one always wins */ + if (*(s1+1) != '-' && *(s2+1) == '-') { + ret = -1;
I hope you don't pass invalid string arguments (e.g. empty string), otherwise we can get a segfault here.
+ } else if (*(s2+1) != '-' && *(s1+1) == '-') { + ret = 1; + } else { + ret = strcmp(s1, s2); + } + return(ret); +}
NG
On Thu, Oct 14, 2010 at 1:55 PM, Nagy Gabor
I like this.
Cool :)
+ /* First skip all spaces in both strings */ + while(isspace((unsigned char)*s1)) + s1++; + while(isspace((unsigned char)*s2)) + s2++; + /* If we compare a long option (--abcd) and a short one (-a), + * the short one always wins */ + if (*(s1+1) != '-' && *(s2+1) == '-') { + ret = -1;
I hope you don't pass invalid string arguments (e.g. empty string), otherwise we can get a segfault here.
I missed something very important. I thought we had complete controls on these strings, while in fact we don't have any control at all, since it's the gettext-ed strings that I sort :P I will make a safer version, thanks.
$ pacman -Uh
options:
-b, --dbpath <path> set an alternate database location
-d, --nodeps skip dependency checks
-f, --force force install, overwrite conflicting files
-k, --dbonly only modify database entries, not package files
-r, --root <path> set an alternate installation root
-v, --verbose be verbose
--arch <arch> set an alternate architecture
--asdeps install packages as non-explicitly installed
--asexplicit install packages as explicitly installed
--cachedir <dir> set an alternate package cache location
--config <path> set an alternate configuration file
--debug display debug messages
--ignore <pkg> ignore a package upgrade (can be used more than once)
--ignoregroup <grp>
ignore a group upgrade (can be used more than once)
--logfile <path> set an alternate log file
--noconfirm do not ask for any confirmation
--noprogressbar do not show a progress bar when downloading files
--noscriptlet do not execute the install scriptlet if one exists
--print only print the targets instead of performing the operation
--print-format <string>
specify how the targets should be printed
Signed-off-by: Xavier Chantry
On Thu, Oct 14, 2010 at 8:36 AM, Xavier Chantry
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 7d51124..38d7f6a 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -26,8 +26,10 @@ #define PACKAGE_VERSION GIT_VERSION #endif
+#include
#include /* atoi */ #include +#include /* isspace */ #include #include #include @@ -59,6 +61,41 @@ pmdb_t *db_local; /* list of targets specified on command line */ static alpm_list_t *pm_targets; +/* Used to sort the options in --help */ +static int options_cmp(const void *p1, const void *p2) +{ + const char *s1 = p1; + const char *s2 = p2; + + assert(s1); + assert(s2);
Is the assert stuff you added to be safer? We don't want to use this. One, they are compiled into nothing if NDEBUG is defined, and two, it is a bit silly to abort on this condition. cmp(NULL, NULL) ==0, and then just decide whether to sort NULL first or last. -Dan
On Thu, Oct 14, 2010 at 3:44 PM, Dan McGee
Is the assert stuff you added to be safer? We don't want to use this. One, they are compiled into nothing if NDEBUG is defined, and two, it is a bit silly to abort on this condition. cmp(NULL, NULL) ==0, and then just decide whether to sort NULL first or last.
It was not supposed to be safer, just to explicitly state that this case should not happen. If gettext returns NULL, our --help output is going to look awesome : (null)(null)(null).. It's not perfectly clear to me that an assert is worse. In the unlikely case that this could be triggered, at least an assert would fail gracefully telling us where it failed and possibly giving a core dump that would tell us more about what happened. Anyway we could debate over and over about assert usage. Maybe it's more interesting for an expensive check in a hot-path that you do not want to keep in a release build, but you want to make sure that the assert is indeed not triggered while developing / testing. I updated the patch with an explicit check (I actually already did this before choosing to use assert) : http://code.toofishes.net/cgit/xavier/pacman.git/log/?h=parseargs
participants (4)
-
Allan McRae
-
Dan McGee
-
Nagy Gabor
-
Xavier Chantry