Re: [PATCH/WIP v3 4/4] ref-filter: move code from 'for-each-ref'

2015-05-28 Thread Karthik Nayak

On 05/29/2015 02:05 AM, Matthieu Moy wrote:

Karthik Nayak karthik@gmail.com writes:


Move most of the code from 'for-each-ref' to 'ref-filter' to make
it publically available to other commands, this is to unify the code


s/publically/publicly/


--- /dev/null
+++ b/ref-filter.h


Moving file to the .h file should be done in a separate patch. I don't
want to review the 1050 lines of cut-and-paste other than by doing the
cut-and-paste myself and see if I get the same result, but this part is
not as straightforward and needs proper thinking and review.

In short: the big code movement should be *only* a cut-and-paste, alone
in its own patch.



Ok, will separate it into two patches.



On overall, we're getting close to an acceptable version for these 4
patches. My advice: prioritize polishing these few patches, so that we
can do a detailed review and then consider this part done (either
merged in git.git or not, but I'd like to avoid having to review the
code movement  refactoring again when we move to the next patches).



Sure I'll fix changes suggested by you and push to Github probably by 
tonight (IST), will wait for a day or two to see if there are more 
suggestions by others on the mailing list before sending a new patch 
series here.


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


Re: [PATCH/WIP v3 4/4] ref-filter: move code from 'for-each-ref'

2015-05-28 Thread Matthieu Moy
Karthik Nayak karthik@gmail.com writes:

 Move most of the code from 'for-each-ref' to 'ref-filter' to make
 it publically available to other commands, this is to unify the code

s/publically/publicly/

 --- /dev/null
 +++ b/ref-filter.h

Moving file to the .h file should be done in a separate patch. I don't
want to review the 1050 lines of cut-and-paste other than by doing the
cut-and-paste myself and see if I get the same result, but this part is
not as straightforward and needs proper thinking and review.

In short: the big code movement should be *only* a cut-and-paste, alone
in its own patch.

On overall, we're getting close to an acceptable version for these 4
patches. My advice: prioritize polishing these few patches, so that we
can do a detailed review and then consider this part done (either
merged in git.git or not, but I'd like to avoid having to review the
code movement  refactoring again when we move to the next patches).

-- 
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/WIP v3 4/4] ref-filter: move code from 'for-each-ref'

2015-05-28 Thread Karthik Nayak
Move most of the code from 'for-each-ref' to 'ref-filter' to make
it publically available to other commands, this is to unify the code
of 'tag -l', 'branch -l' and 'for-each-ref' so that they can share
their implementations with each other.

Mentored-by: Christian Couder christian.cou...@gmail.com
Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Karthik Nayak karthik@gmail.com
---
 Makefile   |1 +
 builtin/for-each-ref.c | 1089 +---
 ref-filter.c   | 1051 ++
 ref-filter.h   |   66 +++
 4 files changed, 1119 insertions(+), 1088 deletions(-)
 create mode 100644 ref-filter.c
 create mode 100644 ref-filter.h

diff --git a/Makefile b/Makefile
index 36655d5..068d313 100644
--- a/Makefile
+++ b/Makefile
@@ -761,6 +761,7 @@ LIB_OBJS += reachable.o
 LIB_OBJS += read-cache.o
 LIB_OBJS += reflog-walk.o
 LIB_OBJS += refs.o
+LIB_OBJS += ref-filter.o
 LIB_OBJS += remote.o
 LIB_OBJS += replace_object.o
 LIB_OBJS += rerere.o
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index f045def..2f11c01 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,1095 +1,8 @@
 #include builtin.h
 #include cache.h
 #include refs.h
-#include object.h
-#include tag.h
-#include commit.h
-#include tree.h
-#include blob.h
-#include quote.h
 #include parse-options.h
-#include remote.h
-#include color.h
-
-/* Quoting styles */
-#define QUOTE_NONE 0
-#define QUOTE_SHELL 1
-#define QUOTE_PERL 2
-#define QUOTE_PYTHON 4
-#define QUOTE_TCL 8
-
-typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
-
-struct atom_value {
-   const char *s;
-   unsigned long ul; /* used for sorting when not FIELD_STR */
-};
-
-struct ref_sort {
-   struct ref_sort *next;
-   int atom; /* index into used_atom array */
-   unsigned reverse : 1;
-};
-
-struct ref_array_item {
-   unsigned char objectname[20];
-   int flag;
-   const char *symref;
-   struct atom_value *value;
-   char *refname;
-};
-
-struct ref_array {
-   int nr, alloc;
-   struct ref_array_item **items;
-};
-
-struct ref_filter {
-   const char **name_patterns;
-};
-
-struct ref_filter_cbdata {
-   struct ref_array array;
-   struct ref_filter filter;
-};
-
-static struct {
-   const char *name;
-   cmp_type cmp_type;
-} valid_atom[] = {
-   { refname },
-   { objecttype },
-   { objectsize, FIELD_ULONG },
-   { objectname },
-   { tree },
-   { parent },
-   { numparent, FIELD_ULONG },
-   { object },
-   { type },
-   { tag },
-   { author },
-   { authorname },
-   { authoremail },
-   { authordate, FIELD_TIME },
-   { committer },
-   { committername },
-   { committeremail },
-   { committerdate, FIELD_TIME },
-   { tagger },
-   { taggername },
-   { taggeremail },
-   { taggerdate, FIELD_TIME },
-   { creator },
-   { creatordate, FIELD_TIME },
-   { subject },
-   { body },
-   { contents },
-   { contents:subject },
-   { contents:body },
-   { contents:signature },
-   { upstream },
-   { symref },
-   { flag },
-   { HEAD },
-   { color },
-};
-
-/*
- * An atom is a valid field atom listed above, possibly prefixed with
- * a * to denote deref_tag().
- *
- * We parse given format string and sort specifiers, and make a list
- * of properties that we need to extract out of objects. ref_array_item
- * structure will hold an array of values extracted that can be
- * indexed with the atom number, which is an index into this
- * array.
- */
-static const char **used_atom;
-static cmp_type *used_atom_type;
-static int used_atom_cnt, need_tagged, need_symref;
-static int need_color_reset_at_eol;
-
-/*
- * Used to parse format string and sort specifiers
- */
-int parse_ref_filter_atom(const char *atom, const char *ep)
-{
-   const char *sp;
-   int i, at;
-
-   sp = atom;
-   if (*sp == '*'  sp  ep)
-   sp++; /* deref */
-   if (ep = sp)
-   die(malformed field name: %.*s, (int)(ep-atom), atom);
-
-   /* Do we have the atom already used elsewhere? */
-   for (i = 0; i  used_atom_cnt; i++) {
-   int len = strlen(used_atom[i]);
-   if (len == ep - atom  !memcmp(used_atom[i], atom, len))
-   return i;
-   }
-
-   /* Is the atom a valid one? */
-   for (i = 0; i  ARRAY_SIZE(valid_atom); i++) {
-   int len = strlen(valid_atom[i].name);
-   /*
-* If the atom name has a colon, strip it and everything after
-* it off - it specifies the format for this entry, and
-* shouldn't be used for checking against the valid_atom
-* table.
-*/
-   const char *formatp = strchr(sp, ':');
-   if (!formatp ||