diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2012-02-28 16:14:47 -0800 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-02 15:49:29 -0800 |
| commit | 74fa4bfae37e9d7c9e35550c881b114d7a83c4fa (patch) | |
| tree | 98184643a8c42b1402e4b33f835eac424fe88768 /src/path.c | |
| parent | 760db29c456ef2029a81d577d95a3fafb37ce5c6 (diff) | |
| download | libgit2-74fa4bfae37e9d7c9e35550c881b114d7a83c4fa.tar.gz | |
Update diff to use iterators
This is a major reorganization of the diff code. This changes
the diff functions to use the iterators for traversing the
content. This allowed a lot of code to be simplified. Also,
this moved the functions relating to outputting a diff into a
new file (diff_output.c).
This includes a number of other changes - adding utility
functions, extending iterators, etc. plus more tests for the
diff code. This also takes the example diff.c program much
further in terms of emulating git-diff command line options.
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index ec40f4b06..ceae2abcf 100644 --- a/src/path.c +++ b/src/path.c @@ -583,3 +583,46 @@ int git_path_dirload( return GIT_SUCCESS; } +int git_path_with_stat_cmp(const void *a, const void *b) +{ + const git_path_with_stat *psa = a, *psb = b; + return git__strcmp_cb(psa->path, psb->path); +} + +int git_path_dirload_with_stat( + const char *path, + size_t prefix_len, + git_vector *contents) +{ + int error; + unsigned int i; + git_path_with_stat *ps; + git_buf full = GIT_BUF_INIT; + + if ((error = git_buf_set(&full, path, prefix_len)) != GIT_SUCCESS) + return error; + + if ((error = git_path_dirload(path, prefix_len, + sizeof(git_path_with_stat) + 1, contents)) != GIT_SUCCESS) { + git_buf_free(&full); + return error; + } + + git_vector_foreach(contents, i, ps) { + size_t path_len = strlen((char *)ps); + + memmove(ps->path, ps, path_len + 1); + ps->path_len = path_len; + + git_buf_joinpath(&full, full.ptr, ps->path); + p_lstat(full.ptr, &ps->st); + git_buf_truncate(&full, prefix_len); + + if (S_ISDIR(ps->st.st_mode)) { + ps->path[path_len] = '/'; + ps->path[path_len + 1] = '\0'; + } + } + + return error; +} |
