Documentation: wording fixes in the user manual and glossary
[gitweb.git] / diffcore-pickaxe.c
index cfc4262e4d6e7baf6e11da73b3653cbf11c63fce..185f86b2840d3337eac9fb2b17b260ca0c53fbab 100644 (file)
@@ -12,47 +12,6 @@ typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
                          struct diff_options *o,
                          regex_t *regexp, kwset_t kws);
 
-static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
-                        regex_t *regexp, kwset_t kws, pickaxe_fn fn);
-
-static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
-                   regex_t *regexp, kwset_t kws, pickaxe_fn fn)
-{
-       int i;
-       struct diff_queue_struct outq;
-
-       DIFF_QUEUE_CLEAR(&outq);
-
-       if (o->pickaxe_opts & DIFF_PICKAXE_ALL) {
-               /* 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))
-                               return; /* do not munge the queue */
-               }
-
-               /*
-                * Otherwise we will clear the whole queue by copying
-                * the empty outq at the end of this function, but
-                * first clear the current entries in the queue.
-                */
-               for (i = 0; i < q->nr; i++)
-                       diff_free_filepair(q->queue[i]);
-       } else {
-               /* 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))
-                               diff_q(&outq, p);
-                       else
-                               diff_free_filepair(p);
-               }
-       }
-
-       free(q->queue);
-       *q = outq;
-}
-
 struct diffgrep_cb {
        regex_t *regexp;
        int hit;
@@ -135,13 +94,10 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
                while (sz) {
                        struct kwsmatch kwsm;
                        size_t offset = kwsexec(kws, data, sz, &kwsm);
-                       const char *found;
                        if (offset == -1)
                                break;
-                       else
-                               found = data + offset;
-                       sz -= found - data + kwsm.size[0];
-                       data = found + kwsm.size[0];
+                       sz -= offset + kwsm.size[0];
+                       data += offset + kwsm.size[0];
                        cnt++;
                }
        }
@@ -204,11 +160,48 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
        return ret;
 }
 
+static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
+                   regex_t *regexp, kwset_t kws, pickaxe_fn fn)
+{
+       int i;
+       struct diff_queue_struct outq;
+
+       DIFF_QUEUE_CLEAR(&outq);
+
+       if (o->pickaxe_opts & DIFF_PICKAXE_ALL) {
+               /* 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))
+                               return; /* do not munge the queue */
+               }
+
+               /*
+                * Otherwise we will clear the whole queue by copying
+                * the empty outq at the end of this function, but
+                * first clear the current entries in the queue.
+                */
+               for (i = 0; i < q->nr; i++)
+                       diff_free_filepair(q->queue[i]);
+       } else {
+               /* 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))
+                               diff_q(&outq, p);
+                       else
+                               diff_free_filepair(p);
+               }
+       }
+
+       free(q->queue);
+       *q = outq;
+}
+
 void diffcore_pickaxe(struct diff_options *o)
 {
        const char *needle = o->pickaxe;
        int opts = o->pickaxe_opts;
-       unsigned long len = strlen(needle);
        regex_t regex, *regexp = NULL;
        kwset_t kws = NULL;
 
@@ -229,7 +222,7 @@ void diffcore_pickaxe(struct diff_options *o)
        } else {
                kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)
                               ? tolower_trans_tbl : NULL);
-               kwsincr(kws, needle, len);
+               kwsincr(kws, needle, strlen(needle));
                kwsprep(kws);
        }