{"thread":{"id":"27760","subject":"[PATCH 0/3] prepare for histogram diff","startedAt":"2011-07-06T06:15:42Z","lastAt":"2011-07-06T15:01:38Z","messageCount":6,"participants":["Tay Ray Chuan","Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"170853","messageId":"1309932945-5048-1-git-send-email-rctay89@gmail.com","threadId":"27760","inReplyTo":null,"subject":"[PATCH 0/3] prepare for histogram diff","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-07-06T06:15:42Z","receivedAt":"2011-07-06T06:15:42Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Tay Ray Chuan (3):\n  xdiff/xprepare: use memset\n  xdiff/xpatience: factor out fall-back-diff function\n  t4033-diff-patience: factor out tests\n\n t/lib-diff-patience.sh   |  162 ++++++++++++++++++++++++++++++++++++++++++++++\n t/t4033-diff-patience.sh |  162 +---------------------------------------------\n xdiff/xpatience.c        |   27 +-------\n xdiff/xprepare.c         |   10 +--\n xdiff/xutils.c           |   31 +++++++++\n xdiff/xutils.h           |    2 +\n 6 files changed, 203 insertions(+), 191 deletions(-)\n create mode 100644 t/lib-diff-patience.sh\n\n-- \n1.7.3.4.678.g170bd\n"},{"id":"170854","messageId":"1309932945-5048-2-git-send-email-rctay89@gmail.com","threadId":"27760","inReplyTo":"1309932945-5048-1-git-send-email-rctay89@gmail.com","subject":"[PATCH 1/3] xdiff/xprepare: use memset","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-07-06T06:15:43Z","receivedAt":"2011-07-06T06:15:43Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"---\n xdiff/xprepare.c |   10 +++-------\n 1 files changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/xdiff/xprepare.c b/xdiff/xprepare.c\nindex 1689085..783631a 100644\n--- a/xdiff/xprepare.c\n+++ b/xdiff/xprepare.c\n@@ -64,8 +64,6 @@ static int xdl_optimize_ctxs(xdfile_t *xdf1, xdfile_t *xdf2);\n \n \n static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {\n-\tlong i;\n-\n \tcf->flags = flags;\n \n \tcf->hbits = xdl_hashbits((unsigned int) size);\n@@ -80,8 +78,7 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {\n \t\txdl_cha_free(&cf->ncha);\n \t\treturn -1;\n \t}\n-\tfor (i = 0; i < cf->hsize; i++)\n-\t\tcf->rchash[i] = NULL;\n+\tmemset(cf->rchash, 0, cf->hsize * sizeof(xdlclass_t *));\n \n \tcf->count = 0;\n \n@@ -136,7 +133,7 @@ static int xdl_classify_record(xdlclassifier_t *cf, xrecord_t **rhash, unsigned\n static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,\n \t\t\t   xdlclassifier_t *cf, xdfile_t *xdf) {\n \tunsigned int hbits;\n-\tlong i, nrec, hsize, bsize;\n+\tlong nrec, hsize, bsize;\n \tunsigned long hav;\n \tchar const *blk, *cur, *top, *prev;\n \txrecord_t *crec;\n@@ -164,8 +161,7 @@ static int xdl_prepare_ctx(mmfile_t *mf, long narec, xpparam_t const *xpp,\n \t\txdl_cha_free(&xdf->rcha);\n \t\treturn -1;\n \t}\n-\tfor (i = 0; i < hsize; i++)\n-\t\trhash[i] = NULL;\n+\tmemset(rhash, 0, hsize * sizeof(xrecord_t *));\n \n \tnrec = 0;\n \tif ((cur = blk = xdl_mmfile_first(mf, &bsize)) != NULL) {\n-- \n1.7.3.4.678.g170bd\n"},{"id":"170855","messageId":"1309932945-5048-3-git-send-email-rctay89@gmail.com","threadId":"27760","inReplyTo":"1309932945-5048-2-git-send-email-rctay89@gmail.com","subject":"[PATCH 2/3] xdiff/xpatience: factor out fall-back-diff function","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-07-06T06:15:44Z","receivedAt":"2011-07-06T06:15:44Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n xdiff/xpatience.c |   27 ++-------------------------\n xdiff/xutils.c    |   31 +++++++++++++++++++++++++++++++\n xdiff/xutils.h    |    2 ++\n 3 files changed, 35 insertions(+), 25 deletions(-)\n\ndiff --git a/xdiff/xpatience.c b/xdiff/xpatience.c\nindex e42c16a..fdd7d02 100644\n--- a/xdiff/xpatience.c\n+++ b/xdiff/xpatience.c\n@@ -287,34 +287,11 @@ static int walk_common_sequence(struct hashmap *map, struct entry *first,\n static int fall_back_to_classic_diff(struct hashmap *map,\n \t\tint line1, int count1, int line2, int count2)\n {\n-\t/*\n-\t * This probably does not work outside Git, since\n-\t * we have a very simple mmfile structure.\n-\t *\n-\t * Note: ideally, we would reuse the prepared environment, but\n-\t * the libxdiff interface does not (yet) allow for diffing only\n-\t * ranges of lines instead of the whole files.\n-\t */\n-\tmmfile_t subfile1, subfile2;\n \txpparam_t xpp;\n-\txdfenv_t env;\n-\n-\tsubfile1.ptr = (char *)map->env->xdf1.recs[line1 - 1]->ptr;\n-\tsubfile1.size = map->env->xdf1.recs[line1 + count1 - 2]->ptr +\n-\t\tmap->env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;\n-\tsubfile2.ptr = (char *)map->env->xdf2.recs[line2 - 1]->ptr;\n-\tsubfile2.size = map->env->xdf2.recs[line2 + count2 - 2]->ptr +\n-\t\tmap->env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;\n \txpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;\n-\tif (xdl_do_diff(&subfile1, &subfile2, &xpp, &env) < 0)\n-\t\treturn -1;\n \n-\tmemcpy(map->env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);\n-\tmemcpy(map->env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);\n-\n-\txdl_free_env(&env);\n-\n-\treturn 0;\n+\treturn xdl_fall_back_diff(map->env, &xpp,\n+\t\t\t\t  line1, count1, line2, count2);\n }\n \n /*\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex ab65034..ded7c32 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -402,3 +402,34 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,\n \n \treturn 0;\n }\n+\n+int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,\n+\t\tint line1, int count1, int line2, int count2)\n+{\n+\t/*\n+\t * This probably does not work outside Git, since\n+\t * we have a very simple mmfile structure.\n+\t *\n+\t * Note: ideally, we would reuse the prepared environment, but\n+\t * the libxdiff interface does not (yet) allow for diffing only\n+\t * ranges of lines instead of the whole files.\n+\t */\n+\tmmfile_t subfile1, subfile2;\n+\txdfenv_t env;\n+\n+\tsubfile1.ptr = (char *)diff_env->xdf1.recs[line1 - 1]->ptr;\n+\tsubfile1.size = diff_env->xdf1.recs[line1 + count1 - 2]->ptr +\n+\t\tdiff_env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;\n+\tsubfile2.ptr = (char *)diff_env->xdf2.recs[line2 - 1]->ptr;\n+\tsubfile2.size = diff_env->xdf2.recs[line2 + count2 - 2]->ptr +\n+\t\tdiff_env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;\n+\tif (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0)\n+\t\treturn -1;\n+\n+\tmemcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);\n+\tmemcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);\n+\n+\txdl_free_env(&env);\n+\n+\treturn 0;\n+}\ndiff --git a/xdiff/xutils.h b/xdiff/xutils.h\nindex d5de829..674a657 100644\n--- a/xdiff/xutils.h\n+++ b/xdiff/xutils.h\n@@ -41,6 +41,8 @@ int xdl_num_out(char *out, long val);\n long xdl_atol(char const *str, char const **next);\n int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,\n \t\t      const char *func, long funclen, xdemitcb_t *ecb);\n+int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,\n+\t\t       int line1, int count1, int line2, int count2);\n \n \n \n-- \n1.7.3.4.678.g170bd\n"},{"id":"170856","messageId":"1309932945-5048-4-git-send-email-rctay89@gmail.com","threadId":"27760","inReplyTo":"1309932945-5048-3-git-send-email-rctay89@gmail.com","subject":"[PATCH 3/3] t4033-diff-patience: factor out tests","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-07-06T06:15:45Z","receivedAt":"2011-07-06T06:15:45Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"---\n t/lib-diff-patience.sh   |  162 ++++++++++++++++++++++++++++++++++++++++++++++\n t/t4033-diff-patience.sh |  162 +---------------------------------------------\n 2 files changed, 165 insertions(+), 159 deletions(-)\n create mode 100644 t/lib-diff-patience.sh\n\ndiff --git a/t/lib-diff-patience.sh b/t/lib-diff-patience.sh\nnew file mode 100644\nindex 0000000..ab04646\n--- /dev/null\n+++ b/t/lib-diff-patience.sh\n@@ -0,0 +1,162 @@\n+test_diff_frobnitz() {\n+\tcat >file1 <<\\EOF\n+#include <stdio.h>\n+\n+// Frobs foo heartily\n+int frobnitz(int foo)\n+{\n+    int i;\n+    for(i = 0; i < 10; i++)\n+    {\n+        printf(\"Your answer is: \");\n+        printf(\"%d\\n\", foo);\n+    }\n+}\n+\n+int fact(int n)\n+{\n+    if(n > 1)\n+    {\n+        return fact(n-1) * n;\n+    }\n+    return 1;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+    frobnitz(fact(10));\n+}\n+EOF\n+\n+\tcat >file2 <<\\EOF\n+#include <stdio.h>\n+\n+int fib(int n)\n+{\n+    if(n > 2)\n+    {\n+        return fib(n-1) + fib(n-2);\n+    }\n+    return 1;\n+}\n+\n+// Frobs foo heartily\n+int frobnitz(int foo)\n+{\n+    int i;\n+    for(i = 0; i < 10; i++)\n+    {\n+        printf(\"%d\\n\", foo);\n+    }\n+}\n+\n+int main(int argc, char **argv)\n+{\n+    frobnitz(fib(10));\n+}\n+EOF\n+\n+\tcat >expect <<\\EOF\n+diff --git a/file1 b/file2\n+index 6faa5a3..e3af329 100644\n+--- a/file1\n++++ b/file2\n+@@ -1,26 +1,25 @@\n+ #include <stdio.h>\n+ \n++int fib(int n)\n++{\n++    if(n > 2)\n++    {\n++        return fib(n-1) + fib(n-2);\n++    }\n++    return 1;\n++}\n++\n+ // Frobs foo heartily\n+ int frobnitz(int foo)\n+ {\n+     int i;\n+     for(i = 0; i < 10; i++)\n+     {\n+-        printf(\"Your answer is: \");\n+         printf(\"%d\\n\", foo);\n+     }\n+ }\n+ \n+-int fact(int n)\n+-{\n+-    if(n > 1)\n+-    {\n+-        return fact(n-1) * n;\n+-    }\n+-    return 1;\n+-}\n+-\n+ int main(int argc, char **argv)\n+ {\n+-    frobnitz(fact(10));\n++    frobnitz(fib(10));\n+ }\n+EOF\n+\n+\tSTRATEGY=$1\n+\n+\ttest_expect_success \"$STRATEGY diff\" '\n+\t\ttest_must_fail git diff --no-index \"--$STRATEGY\" file1 file2 > output &&\n+\t\ttest_cmp expect output\n+\t'\n+\n+\ttest_expect_success \"$STRATEGY diff output is valid\" '\n+\t\tmv file2 expect &&\n+\t\tgit apply < output &&\n+\t\ttest_cmp expect file2\n+\t'\n+}\n+\n+test_diff_unique() {\n+\tcat >uniq1 <<\\EOF\n+1\n+2\n+3\n+4\n+5\n+6\n+EOF\n+\n+\tcat >uniq2 <<\\EOF\n+a\n+b\n+c\n+d\n+e\n+f\n+EOF\n+\n+\tcat >expect <<\\EOF\n+diff --git a/uniq1 b/uniq2\n+index b414108..0fdf397 100644\n+--- a/uniq1\n++++ b/uniq2\n+@@ -1,6 +1,6 @@\n+-1\n+-2\n+-3\n+-4\n+-5\n+-6\n++a\n++b\n++c\n++d\n++e\n++f\n+EOF\n+\n+\tSTRATEGY=$1\n+\n+\ttest_expect_success 'completely different files' '\n+\t\ttest_must_fail git diff --no-index \"--$STRATEGY\" uniq1 uniq2 > output &&\n+\t\ttest_cmp expect output\n+\t'\n+}\n\\ No newline at end of file\ndiff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh\nindex 1eb1498..9fe9921 100755\n--- a/t/t4033-diff-patience.sh\n+++ b/t/t4033-diff-patience.sh\n@@ -3,166 +3,10 @@\n test_description='patience diff algorithm'\n \n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-diff-patience.sh\n \n-cat >file1 <<\\EOF\n-#include <stdio.h>\n+test_diff_frobnitz \"patience\"\n \n-// Frobs foo heartily\n-int frobnitz(int foo)\n-{\n-    int i;\n-    for(i = 0; i < 10; i++)\n-    {\n-        printf(\"Your answer is: \");\n-        printf(\"%d\\n\", foo);\n-    }\n-}\n-\n-int fact(int n)\n-{\n-    if(n > 1)\n-    {\n-        return fact(n-1) * n;\n-    }\n-    return 1;\n-}\n-\n-int main(int argc, char **argv)\n-{\n-    frobnitz(fact(10));\n-}\n-EOF\n-\n-cat >file2 <<\\EOF\n-#include <stdio.h>\n-\n-int fib(int n)\n-{\n-    if(n > 2)\n-    {\n-        return fib(n-1) + fib(n-2);\n-    }\n-    return 1;\n-}\n-\n-// Frobs foo heartily\n-int frobnitz(int foo)\n-{\n-    int i;\n-    for(i = 0; i < 10; i++)\n-    {\n-        printf(\"%d\\n\", foo);\n-    }\n-}\n-\n-int main(int argc, char **argv)\n-{\n-    frobnitz(fib(10));\n-}\n-EOF\n-\n-cat >expect <<\\EOF\n-diff --git a/file1 b/file2\n-index 6faa5a3..e3af329 100644\n---- a/file1\n-+++ b/file2\n-@@ -1,26 +1,25 @@\n- #include <stdio.h>\n- \n-+int fib(int n)\n-+{\n-+    if(n > 2)\n-+    {\n-+        return fib(n-1) + fib(n-2);\n-+    }\n-+    return 1;\n-+}\n-+\n- // Frobs foo heartily\n- int frobnitz(int foo)\n- {\n-     int i;\n-     for(i = 0; i < 10; i++)\n-     {\n--        printf(\"Your answer is: \");\n-         printf(\"%d\\n\", foo);\n-     }\n- }\n- \n--int fact(int n)\n--{\n--    if(n > 1)\n--    {\n--        return fact(n-1) * n;\n--    }\n--    return 1;\n--}\n--\n- int main(int argc, char **argv)\n- {\n--    frobnitz(fact(10));\n-+    frobnitz(fib(10));\n- }\n-EOF\n-\n-test_expect_success 'patience diff' '\n-\n-\ttest_must_fail git diff --no-index --patience file1 file2 > output &&\n-\ttest_cmp expect output\n-\n-'\n-\n-test_expect_success 'patience diff output is valid' '\n-\n-\tmv file2 expect &&\n-\tgit apply < output &&\n-\ttest_cmp expect file2\n-\n-'\n-\n-cat >uniq1 <<\\EOF\n-1\n-2\n-3\n-4\n-5\n-6\n-EOF\n-\n-cat >uniq2 <<\\EOF\n-a\n-b\n-c\n-d\n-e\n-f\n-EOF\n-\n-cat >expect <<\\EOF\n-diff --git a/uniq1 b/uniq2\n-index b414108..0fdf397 100644\n---- a/uniq1\n-+++ b/uniq2\n-@@ -1,6 +1,6 @@\n--1\n--2\n--3\n--4\n--5\n--6\n-+a\n-+b\n-+c\n-+d\n-+e\n-+f\n-EOF\n-\n-test_expect_success 'completely different files' '\n-\n-\ttest_must_fail git diff --no-index --patience uniq1 uniq2 > output &&\n-\ttest_cmp expect output\n-\n-'\n+test_diff_unique \"patience\"\n \n test_done\n-- \n1.7.3.4.678.g170bd\n"},{"id":"170861","messageId":"CALkWK0=qO4NOfK0x044Hd+dM5pY8-EMrBrk_Tkia=fpYDzkyig@mail.gmail.com","threadId":"27760","inReplyTo":"1309932945-5048-4-git-send-email-rctay89@gmail.com","subject":"Re: [PATCH 3/3] t4033-diff-patience: factor out tests","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-06T07:29:09Z","receivedAt":"2011-07-06T07:29:09Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Tay,\n\nTay Ray Chuan writes:\n> ---\n\nSubmitting RFC patches without commit messages is alright I think, but\na missing signoff won't even permit anyone else to pick up this up and\nwork on it.  Please sign-off on everything.\n\n>  t/lib-diff-patience.sh   |  162 ++++++++++++++++++++++++++++++++++++++++++++++\n>  t/t4033-diff-patience.sh |  162 +---------------------------------------------\n>  2 files changed, 165 insertions(+), 159 deletions(-)\n>  create mode 100644 t/lib-diff-patience.sh\n\nMaybe separate this out into two patches: one that renames the file,\nand another that makes the minor changes so that it's easy to review?\n\n-- Ram\n"},{"id":"170924","messageId":"CALUzUxoOS69xR07eoYYjum5XBqAVuFgh9LkzKCV2X5J5_m3gZA@mail.gmail.com","threadId":"27760","inReplyTo":"CALkWK0=qO4NOfK0x044Hd+dM5pY8-EMrBrk_Tkia=fpYDzkyig@mail.gmail.com","subject":"Re: [PATCH 3/3] t4033-diff-patience: factor out tests","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-07-06T15:01:38Z","receivedAt":"2011-07-06T15:01:38Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Wed, Jul 6, 2011 at 3:29 PM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:\n> Submitting RFC patches without commit messages is alright I think, but\n> a missing signoff won't even permit anyone else to pick up this up and\n> work on it.  Please sign-off on everything.\n\nOops.\n\n>>  t/lib-diff-patience.sh   |  162 ++++++++++++++++++++++++++++++++++++++++++++++\n>>  t/t4033-diff-patience.sh |  162 +---------------------------------------------\n>>  2 files changed, 165 insertions(+), 159 deletions(-)\n>>  create mode 100644 t/lib-diff-patience.sh\n>\n> Maybe separate this out into two patches: one that renames the file,\n> and another that makes the minor changes so that it's easy to review?\n\nGood idea.\n\n-- \nCheers,\nRay Chuan\n"}]}