diff options
| author | Russell Belfer <rb@github.com> | 2012-11-08 16:56:34 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-11-09 13:52:07 -0800 |
| commit | 55cbd05b18960e761a4d237ce5f1ff06455da98d (patch) | |
| tree | ef602ca15261aa1d5ff6be6ea043d74d5fc45459 /src/index.c | |
| parent | 2e3d4b96c08f1b0e2ee9b248c53aec523d70fd25 (diff) | |
| download | libgit2-55cbd05b18960e761a4d237ce5f1ff06455da98d.tar.gz | |
Some diff refactorings to help code reuse
There are some diff functions that are useful in a rewritten
checkout and this lays some groundwork for that. This contains
three main things:
1. Share the function diff uses to calculate the OID for a file
in the working directory (now named `git_diff__oid_for_file`
2. Add a `git_diff__paired_foreach` function to iterator over
two diff lists concurrently. Convert status to use it.
3. Move all the string/prefix/index entry comparisons into
function pointers inside the `git_diff_list` object so they
can be switched between case sensitive and insensitive
versions. This makes them easier to reuse in various
functions without replicating logic. As part of this, move
a couple of index functions out of diff.c and into index.c.
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/index.c b/src/index.c index 214d29def..c1b4565a3 100644 --- a/src/index.c +++ b/src/index.c @@ -516,7 +516,7 @@ git_index_entry *git_index_get_bypath(git_index *index, const char *path, int st return git_index_get_byindex(index, pos); } -void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry) +void git_index_entry__init_from_stat(git_index_entry *entry, struct stat *st) { entry->ctime.seconds = (git_time_t)st->st_ctime; entry->mtime.seconds = (git_time_t)st->st_mtime; @@ -530,6 +530,22 @@ void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry) entry->file_size = st->st_size; } +int git_index_entry__cmp(const void *a, const void *b) +{ + const git_index_entry *entry_a = a; + const git_index_entry *entry_b = b; + + return strcmp(entry_a->path, entry_b->path); +} + +int git_index_entry__cmp_icase(const void *a, const void *b) +{ + const git_index_entry *entry_a = a; + const git_index_entry *entry_b = b; + + return strcasecmp(entry_a->path, entry_b->path); +} + static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path) { git_index_entry *entry = NULL; @@ -568,7 +584,7 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const entry = git__calloc(1, sizeof(git_index_entry)); GITERR_CHECK_ALLOC(entry); - git_index__init_entry_from_stat(&st, entry); + git_index_entry__init_from_stat(entry, &st); entry->oid = oid; entry->path = git__strdup(rel_path); |
