Commit 6574cd00 by Edward Thomson

index: rename `frombuffer` to `from_buffer`

The majority of functions are named `from_something` (with an
underscore) instead of `fromsomething`.  Update the index functions for
consistency with the rest of the library.
parent 08f39208
...@@ -191,10 +191,11 @@ GIT_EXTERN(void) giterr_set_oom(void); ...@@ -191,10 +191,11 @@ GIT_EXTERN(void) giterr_set_oom(void);
/**@}*/ /**@}*/
/** @name Deprecated Index Constants /** @name Deprecated Index Functions and Constants
* *
* These enumeration values are retained for backward compatibility. * These functions and enumeration values are retained for backward
* The newer versions of these values should be preferred in all new code. * compatibility. The newer versions of these values should be
* preferred in all new code.
* *
* There is no plan to remove these backward compatibility values at * There is no plan to remove these backward compatibility values at
* this time. * this time.
...@@ -234,6 +235,11 @@ GIT_EXTERN(void) giterr_set_oom(void); ...@@ -234,6 +235,11 @@ GIT_EXTERN(void) giterr_set_oom(void);
#define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS #define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS
#define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER #define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER
GIT_EXTERN(int) git_index_add_frombuffer(
git_index *index,
const git_index_entry *entry,
const void *buffer, size_t len);
/**@}*/ /**@}*/
/** @name Deprecated Object Constants /** @name Deprecated Object Constants
......
...@@ -572,7 +572,7 @@ GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path); ...@@ -572,7 +572,7 @@ GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
* @param len length of the data * @param len length of the data
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_index_add_frombuffer( GIT_EXTERN(int) git_index_add_from_buffer(
git_index *index, git_index *index,
const git_index_entry *entry, const git_index_entry *entry,
const void *buffer, size_t len); const void *buffer, size_t len);
......
...@@ -1454,7 +1454,7 @@ GIT_INLINE(bool) valid_filemode(const int filemode) ...@@ -1454,7 +1454,7 @@ GIT_INLINE(bool) valid_filemode(const int filemode)
return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT); return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
} }
int git_index_add_frombuffer( int git_index_add_from_buffer(
git_index *index, const git_index_entry *source_entry, git_index *index, const git_index_entry *source_entry,
const void *buffer, size_t len) const void *buffer, size_t len)
{ {
...@@ -3709,3 +3709,12 @@ void git_indexwriter_cleanup(git_indexwriter *writer) ...@@ -3709,3 +3709,12 @@ void git_indexwriter_cleanup(git_indexwriter *writer)
git_index_free(writer->index); git_index_free(writer->index);
writer->index = NULL; writer->index = NULL;
} }
/* Deprecated functions */
int git_index_add_frombuffer(
git_index *index, const git_index_entry *source_entry,
const void *buffer, size_t len)
{
return git_index_add_from_buffer(index, source_entry, buffer, len);
}
...@@ -164,7 +164,7 @@ static void add_entry_and_check_mode_( ...@@ -164,7 +164,7 @@ static void add_entry_and_check_mode_(
git_index_entry new_entry; git_index_entry new_entry;
/* If old_filename exists, we copy that to the new file, and test /* If old_filename exists, we copy that to the new file, and test
* git_index_add(), otherwise create a new entry testing git_index_add_frombuffer * git_index_add(), otherwise create a new entry testing git_index_add_from_buffer
*/ */
if (from_file) if (from_file)
{ {
...@@ -189,7 +189,7 @@ static void add_entry_and_check_mode_( ...@@ -189,7 +189,7 @@ static void add_entry_and_check_mode_(
else else
{ {
const char *content = "hey there\n"; const char *content = "hey there\n";
clar__assert(!git_index_add_frombuffer(index, &new_entry, content, strlen(content)), clar__assert(!git_index_add_from_buffer(index, &new_entry, content, strlen(content)),
file, line, "Cannot add index entry from buffer", NULL, 1); file, line, "Cannot add index entry from buffer", NULL, 1);
} }
...@@ -207,7 +207,7 @@ void test_index_filemodes__explicit(void) ...@@ -207,7 +207,7 @@ void test_index_filemodes__explicit(void)
git_index *index; git_index *index;
/* These tests should run and work everywhere, as the filemode is /* These tests should run and work everywhere, as the filemode is
* given explicitly to git_index_add or git_index_add_frombuffer * given explicitly to git_index_add or git_index_add_from_buffer
*/ */
cl_repo_set_bool(g_repo, "core.filemode", false); cl_repo_set_bool(g_repo, "core.filemode", false);
...@@ -271,7 +271,7 @@ void test_index_filemodes__frombuffer_requires_files(void) ...@@ -271,7 +271,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
new_entry.path = "dummy-file.txt"; new_entry.path = "dummy-file.txt";
new_entry.mode = GIT_FILEMODE_BLOB; new_entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_add_frombuffer(index, cl_git_pass(git_index_add_from_buffer(index,
&new_entry, content, strlen(content))); &new_entry, content, strlen(content)));
cl_assert((ret_entry = git_index_get_bypath(index, "dummy-file.txt", 0))); cl_assert((ret_entry = git_index_get_bypath(index, "dummy-file.txt", 0)));
...@@ -282,7 +282,7 @@ void test_index_filemodes__frombuffer_requires_files(void) ...@@ -282,7 +282,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
new_entry.path = "dummy-file.txt"; new_entry.path = "dummy-file.txt";
new_entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE; new_entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE;
cl_git_pass(git_index_add_frombuffer(index, cl_git_pass(git_index_add_from_buffer(index,
&new_entry, content, strlen(content))); &new_entry, content, strlen(content)));
cl_assert((ret_entry = git_index_get_bypath(index, "dummy-file.txt", 0))); cl_assert((ret_entry = git_index_get_bypath(index, "dummy-file.txt", 0)));
...@@ -293,7 +293,7 @@ void test_index_filemodes__frombuffer_requires_files(void) ...@@ -293,7 +293,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
new_entry.path = "dummy-link.txt"; new_entry.path = "dummy-link.txt";
new_entry.mode = GIT_FILEMODE_LINK; new_entry.mode = GIT_FILEMODE_LINK;
cl_git_pass(git_index_add_frombuffer(index, cl_git_pass(git_index_add_from_buffer(index,
&new_entry, content, strlen(content))); &new_entry, content, strlen(content)));
cl_assert((ret_entry = git_index_get_bypath(index, "dummy-link.txt", 0))); cl_assert((ret_entry = git_index_get_bypath(index, "dummy-link.txt", 0)));
...@@ -304,7 +304,7 @@ void test_index_filemodes__frombuffer_requires_files(void) ...@@ -304,7 +304,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
new_entry.path = "invalid_mode.txt"; new_entry.path = "invalid_mode.txt";
new_entry.mode = GIT_FILEMODE_TREE; new_entry.mode = GIT_FILEMODE_TREE;
cl_git_fail(git_index_add_frombuffer(index, cl_git_fail(git_index_add_from_buffer(index,
&new_entry, content, strlen(content))); &new_entry, content, strlen(content)));
cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0)); cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0));
...@@ -312,7 +312,7 @@ void test_index_filemodes__frombuffer_requires_files(void) ...@@ -312,7 +312,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
new_entry.path = "invalid_mode.txt"; new_entry.path = "invalid_mode.txt";
new_entry.mode = GIT_FILEMODE_COMMIT; new_entry.mode = GIT_FILEMODE_COMMIT;
cl_git_fail(git_index_add_frombuffer(index, cl_git_fail(git_index_add_from_buffer(index,
&new_entry, content, strlen(content))); &new_entry, content, strlen(content)));
cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0)); cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0));
......
...@@ -193,7 +193,7 @@ static void setup_uptodate_files(void) ...@@ -193,7 +193,7 @@ static void setup_uptodate_files(void)
/* Put 'C' into the index */ /* Put 'C' into the index */
new_entry.path = "C"; new_entry.path = "C";
new_entry.mode = GIT_FILEMODE_BLOB; new_entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_add_frombuffer(index, &new_entry, "hello!\n", 7)); cl_git_pass(git_index_add_from_buffer(index, &new_entry, "hello!\n", 7));
git_index_free(index); git_index_free(index);
git_buf_dispose(&path); git_buf_dispose(&path);
......
...@@ -310,7 +310,7 @@ void test_index_tests__add_frombuffer(void) ...@@ -310,7 +310,7 @@ void test_index_tests__add_frombuffer(void)
memset(&entry, 0x0, sizeof(git_index_entry)); memset(&entry, 0x0, sizeof(git_index_entry));
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
entry.path = "test.txt"; entry.path = "test.txt";
cl_git_pass(git_index_add_frombuffer(index, &entry, cl_git_pass(git_index_add_from_buffer(index, &entry,
content, strlen(content))); content, strlen(content)));
/* Wow... it worked! */ /* Wow... it worked! */
...@@ -352,7 +352,7 @@ void test_index_tests__dirty_and_clean(void) ...@@ -352,7 +352,7 @@ void test_index_tests__dirty_and_clean(void)
/* Index is dirty after adding an entry */ /* Index is dirty after adding an entry */
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
entry.path = "test.txt"; entry.path = "test.txt";
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4)); cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
cl_assert(git_index_entrycount(index) == 1); cl_assert(git_index_entrycount(index) == 1);
cl_assert(git_index_is_dirty(index)); cl_assert(git_index_is_dirty(index));
...@@ -374,7 +374,7 @@ void test_index_tests__dirty_and_clean(void) ...@@ -374,7 +374,7 @@ void test_index_tests__dirty_and_clean(void)
cl_assert(!git_index_is_dirty(index)); cl_assert(!git_index_is_dirty(index));
/* Index is dirty when we do an unforced read with dirty content */ /* Index is dirty when we do an unforced read with dirty content */
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4)); cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
cl_assert(git_index_entrycount(index) == 1); cl_assert(git_index_entrycount(index) == 1);
cl_assert(git_index_is_dirty(index)); cl_assert(git_index_is_dirty(index));
...@@ -402,7 +402,7 @@ void test_index_tests__dirty_fails_optionally(void) ...@@ -402,7 +402,7 @@ void test_index_tests__dirty_fails_optionally(void)
/* Index is dirty after adding an entry */ /* Index is dirty after adding an entry */
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
entry.path = "test.txt"; entry.path = "test.txt";
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4)); cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
cl_assert(git_index_is_dirty(index)); cl_assert(git_index_is_dirty(index));
cl_git_pass(git_checkout_head(repo, NULL)); cl_git_pass(git_checkout_head(repo, NULL));
...@@ -410,7 +410,7 @@ void test_index_tests__dirty_fails_optionally(void) ...@@ -410,7 +410,7 @@ void test_index_tests__dirty_fails_optionally(void)
/* Index is dirty (again) after adding an entry */ /* Index is dirty (again) after adding an entry */
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
entry.path = "test.txt"; entry.path = "test.txt";
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4)); cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
cl_assert(git_index_is_dirty(index)); cl_assert(git_index_is_dirty(index));
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 1)); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 1));
...@@ -455,7 +455,7 @@ void test_index_tests__add_frombuffer_reset_entry(void) ...@@ -455,7 +455,7 @@ void test_index_tests__add_frombuffer_reset_entry(void)
memset(&entry, 0x0, sizeof(git_index_entry)); memset(&entry, 0x0, sizeof(git_index_entry));
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
entry.path = "test.txt"; entry.path = "test.txt";
cl_git_pass(git_index_add_frombuffer(index, &entry, cl_git_pass(git_index_add_from_buffer(index, &entry,
content, strlen(content))); content, strlen(content)));
/* Wow... it worked! */ /* Wow... it worked! */
......
...@@ -55,7 +55,7 @@ void test_index_version__can_write_v4(void) ...@@ -55,7 +55,7 @@ void test_index_version__can_write_v4(void)
memset(&entry, 0, sizeof(entry)); memset(&entry, 0, sizeof(entry));
entry.path = paths[i]; entry.path = paths[i];
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_add_frombuffer(index, &entry, paths[i], cl_git_pass(git_index_add_from_buffer(index, &entry, paths[i],
strlen(paths[i]) + 1)); strlen(paths[i]) + 1));
} }
cl_assert_equal_sz(git_index_entrycount(index), ARRAY_SIZE(paths)); cl_assert_equal_sz(git_index_entrycount(index), ARRAY_SIZE(paths));
...@@ -100,7 +100,7 @@ void test_index_version__v4_uses_path_compression(void) ...@@ -100,7 +100,7 @@ void test_index_version__v4_uses_path_compression(void)
path[ARRAY_SIZE(path) - 3] = i; path[ARRAY_SIZE(path) - 3] = i;
path[ARRAY_SIZE(path) - 2] = j; path[ARRAY_SIZE(path) - 2] = j;
path[ARRAY_SIZE(path) - 1] = '\0'; path[ARRAY_SIZE(path) - 1] = '\0';
cl_git_pass(git_index_add_frombuffer(index, &entry, buf, sizeof(buf))); cl_git_pass(git_index_add_from_buffer(index, &entry, buf, sizeof(buf)));
} }
} }
......
...@@ -98,7 +98,7 @@ void test_object_tree_read__largefile(void) ...@@ -98,7 +98,7 @@ void test_object_tree_read__largefile(void)
ie.path = BIGFILE; ie.path = BIGFILE;
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_add_frombuffer(index, &ie, buf, BIGFILE_SIZE)); cl_git_pass(git_index_add_from_buffer(index, &ie, buf, BIGFILE_SIZE));
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, BIGFILE); cl_repo_commit_from_index(&oid, g_repo, NULL, 0, BIGFILE);
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment