Re: [PATCH v6 10/11] for-each-ref: introduce filter_refs()

2015-06-08 Thread Junio C Hamano
Karthik Nayak karthik@gmail.com writes:

 +/*
 + * API for filtering a set of refs. The refs are provided and iterated
 + * over using the for_each_ref_fn(). The refs are stored into and filtered
 + * based on the ref_filter_cbdata structure.
 + */
 +int filter_refs(int (for_each_ref_fn)(each_ref_fn, void *), struct 
 ref_filter_cbdata *data)
 +{
 + return for_each_ref_fn(ref_filter_handler, data);
 +}

I do not think it is such a good idea to allow API callers to
specify for-each-ref-fn directly.  See my message in an earlier
review.

I also think ref_filter_cbdata is an implementation detail of
filter_refs and may not have to be exposed to the API callers.
It probably is more sensible for them to pass

 - an array of refs to receive filtered results (your ref_array thing)
 - the criteria to use when filtering (your ref_filter thing)

as two separate parameters to this function, together with other
parameters that lets you (meaning the implementation of filter_refs())
to decide which for-each-ref iterator to call, e.g. do you want to
use raw iteration?  do you want to iterate only over refs/heads? etc.

In other words, the caller of this API should not have to know that
you (meaning the implementation of filter_refs()) are internally
using for_each_ref() API.

--
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: [PATCH v6 10/11] for-each-ref: introduce filter_refs()

2015-06-08 Thread Karthik Nayak

On 06/08/2015 11:45 PM, Junio C Hamano wrote:

Karthik Nayak karthik@gmail.com writes:


+/*
+ * API for filtering a set of refs. The refs are provided and iterated
+ * over using the for_each_ref_fn(). The refs are stored into and filtered
+ * based on the ref_filter_cbdata structure.
+ */
+int filter_refs(int (for_each_ref_fn)(each_ref_fn, void *), struct 
ref_filter_cbdata *data)
+{
+   return for_each_ref_fn(ref_filter_handler, data);
+}


I do not think it is such a good idea to allow API callers to
specify for-each-ref-fn directly.  See my message in an earlier
review.



I did read your previous message. I misunderstood some things.



I also think ref_filter_cbdata is an implementation detail of
filter_refs and may not have to be exposed to the API callers.
It probably is more sensible for them to pass

  - an array of refs to receive filtered results (your ref_array thing)
  - the criteria to use when filtering (your ref_filter thing)



This could be done.



as two separate parameters to this function, together with other
parameters that lets you (meaning the implementation of filter_refs())
to decide which for-each-ref iterator to call, e.g. do you want to
use raw iteration?  do you want to iterate only over refs/heads? etc.

In other words, the caller of this API should not have to know that
you (meaning the implementation of filter_refs()) are internally
using for_each_ref() API.



I'm a little confused about this, how exactly do you propose we go about 
doing something like this? I mean, usually the user of the API

knows what exactly they want, like in tag.c, branch.c and for-each-ref.c
But I'm not sure what you mean by parameters that lets you (meaning the 
implementation of filter_refs()) to decide which for-each-ref iterator 
to call. A small example maybe? Thanks!


--
Regards,
Karthik
--
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


[PATCH v6 10/11] for-each-ref: introduce filter_refs()

2015-06-07 Thread Karthik Nayak
Introduce filter_refs() which will act as an API for users to
call and provide a function which will iterate over a set of refs
while filtering out the required refs.

Currently this will wrap around ref_filter_handler(). Hence,
ref_filter_handler is made file scope static.

Helped-by: Junio C Hamano gits...@pobox.com
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 | 12 +++-
 ref-filter.h |  8 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index ece16a1..886c3d7 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -858,7 +858,7 @@ static struct ref_array_item *new_ref_array_item(const char 
*refname,
  * A call-back given to for_each_ref().  Filter refs and keep them for
  * later object processing.
  */
-int ref_filter_handler(const char *refname, const struct object_id *oid, int 
flag, void *cb_data)
+static int ref_filter_handler(const char *refname, const struct object_id 
*oid, int flag, void *cb_data)
 {
struct ref_filter_cbdata *ref_cbdata = cb_data;
struct ref_filter *filter = ref_cbdata-filter;
@@ -904,6 +904,16 @@ void ref_array_clear(struct ref_array *array)
array-nr = array-alloc = 0;
 }
 
+/*
+ * API for filtering a set of refs. The refs are provided and iterated
+ * over using the for_each_ref_fn(). The refs are stored into and filtered
+ * based on the ref_filter_cbdata structure.
+ */
+int filter_refs(int (for_each_ref_fn)(each_ref_fn, void *), struct 
ref_filter_cbdata *data)
+{
+   return for_each_ref_fn(ref_filter_handler, data);
+}
+
 static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, 
struct ref_array_item *b)
 {
struct atom_value *va, *vb;
diff --git a/ref-filter.h b/ref-filter.h
index c2c5d37..15e6766 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -46,8 +46,12 @@ struct ref_filter_cbdata {
struct ref_filter filter;
 };
 
-/*  Callback function for for_each_*ref(). This filters the refs based on the 
filters set */
-int ref_filter_handler(const char *refname, const struct object_id *oid, int 
flag, void *cb_data);
+/*
+ * API for filtering a set of refs. The refs are provided and iterated
+ * over using the for_each_ref_fn(). The refs are stored into and filtered
+ * based on the ref_filter_cbdata structure.
+ */
+int filter_refs(int (for_each_ref_fn)(each_ref_fn, void *), struct 
ref_filter_cbdata *data);
 /*  Clear all memory allocated to ref_array */
 void ref_array_clear(struct ref_array *array);
 /*  Parse format string and sort specifiers */
-- 
2.4.2

--
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


[PATCH v6 10/11] for-each-ref: introduce filter_refs()

2015-06-06 Thread Karthik Nayak
Introduce filter_refs() which will act as an API for users to
call and provide a function which will iterate over a set of refs
while filtering out the required refs.

Currently this will wrap around ref_filter_handler(). Hence,
ref_filter_handler is made file scope static.

Helped-by: Junio C Hamano gits...@pobox.com
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 | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/ref-filter.c b/ref-filter.c
index ece16a1..91a6ec9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -904,6 +904,16 @@ void ref_array_clear(struct ref_array *array)
array-nr = array-alloc = 0;
 }
 
+/*
+ * API for filtering a set of refs. The refs are provided and iterated
+ * over using the for_each_ref_fn(). The refs are stored into and filtered
+ * based on the ref_filter_cbdata structure.
+ */
+int filter_refs(int (for_each_ref_fn)(each_ref_fn, void *), struct 
ref_filter_cbdata *data)
+{
+   return for_each_ref_fn(ref_filter_handler, data);
+}
+
 static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, 
struct ref_array_item *b)
 {
struct atom_value *va, *vb;
-- 
2.4.2

--
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