Re: [PATCH 03/10] diffcore-pickaxe.c: Refactor pickaxe_fn signature

2014-04-04 Thread Jakub Narębski

W dniu 2014-03-27 19:50, David A. Dalrymple (and Bhushan G. Lodha) pisze:

From: Bhushan G. Lodha  David A. Dalrymple dad-...@mit.edu

This function type previously accepted separate regex_t and kwset_t
parameters, which conceptually go together. Here we create a struct to
encapsulate them, in anticipation of adding a third field that
pickaxe_fn's may require.

This parallels the existing diffgrep_cb structure for passing possibly
relevant values through to the callbacks invoked by xdi_diff_outf.


If it parallels existing diffgrep_cb structure, why not name this
equivalent in simular way, i.e. pickaxe_cb or pickaxe_options or
pickaxe_cb_opts instead of generic name fn_options?


Signed-off-by: David Dalrymple (on zayin) davi...@alum.mit.edu
---
  diffcore-pickaxe.c | 50 ++
  1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 0d36a3c..7e65095 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -8,17 +8,22 @@
  #include xdiff-interface.h
  #include kwset.h

+struct fn_options {
+   regex_t *regex;
+   kwset_t kws;
+};



--
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 03/10] diffcore-pickaxe.c: Refactor pickaxe_fn signature

2014-03-27 Thread David A. Dalrymple (and Bhushan G. Lodha)
From: Bhushan G. Lodha  David A. Dalrymple dad-...@mit.edu

This function type previously accepted separate regex_t and kwset_t
parameters, which conceptually go together. Here we create a struct to
encapsulate them, in anticipation of adding a third field that
pickaxe_fn's may require.

This parallels the existing diffgrep_cb structure for passing possibly
relevant values through to the callbacks invoked by xdi_diff_outf.

Signed-off-by: David Dalrymple (on zayin) davi...@alum.mit.edu
---
 diffcore-pickaxe.c | 50 ++
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 0d36a3c..7e65095 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -8,17 +8,22 @@
 #include xdiff-interface.h
 #include kwset.h
 
+struct fn_options {
+   regex_t *regex;
+   kwset_t kws;
+};
+
 typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
  struct diff_options *o,
- regex_t *regexp, kwset_t kws);
+ struct fn_options *fno);
 
 static void compile_regex(regex_t *r, const char *s, int cflags);
 
 static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
-regex_t *regexp, kwset_t kws, pickaxe_fn fn);
+pickaxe_fn fn, struct fn_options *fno);
 
 static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
-   regex_t *regexp, kwset_t kws, pickaxe_fn fn)
+   pickaxe_fn fn, struct fn_options *fno)
 {
int i;
struct diff_queue_struct outq;
@@ -29,7 +34,7 @@ static void pickaxe(struct diff_queue_struct *q, struct 
diff_options *o,
/* Showing the whole changeset if needle exists */
for (i = 0; i  q-nr; i++) {
struct diff_filepair *p = q-queue[i];
-   if (pickaxe_match(p, o, regexp, kws, fn))
+   if (pickaxe_match(p, o, fn, fno))
return; /* do not munge the queue */
}
 
@@ -44,7 +49,7 @@ static void pickaxe(struct diff_queue_struct *q, struct 
diff_options *o,
/* Showing only the filepairs that has the needle */
for (i = 0; i  q-nr; i++) {
struct diff_filepair *p = q-queue[i];
-   if (pickaxe_match(p, o, regexp, kws, fn))
+   if (pickaxe_match(p, o, fn, fno))
diff_q(outq, p);
else
diff_free_filepair(p);
@@ -83,7 +88,7 @@ static void diffgrep_consume(void *priv, char *line, unsigned 
long len)
 
 static int diff_grep(mmfile_t *one, mmfile_t *two,
 struct diff_options *o,
-regex_t *regexp, kwset_t kws)
+struct fn_options *fno)
 {
regmatch_t regmatch;
struct diffgrep_cb ecbdata;
@@ -91,9 +96,9 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
xdemitconf_t xecfg;
 
if (!one)
-   return !regexec(regexp, two-ptr, 1, regmatch, 0);
+   return !regexec(fno-regex, two-ptr, 1, regmatch, 0);
if (!two)
-   return !regexec(regexp, one-ptr, 1, regmatch, 0);
+   return !regexec(fno-regex, one-ptr, 1, regmatch, 0);
 
/*
 * We have both sides; need to run textual diff and see if
@@ -101,7 +106,7 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
 */
memset(xpp, 0, sizeof(xpp));
memset(xecfg, 0, sizeof(xecfg));
-   ecbdata.regexp = regexp;
+   ecbdata.regexp = fno-regex;
ecbdata.hit = 0;
xecfg.ctxlen = o-context;
xecfg.interhunkctxlen = o-interhunkcontext;
@@ -113,6 +118,7 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
 static void diffcore_pickaxe_grep(struct diff_options *o)
 {
regex_t regex;
+   struct fn_options fno;
int cflags = REG_EXTENDED | REG_NEWLINE;
 
if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
@@ -120,13 +126,14 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
 
compile_regex(regex, o-pickaxe, cflags);
 
-   pickaxe(diff_queued_diff, o, regex, NULL, diff_grep);
+   fno.regex = regex;
+   pickaxe(diff_queued_diff, o, diff_grep, fno);
 
regfree(regex);
return;
 }
 
-static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
+static unsigned int contains(mmfile_t *mf, struct fn_options *fno)
 {
unsigned int cnt;
unsigned long sz;
@@ -136,12 +143,12 @@ static unsigned int contains(mmfile_t *mf, regex_t 
*regexp, kwset_t kws)
data = mf-ptr;
cnt = 0;
 
-   if (regexp) {
+   if (fno-regex) {
regmatch_t regmatch;
int flags = 0;
 
assert(data[sz] == '\0');
-   while (*data  !regexec(regexp, data, 1,