Re: [RFC/PATCH 4/9] ref-filter: add support to sort by version

2015-07-12 Thread Karthik Nayak
On Sun, Jul 12, 2015 at 2:39 PM, Duy Nguyen pclo...@gmail.com wrote:
 On Thu, Jun 25, 2015 at 6:43 PM, Karthik Nayak karthik@gmail.com wrote:
 Add support to sort by version using the v:refname and
 version:refname option. This is achieved by using the
 'version_cmp()' function as the comparing function for qsort.

 If these v:refname and version:refname are from git-tag, you may want
 to see [1]. I would say version: or v: is in the same class as -
 (for reverse sort) and they should be parsed in
 parse_opt_ref_sorting() instead. They should not be treated as atom
 names. By stripping version: before pref_ref_filter_atom() is called
 in this function, you make version: work with all supported atoms.

 [1] http://article.gmane.org/gmane.comp.version-control.git/242446
 --
 Duy

Thanks for this, what you're saying makes sense, will follow.

-- 
Regards,
Karthik Nayak
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 4/9] ref-filter: add support to sort by version

2015-07-12 Thread Duy Nguyen
On Thu, Jun 25, 2015 at 6:43 PM, Karthik Nayak karthik@gmail.com wrote:
 Add support to sort by version using the v:refname and
 version:refname option. This is achieved by using the
 'version_cmp()' function as the comparing function for qsort.

If these v:refname and version:refname are from git-tag, you may want
to see [1]. I would say version: or v: is in the same class as -
(for reverse sort) and they should be parsed in
parse_opt_ref_sorting() instead. They should not be treated as atom
names. By stripping version: before pref_ref_filter_atom() is called
in this function, you make version: work with all supported atoms.

[1] http://article.gmane.org/gmane.comp.version-control.git/242446
-- 
Duy
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC/PATCH 4/9] ref-filter: add support to sort by version

2015-06-25 Thread Karthik Nayak
Add support to sort by version using the v:refname and
version:refname option. This is achieved by using the
'version_cmp()' function as the comparing function for qsort.

Mentored-by: Christian Couder christian.cou...@gmail.com
Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Karthik Nayak karthik@gmail.com
---
 ref-filter.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 57a5cfb..e307fab 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -10,8 +10,9 @@
 #include quote.h
 #include ref-filter.h
 #include revision.h
+#include version.h
 
-typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
+typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME, FIELD_VER } cmp_type;
 
 static struct {
const char *name;
@@ -53,6 +54,8 @@ static struct {
{ flag },
{ HEAD },
{ color },
+   { version, FIELD_VER },
+   { v, FIELD_VER },
 };
 
 /*
@@ -629,7 +632,9 @@ static void populate_value(struct ref_array_item *ref)
name++;
}
 
-   if (starts_with(name, refname))
+   if (starts_with(name, refname) ||
+   starts_with(name, version:) ||
+   starts_with(name, v:))
refname = ref-refname;
else if (starts_with(name, symref))
refname = ref-symref ? ref-symref : ;
@@ -695,7 +700,13 @@ static void populate_value(struct ref_array_item *ref)
int num_ours, num_theirs;
 
formatp++;
-   if (starts_with(formatp, lalign)) {
+   if (starts_with(name, version) || starts_with(name, 
v)) {
+   if (strcmp(formatp, refname))
+   die(unknown %.*s format %s,
+   (int)(formatp - name), name, 
formatp);
+   v-s = refname;
+   continue;
+   } else if (starts_with(formatp, lalign)) {
const char *valp;
int val;
 
@@ -1165,6 +1176,9 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct 
ref_array_item *a, stru
case FIELD_STR:
cmp = strcmp(va-s, vb-s);
break;
+   case FIELD_VER:
+   cmp = versioncmp(va-s, vb-s);
+   break;
default:
if (va-ul  vb-ul)
cmp = -1;
-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html