Comments (6)
Can you try this patch ? https://gist.github.com/yrmt/870a30a511b79d64590a ? @jperkin or @iMilnb can you review and comment please?
from pkgin.
With this patch, the output of pkgin se nodejs
looks like this:
nodejs-0.12.7 = V8 JavaScript for clients and servers
nodejs-0.10.40 > V8 JavaScript for clients and servers
nodejs-0.8.28 > V8 JavaScript for clients and servers
nodejs-0.6.21 > Evented I/O for V8 javascript`
from pkgin.
Just going through some old tickets, @nbyouri do you still have your proposed patch anywhere? That gist is a 404.
from pkgin.
https://gist.github.com/nbyouri/870a30a511b79d64590a
from pkgin.
Thanks! I've tidied it up a bit and made it also sort alphabetically first, which I think will give the results that most people would expect. Diff that I'm currently testing is below:
diff --git a/pkglist.c b/pkglist.c
index 212a031..0e4f469 100644
--- a/pkglist.c
+++ b/pkglist.c
@@ -39,6 +39,17 @@ int r_plistcounter, l_plistcounter;
static void setfmt(char *, char *);
+/*
+ * Small structure for sorting package results.
+ */
+struct pkg_sort {
+ char *full;
+ char *name;
+ char *version;
+ char *comment;
+ char flag;
+};
+
/**
* \fn malloc_pkglist
*
@@ -293,14 +304,42 @@ list_pkgs(const char *pkgquery, int lstype)
free(plisthead);
}
+/*
+ * Sort a list of packages first by package name (alphabetically) and then by
+ * version (highest first).
+ */
+static int
+pkg_sort_cmp(const void *a, const void *b)
+{
+ const struct pkg_sort p1 = *(const struct pkg_sort *)a;
+ const struct pkg_sort p2 = *(const struct pkg_sort *)b;
+
+ /*
+ * First compare name, if they are the same then fall through to
+ * a version comparison.
+ */
+ if (strcmp(p1.name, p2.name) > 0)
+ return 1;
+ else if (strcmp(p1.name, p2.name) < 0)
+ return -1;
+
+ if (dewey_cmp(p1.version, DEWEY_LT, p2.version))
+ return 1;
+ else if (dewey_cmp(p1.version, DEWEY_GT, p2.version))
+ return -1;
+
+ return 0;
+}
+
int
search_pkg(const char *pattern)
{
Pkglist *plist;
+ struct pkg_sort *psort;
regex_t re;
int rc;
char eb[64], is_inst, outpkg[BUFSIZ];
- int matched = 0;
+ int matched = 0, pcount = 0;
char sfmt[10], pfmt[10];
setfmt(&sfmt[0], &pfmt[0]);
@@ -311,6 +350,8 @@ search_pkg(const char *pattern)
errx(EXIT_FAILURE, "regcomp: %s: %s", pattern, eb);
}
+ psort = xmalloc(sizeof(struct pkg_sort));
+
SLIST_FOREACH(plist, &r_plisthead, next) {
if (regexec(&re, plist->name, 0, NULL, 0) == 0 ||
regexec(&re, plist->full, 0, NULL, 0) == 0 ||
@@ -327,11 +368,27 @@ search_pkg(const char *pattern)
else
is_inst = '\0';
- snprintf(outpkg, BUFSIZ, sfmt, plist->full, is_inst);
- printf(pfmt, outpkg, plist->comment);
+ psort = xrealloc(psort, (pcount + 1) * sizeof(*psort));
+ psort[pcount].full = xstrdup(plist->full);
+ psort[pcount].name = xstrdup(plist->name);
+ psort[pcount].version = xstrdup(plist->version);
+ psort[pcount].comment = xstrdup(plist->comment);
+ psort[pcount++].flag = is_inst;
}
}
+ qsort(psort, pcount, sizeof(struct pkg_sort), pkg_sort_cmp);
+
+ for (int i = 0; i < pcount; i++) {
+ snprintf(outpkg, BUFSIZ, sfmt, psort[i].full, psort[i].flag);
+ printf(pfmt, outpkg, psort[i].comment);
+
+ XFREE(psort[i].name);
+ XFREE(psort[i].comment);
+ }
+
+ XFREE(psort);
+
regfree(&re);
if (matched) {
Before:
$ pkgin se nodejs
nodejs-8.17.0nb1 > V8 JavaScript for clients and servers
nodejs-13.12.0 = V8 JavaScript for clients and servers
nodejs-12.16.1 > V8 JavaScript for clients and servers
nodejs-10.19.0 > V8 JavaScript for clients and servers
$ pkgin se ffmpeg
gst-plugins1-libav-1.16.2nb1 GStreamer libav/ffmpeg plugin
ffplay4-4.2.2nb1 Simple SDL frontend for FFmpeg
ffplay3-3.4.7nb1 Simple SDL frontend for FFmpeg
ffplay1-1.2.12nb6 Simple SDL frontend for FFmpeg
ffmpegthumbnailer-2.2.0nb1 Lightweight video thumbnailer that can be used by file managers
ffmpeg4-4.2.2nb4 = Decoding, encoding and streaming software (v4.x)
ffmpeg3-3.4.7nb3 = Decoding, encoding and streaming software (v3.x)
ffmpeg2theora-0.30nb6 Simple converter to create Ogg Theora files
ffmpeg1-1.2.12nb14 Decoding, encoding and streaming software (v1.x)
After:
$ pkgin se nodejs
nodejs-13.12.0 = V8 JavaScript for clients and servers
nodejs-12.16.1 > V8 JavaScript for clients and servers
nodejs-10.19.0 > V8 JavaScript for clients and servers
nodejs-8.17.0nb1 > V8 JavaScript for clients and servers
$ pkgin se ffmpeg
ffmpeg1-1.2.12nb14 Decoding, encoding and streaming software (v1.x)
ffmpeg2theora-0.30nb6 Simple converter to create Ogg Theora files
ffmpeg3-3.4.7nb3 = Decoding, encoding and streaming software (v3.x)
ffmpeg4-4.2.2nb4 = Decoding, encoding and streaming software (v4.x)
ffmpegthumbnailer-2.2.0nb1 Lightweight video thumbnailer that can be used by file managers
ffplay1-1.2.12nb6 Simple SDL frontend for FFmpeg
ffplay3-3.4.7nb1 Simple SDL frontend for FFmpeg
ffplay4-4.2.2nb1 Simple SDL frontend for FFmpeg
gst-plugins1-libav-1.16.2nb1 GStreamer libav/ffmpeg plugin
from pkgin.
Looks great :)
from pkgin.
Related Issues (20)
- "upgrade" does not warn about missing packages in repo HOT 3
- partial upgrades are confusing, and man page does not explain what upgrade means HOT 7
- verbose mode is completely wrong
- Category parsing needs to be improved
- Multiple users running install at the same time corrupts the pkgin database
- Incorrect version comparison logic HOT 2
- pkgin struggling with nodejs's multiple version HOT 5
- pkgin should allow user prioritizing of pkg_summary archive formats HOT 2
- deinstall does not order packages correctly HOT 8
- inconsistency in output HOT 7
- pkgin leaks memory quadratically HOT 1
- Upgrade will install unnecessary packages HOT 7
- ohloh thin badge does not load on pkgin website HOT 1
- 'pkgin rm *' behaves unexpectedly HOT 6
- Download packages in parallel
- Dependent packages should only be upgraded once HOT 2
- [Feature Request] Add retry when download fails during install
- man page nits HOT 2
- configure.ac wrongly checks for header files in build environment
- pkgin fug should print a warning about deprecation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkgin.