diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-03-21 12:33:09 -0700 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-21 12:33:09 -0700 |
commit | a48ea31d69a76d6b398d3a1e522a1c7363a9b92a (patch) | |
tree | 1205730de9c5a02688a61360081c284c8ab6e535 /src/diff.c | |
parent | a4c291ef128e870d4e748dedfb3798c33df0ac15 (diff) | |
download | libgit2-a48ea31d69a76d6b398d3a1e522a1c7363a9b92a.tar.gz |
Reimplment git_status_foreach using git diff
This is an initial reimplementation of status using diff a la
the way that core git does it.
Diffstat (limited to 'src/diff.c')
-rw-r--r-- | src/diff.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/diff.c b/src/diff.c index 69c944c63..469a6c05c 100644 --- a/src/diff.c +++ b/src/diff.c @@ -538,33 +538,22 @@ int git_diff_merge( const git_diff_list *from) { int error = 0; - unsigned int i = 0, j = 0; git_vector onto_new; - git_diff_delta *delta; + git_diff_delta *delta, *o; + const git_diff_delta *f; + unsigned int i; if (git_vector_init(&onto_new, onto->deltas.length, diff_delta__cmp) < 0) return -1; - while (!error && (i < onto->deltas.length || j < from->deltas.length)) { - git_diff_delta *o = git_vector_get(&onto->deltas, i); - const git_diff_delta *f = git_vector_get_const(&from->deltas, j); - const char *opath = !o ? NULL : o->old.path ? o->old.path : o->new.path; - const char *fpath = !f ? NULL : f->old.path ? f->old.path : f->new.path; - - if (opath && (!fpath || strcmp(opath, fpath) < 0)) { - delta = diff_delta__dup(o); - i++; - } else if (fpath && (!opath || strcmp(opath, fpath) > 0)) { - delta = diff_delta__dup(f); - j++; - } else { - delta = diff_delta__merge_like_cgit(o, f); - i++; - j++; - } - - error = !delta ? -1 : git_vector_insert(&onto_new, delta); - } + GIT_DIFF_COITERATE( + onto, from, o, f, + delta = diff_delta__dup(o), + delta = diff_delta__dup(f), + delta = diff_delta__merge_like_cgit(o, f), + if ((error = !delta ? -1 : git_vector_insert(&onto_new, delta)) < 0) + break; + ); if (error == 0) { git_vector_swap(&onto->deltas, &onto_new); @@ -577,3 +566,4 @@ int git_diff_merge( return error; } + |