diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-05-19 12:35:21 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-06-06 09:38:43 +0200 |
commit | 8ceb890b77fc3ef1ab0fb4ef1d669366734cea85 (patch) | |
tree | c8e89c5e6cea423053c4f26204c09280b80e4421 /src | |
parent | 11d0be23c481f2df2e03e804c611a0f7d2be1599 (diff) | |
download | libgit2-8ceb890b77fc3ef1ab0fb4ef1d669366734cea85.tar.gz |
index: set last written index entry in foreach-entry-loop
The last written disk entry is currently being written inside of the
function `write_disk_entry`. Make behavior a bit more obviously by
instead setting it inside of `write_entries` while iterating all
entries.
Diffstat (limited to 'src')
-rw-r--r-- | src/index.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/index.c b/src/index.c index 110760c9c..aaf76c85d 100644 --- a/src/index.c +++ b/src/index.c @@ -2580,7 +2580,7 @@ static bool is_index_extended(git_index *index) return (extended > 0); } -static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const char **last) +static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const char *last) { void *mem = NULL; struct entry_short *ondisk; @@ -2592,7 +2592,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha path_len = ((struct entry_internal *)entry)->pathlen; if (last) { - const char *last_c = *last; + const char *last_c = last; while (*path_start == *last_c) { if (!*path_start || !*last_c) @@ -2602,7 +2602,6 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha ++same_len; } path_len -= same_len; - *last = entry->path; } if (entry->flags & GIT_IDXENTRY_EXTENDED) @@ -2668,8 +2667,7 @@ static int write_entries(git_index *index, git_filebuf *file) size_t i; git_vector case_sorted, *entries; git_index_entry *entry; - const char **last = NULL; - const char *empty = ""; + const char *last = NULL; /* If index->entries is sorted case-insensitively, then we need * to re-sort it case-sensitively before writing */ @@ -2682,11 +2680,14 @@ static int write_entries(git_index *index, git_filebuf *file) } if (index->version >= INDEX_VERSION_NUMBER_COMP) - last = ∅ + last = ""; - git_vector_foreach(entries, i, entry) + git_vector_foreach(entries, i, entry) { if ((error = write_disk_entry(file, entry, last)) < 0) break; + if (index->version >= INDEX_VERSION_NUMBER_COMP) + last = entry->path; + } if (index->ignore_case) git_vector_free(&case_sorted); |