Re: [PATCH v12 10/13] tag.c: use 'ref-filter' data structures

2015-08-19 Thread Karthik Nayak
On Wed, Aug 19, 2015 at 8:26 PM, Matthieu Moy
matthieu@grenoble-inp.fr wrote:
 Karthik Nayak karthik@gmail.com writes:

 This is a temporary step before porting 'tag.c' to use 'ref-filter'
 completely. As this is a temporary step, most of the code
 introduced here will be removed when 'tag.c' is ported over to use
 'ref-filter' APIs

 If you resend: missing '.' at the end of sentence.


Ok will add.

 - if (lines != -1)
 + if (filter.lines != -1)
   die(_(-n option is only allowed with -l.));
 - if (with_commit)
 + if (filter.with_commit)
   die(_(--contains option is only allowed with -l.));
 - if (points_at.nr)
 + if (filter.points_at.nr)
   die(_(--points-at option is only allowed with -l.));

 It may make sense to factor these checks into a function like

   void check_filter_consistancy(struct ref_filter *filter)

 in ref-filter.c, since for-each-ref, branch and tag will eventually have
 the same set of constraints on the options.


Ah! this is needed only in branch and tag where we need to see if the options
are used with tag.c and both have a different sort of check for this.
Might need more of a cleanup in branch.c and tag.c before we could do something
like this so that we could have a similar check.

for reference branch.c uses:

if (!!delete + !!rename + !!new_upstream +
list + unset_upstream  1)
usage_with_options(builtin_branch_usage, options);

whereas tag.c uses what you stated above.

-- 
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: [PATCH v12 10/13] tag.c: use 'ref-filter' data structures

2015-08-19 Thread Matthieu Moy
Karthik Nayak karthik@gmail.com writes:

 This is a temporary step before porting 'tag.c' to use 'ref-filter'
 completely. As this is a temporary step, most of the code
 introduced here will be removed when 'tag.c' is ported over to use
 'ref-filter' APIs

If you resend: missing '.' at the end of sentence.

 - if (lines != -1)
 + if (filter.lines != -1)
   die(_(-n option is only allowed with -l.));
 - if (with_commit)
 + if (filter.with_commit)
   die(_(--contains option is only allowed with -l.));
 - if (points_at.nr)
 + if (filter.points_at.nr)
   die(_(--points-at option is only allowed with -l.));

It may make sense to factor these checks into a function like

  void check_filter_consistancy(struct ref_filter *filter)

in ref-filter.c, since for-each-ref, branch and tag will eventually have
the same set of constraints on the options.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
--
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 v12 10/13] tag.c: use 'ref-filter' data structures

2015-08-18 Thread Karthik Nayak
From: Karthik Nayak karthik@gmail.com

Make 'tag.c' use 'ref-filter' data structures and make changes to
support the new data structures. This is a part of the process
of porting 'tag.c' to use 'ref-filter' APIs.

This is a temporary step before porting 'tag.c' to use 'ref-filter'
completely. As this is a temporary step, most of the code
introduced here will be removed when 'tag.c' is ported over to use
'ref-filter' APIs

Mentored-by: Christian Couder christian.cou...@gmail.com
Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Karthik Nayak karthik@gmail.com
---
 builtin/tag.c | 106 +++---
 1 file changed, 57 insertions(+), 49 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 0fc7557..e96bae2 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -17,6 +17,7 @@
 #include gpg-interface.h
 #include sha1-array.h
 #include column.h
+#include ref-filter.h
 
 static const char * const git_tag_usage[] = {
N_(git tag [-a | -s | -u key-id] [-f] [-m msg | -F file] 
tagname [head]),
@@ -34,15 +35,6 @@ static const char * const git_tag_usage[] = {
 
 static int tag_sort;
 
-struct tag_filter {
-   const char **patterns;
-   int lines;
-   int sort;
-   struct string_list tags;
-   struct commit_list *with_commit;
-};
-
-static struct sha1_array points_at;
 static unsigned int colopts;
 
 static int match_pattern(const char **patterns, const char *ref)
@@ -61,19 +53,20 @@ static int match_pattern(const char **patterns, const char 
*ref)
  * removed as we port tag.c to use the ref-filter APIs.
  */
 static const unsigned char *match_points_at(const char *refname,
-   const unsigned char *sha1)
+   const unsigned char *sha1,
+   struct sha1_array *points_at)
 {
const unsigned char *tagged_sha1 = NULL;
struct object *obj;
 
-   if (sha1_array_lookup(points_at, sha1) = 0)
+   if (sha1_array_lookup(points_at, sha1) = 0)
return sha1;
obj = parse_object(sha1);
if (!obj)
die(_(malformed object at '%s'), refname);
if (obj-type == OBJ_TAG)
tagged_sha1 = ((struct tag *)obj)-tagged-sha1;
-   if (tagged_sha1  sha1_array_lookup(points_at, tagged_sha1) = 0)
+   if (tagged_sha1  sha1_array_lookup(points_at, tagged_sha1) = 0)
return tagged_sha1;
return NULL;
 }
@@ -228,12 +221,24 @@ free_return:
free(buf);
 }
 
+static void ref_array_append(struct ref_array *array, const char *refname)
+{
+   size_t len = strlen(refname);
+   struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item) + 
len + 1);
+   memcpy(ref-refname, refname, len);
+   ref-refname[len] = '\0';
+   REALLOC_ARRAY(array-items, array-nr + 1);
+   array-items[array-nr++] = ref;
+}
+
 static int show_reference(const char *refname, const struct object_id *oid,
  int flag, void *cb_data)
 {
-   struct tag_filter *filter = cb_data;
+   struct ref_filter_cbdata *data = cb_data;
+   struct ref_array *array = data-array;
+   struct ref_filter *filter = data-filter;
 
-   if (match_pattern(filter-patterns, refname)) {
+   if (match_pattern(filter-name_patterns, refname)) {
if (filter-with_commit) {
struct commit *commit;
 
@@ -244,12 +249,12 @@ static int show_reference(const char *refname, const 
struct object_id *oid,
return 0;
}
 
-   if (points_at.nr  !match_points_at(refname, oid-hash))
+   if (filter-points_at.nr  !match_points_at(refname, 
oid-hash, filter-points_at))
return 0;
 
if (!filter-lines) {
-   if (filter-sort)
-   string_list_append(filter-tags, refname);
+   if (tag_sort)
+   ref_array_append(array, refname);
else
printf(%s\n, refname);
return 0;
@@ -264,36 +269,36 @@ static int show_reference(const char *refname, const 
struct object_id *oid,
 
 static int sort_by_version(const void *a_, const void *b_)
 {
-   const struct string_list_item *a = a_;
-   const struct string_list_item *b = b_;
-   return versioncmp(a-string, b-string);
+   const struct ref_array_item *a = *((struct ref_array_item **)a_);
+   const struct ref_array_item *b = *((struct ref_array_item **)b_);
+   return versioncmp(a-refname, b-refname);
 }
 
-static int list_tags(const char **patterns, int lines,
-struct commit_list *with_commit, int sort)
+static int list_tags(struct ref_filter *filter, int sort)
 {
-   struct tag_filter filter;
+   struct ref_array array;
+