title: libgit2 - need help to understand how git_diff_foreach works
body: <p>I'm using libgit2 0.22.2, odb/refdb backed by mysql. I was testing git_diff_foreach function, but not sure how it works, please advise!</p>
  
  <p>Below is my testing data and code, I put a blob 'README.md' into odb and commit, the content was 'commit' and later I put another blob with same name into odb and commit, this time the content was 'commit test'</p>
  
  <p>I was trying to diff the 2 tree to print diff deltas in 3 callbacks (file, hunk, line). But only the file callback printed something</p>
  
  <p>update:</p>
  
  <p>i debugged into the foreach function, there's error in diff.h git_diff_file__resolve_zero_size function. after return statement error pops up:</p>
  
  <p>Run-Time Check Failure #2 - Stack around the variable 'len' was corrupted.</p>
  
  <p>code:</p>
  
  <p>get diff:</p>
  
  <pre><code>int error;
  git_object *commit;
  git_commit *parent = NULL;
  error = git_revparse_single(&amp;commit, repo, "HEAD^{commit}");
  error = git_commit_parent(&amp;parent, (git_commit *)commit, 0);
  
  git_tree *commit_tree = NULL, *parent_tree = NULL;
  error = git_commit_tree(&amp;commit_tree, (git_commit *)commit);
  error = git_commit_tree(&amp;parent_tree, parent);
  
  git_diff *diff = NULL;
  error = git_diff_tree_to_tree(&amp;diff, repo, commit_tree, parent_tree, NULL);
  
  git_mysql_tree_diff(mysql, repo, diff);
  
  git_object_free(commit);
  git_commit_free(parent);
  git_tree_free(commit_tree);
  git_tree_free(parent_tree);
  git_diff_free(diff);
  </code></pre>
  
  <p>iterate diff:</p>
  
  <pre><code>int each_file_cb(const git_diff_delta *delta,float progress,void *payload)
  {
      printf("new file:%s \n", delta-&gt;new_file.path);
      printf("old file:%s \n", delta-&gt;old_file.path);
  
      return 0;
  }
  
  int each_hunk_cb(
      const git_diff_delta *delta,
      const git_diff_hunk *hunk,
      void *payload)
  {
  
      printf("hunk header:%s \n", hunk-&gt;header);
  
      return 0;
  }
  
  int each_line_cb(
      const git_diff_delta *delta,
      const git_diff_hunk *hunk,
      const git_diff_line *line,
      void *payload)
  {
      printf("line content:%s \n", line-&gt;content);
  
      return 0;
  }
  
  int git_mysql_tree_diff(git_diff *diff){
      int error;
  
      error = git_diff_foreach(diff,
          each_file_cb,
          each_hunk_cb,
          each_line_cb,
          NULL);
  
      return error;
  }
  </code></pre>
  
  <p>Data:</p>
  
  <pre><code># oid,                                     type, size, data
  '92168310a2a8e8d6577028d97931fd104965f6c5', '2', '37', 100644 README.md �����؊�J��B���f�N
  '9f4ee02f459f6a28fa7a129fde6653d971429336', '1', '248', tree 92168310a2a8e8d6577028d97931fd104965f6c5 parent ad6aa3d0fcecefa5e9ea250a069da4d3be1f8e3d author Jerry Jin &lt;jerry.yang.jin@gmail.com&gt; 1430376253 +0800 committer Jerry Jin &lt;jerry.yang.jin@gmail.com&gt; 1430376253 +0800 encoding UTF-8 update readme
  'ad6aa3d0fcecefa5e9ea250a069da4d3be1f8e3d', '1', '201', tree af0f65dba4ddecf5f4faf889cbd2852c341958c7 author Jerry Jin &lt;jerry.yang.jin@gmail.com&gt; 1430376223 +0800 committer Jerry Jin &lt;jerry.yang.jin@gmail.com&gt; 1430376223 +0800 encoding UTF-8 Initial Commit
  'af0f65dba4ddecf5f4faf889cbd2852c341958c7', '2', '37', 100644 README.md ��vX"��}���lW�`@�#
  'f8a612e3f687d88a984acaf41142ba85a3668d4e', '3', '11', commit test
  'fcad765822a69c7de41bb1db186c57b160409923', '3', '6', commit
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>file progress:0.000000
  </code></pre>