Commit 08f392080cfd7e08972820d8147dc06432e7c4bf

Edward Thomson 2019-06-08T17:46:04

blob: add underscore to `from` functions The majority of functions are named `from_something` (with an underscore) instead of `fromsomething`. Update the blob functions for consistency with the rest of the library.

diff --git a/include/git2/blob.h b/include/git2/blob.h
index ff1a481..072522d 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_blob_filtered_content(
  *	relative to the repository's working dir
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
+GIT_EXTERN(int) git_blob_create_from_workdir(git_oid *id, git_repository *repo, const char *relative_path);
 
 /**
  * Read a file from the filesystem and write its content
@@ -148,7 +148,7 @@ GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, c
  * @param path file from which the blob will be created
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_blob_create_from_disk(git_oid *id, git_repository *repo, const char *path);
 
 /**
  * Create a stream to write a new blob into the object db
@@ -156,12 +156,12 @@ GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, cons
  * This function may need to buffer the data on disk and will in
  * general not be the right choice if you know the size of the data
  * to write. If you have data in memory, use
- * `git_blob_create_frombuffer()`. If you do not, but know the size of
+ * `git_blob_create_from_buffer()`. If you do not, but know the size of
  * the contents (and don't want/need to perform filtering), use
  * `git_odb_open_wstream()`.
  *
  * Don't close this stream yourself but pass it to
- * `git_blob_create_fromstream_commit()` to commit the write to the
+ * `git_blob_create_from_stream_commit()` to commit the write to the
  * object db and get the object id.
  *
  * If the `hintpath` parameter is filled, it will be used to determine
@@ -175,7 +175,7 @@ GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, cons
  *        to apply onto the content of the blob to be created.
  * @return 0 or error code
  */
-GIT_EXTERN(int) git_blob_create_fromstream(
+GIT_EXTERN(int) git_blob_create_from_stream(
 	git_writestream **out,
 	git_repository *repo,
 	const char *hintpath);
@@ -189,7 +189,7 @@ GIT_EXTERN(int) git_blob_create_fromstream(
  * @param stream the stream to close
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_blob_create_fromstream_commit(
+GIT_EXTERN(int) git_blob_create_from_stream_commit(
 	git_oid *out,
 	git_writestream *stream);
 
@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_blob_create_fromstream_commit(
  * @param len length of the data
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_blob_create_frombuffer(
+GIT_EXTERN(int) git_blob_create_from_buffer(
 	git_oid *id, git_repository *repo, const void *buffer, size_t len);
 
 /**
diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index 108d422..7c0a6e4 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -45,6 +45,30 @@
  */
 GIT_BEGIN_DECL
 
+/** @name Deprecated Blob Functions
+ *
+ * These functions are retained for backward compatibility.  The newer
+ * versions of these functions should be preferred in all new code.
+ *
+ * There is no plan to remove these backward compatibility values at
+ * this time.
+ */
+/**@{*/
+
+GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
+GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
+GIT_EXTERN(int) git_blob_create_fromstream(
+	git_writestream **out,
+	git_repository *repo,
+	const char *hintpath);
+GIT_EXTERN(int) git_blob_create_fromstream_commit(
+	git_oid *out,
+	git_writestream *stream);
+GIT_EXTERN(int) git_blob_create_frombuffer(
+	git_oid *id, git_repository *repo, const void *buffer, size_t len);
+
+/**@}*/
+
 /** @name Deprecated Buffer Functions
  *
  * These functions and enumeration values are retained for backward
diff --git a/src/apply.c b/src/apply.c
index fdafa66..f876e43 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -532,7 +532,7 @@ static int apply_one(
 	if (delta->status != GIT_DELTA_DELETED) {
 		if ((error = git_apply__patch(&post_contents, &filename, &mode,
 				pre_contents.ptr, pre_contents.size, patch, opts)) < 0 ||
-			(error = git_blob_create_frombuffer(&post_id, repo,
+			(error = git_blob_create_from_buffer(&post_id, repo,
 				post_contents.ptr, post_contents.size)) < 0)
 			goto done;
 
diff --git a/src/blob.c b/src/blob.c
index 566d24b..31e6ccf 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -70,7 +70,7 @@ int git_blob__parse(void *_blob, git_odb_object *odb_obj)
 	return 0;
 }
 
-int git_blob_create_frombuffer(
+int git_blob_create_from_buffer(
 	git_oid *id, git_repository *repo, const void *buffer, size_t len)
 {
 	int error;
@@ -263,13 +263,13 @@ done:
 	return error;
 }
 
-int git_blob_create_fromworkdir(
+int git_blob_create_from_workdir(
 	git_oid *id, git_repository *repo, const char *path)
 {
 	return git_blob__create_from_paths(id, NULL, repo, NULL, path, 0, true);
 }
 
-int git_blob_create_fromdisk(
+int git_blob_create_from_disk(
 	git_oid *id, git_repository *repo, const char *path)
 {
 	int error;
@@ -325,7 +325,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer, 
 	return git_filebuf_write(&stream->fbuf, buffer, len);
 }
 
-int git_blob_create_fromstream(git_writestream **out, git_repository *repo, const char *hintpath)
+int git_blob_create_from_stream(git_writestream **out, git_repository *repo, const char *hintpath)
 {
 	int error;
 	git_buf path = GIT_BUF_INIT;
@@ -364,7 +364,7 @@ cleanup:
 	return error;
 }
 
-int git_blob_create_fromstream_commit(git_oid *out, git_writestream *_stream)
+int git_blob_create_from_stream_commit(git_oid *out, git_writestream *_stream)
 {
 	int error;
 	blob_writestream *stream = (blob_writestream *) _stream;
@@ -427,3 +427,36 @@ int git_blob_filtered_content(
 
 	return error;
 }
+
+/* Deprecated functions */
+
+int git_blob_create_frombuffer(
+	git_oid *id, git_repository *repo, const void *buffer, size_t len)
+{
+	return git_blob_create_from_buffer(id, repo, buffer, len);
+}
+
+int git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path)
+{
+	return git_blob_create_from_workdir(id, repo, relative_path);
+}
+
+int git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path)
+{
+	return git_blob_create_from_disk(id, repo, path);
+}
+
+int git_blob_create_fromstream(
+    git_writestream **out,
+    git_repository *repo,
+    const char *hintpath)
+{
+	return  git_blob_create_from_stream(out, repo, hintpath);
+}
+
+int git_blob_create_fromstream_commit(
+	git_oid *out,
+	git_writestream *stream)
+{
+	return git_blob_create_from_stream_commit(out, stream);
+}
diff --git a/src/index.c b/src/index.c
index ee8dfd5..ec43433 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1477,7 +1477,7 @@ int git_index_add_frombuffer(
 	if (index_entry_dup(&entry, index, source_entry) < 0)
 		return -1;
 
-	error = git_blob_create_frombuffer(&id, INDEX_OWNER(index), buffer, len);
+	error = git_blob_create_from_buffer(&id, INDEX_OWNER(index), buffer, len);
 	if (error < 0) {
 		index_entry_free(entry);
 		return error;
diff --git a/src/notes.c b/src/notes.c
index 8e622c6..5028107 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -288,7 +288,7 @@ static int note_write(
 
 	/* TODO: should we apply filters? */
 	/* create note object */
-	if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
+	if ((error = git_blob_create_from_buffer(&oid, repo, note, strlen(note))) < 0)
 		goto cleanup;
 
 	if ((error = manipulate_note_in_tree_r(
diff --git a/tests/filter/blob.c b/tests/filter/blob.c
index 6e30e20..22f3503 100644
--- a/tests/filter/blob.c
+++ b/tests/filter/blob.c
@@ -87,14 +87,14 @@ void test_filter_blob__ident(void)
 	git_buf buf = { 0 };
 
 	cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n");
-	cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident"));
+	cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "test.ident"));
 	cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
 	cl_assert_equal_s(
 		"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
 	git_blob_free(blob);
 
 	cl_git_mkfile("crlf/test.ident", "Some text\n$Id: Any old just you want$\nGoes there\n");
-	cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident"));
+	cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "test.ident"));
 	cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
 	cl_assert_equal_s(
 		"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
diff --git a/tests/filter/ident.c b/tests/filter/ident.c
index cee0cc2..ed2e467 100644
--- a/tests/filter/ident.c
+++ b/tests/filter/ident.c
@@ -23,7 +23,7 @@ static void add_blob_and_filter(
 	git_buf out = { 0 };
 
 	cl_git_mkfile("crlf/identtest", data);
-	cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "identtest"));
+	cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "identtest"));
 	cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
 
 	cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index 1b68bdc..cddb411 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -352,7 +352,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
 		return 0;
 
 	for (i = 0; i < expected_len; i++) {
-		git_blob_create_fromworkdir(&actual_oid, repo, expected[i].path);
+		git_blob_create_from_workdir(&actual_oid, repo, expected[i].path);
 		git_oid_fromstr(&expected_oid, expected[i].oid_str);
 
 		if (git_oid_cmp(&actual_oid, &expected_oid) != 0)
diff --git a/tests/object/blob/filter.c b/tests/object/blob/filter.c
index 002177c..45dbc92 100644
--- a/tests/object/blob/filter.c
+++ b/tests/object/blob/filter.c
@@ -59,7 +59,7 @@ void test_object_blob_filter__initialize(void)
 		if (g_crlf_raw_len[i] < 0)
 			g_crlf_raw_len[i] = strlen(g_crlf_raw[i]);
 
-		cl_git_pass(git_blob_create_frombuffer(
+		cl_git_pass(git_blob_create_from_buffer(
 			&g_crlf_oids[i], g_repo, g_crlf_raw[i], (size_t)g_crlf_raw_len[i]));
 	}
 }
diff --git a/tests/object/blob/fromstream.c b/tests/object/blob/fromstream.c
index 60090b6..416b452 100644
--- a/tests/object/blob/fromstream.c
+++ b/tests/object/blob/fromstream.c
@@ -29,12 +29,12 @@ void test_object_blob_fromstream__multiple_write(void)
 	cl_git_fail_with(GIT_ENOTFOUND,
 			 git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_ANY));
 
-	cl_git_pass(git_blob_create_fromstream(&stream, repo, NULL));
+	cl_git_pass(git_blob_create_from_stream(&stream, repo, NULL));
 
 	for (i = 0; i < howmany; i++)
 		cl_git_pass(stream->write(stream, textual_content, strlen(textual_content)));
 
-	cl_git_pass(git_blob_create_fromstream_commit(&id, stream));
+	cl_git_pass(git_blob_create_from_stream_commit(&id, stream));
 	cl_assert_equal_oid(&expected_id, &id);
 
 	cl_git_pass(git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_BLOB));
@@ -67,12 +67,12 @@ static void assert_named_chunked_blob(const char *expected_sha, const char *fake
 
 	cl_git_pass(git_oid_fromstr(&expected_id, expected_sha));
 
-	cl_git_pass(git_blob_create_fromstream(&stream, repo, fake_name));
+	cl_git_pass(git_blob_create_from_stream(&stream, repo, fake_name));
 
 	for (i = 0; i < howmany; i++)
 		cl_git_pass(stream->write(stream, textual_content, strlen(textual_content)));
 
-	cl_git_pass(git_blob_create_fromstream_commit(&id, stream));
+	cl_git_pass(git_blob_create_from_stream_commit(&id, stream));
 
 	cl_assert_equal_oid(&expected_id, &id);
 }
diff --git a/tests/object/blob/write.c b/tests/object/blob/write.c
index 4cf5a66..e6b67fb 100644
--- a/tests/object/blob/write.c
+++ b/tests/object/blob/write.c
@@ -33,7 +33,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo
 {
 	repo = cl_git_sandbox_init(WORKDIR);
 
-	assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_fromworkdir);
+	assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_from_workdir);
 }
 
 void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
@@ -46,7 +46,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolut
 	cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
 	cl_must_pass(git_buf_puts(&full_path, "test.txt"));
 
-	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
+	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
 
 	git_buf_dispose(&full_path);
 	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
@@ -62,7 +62,7 @@ void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_fi
 	cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
 	cl_must_pass(git_buf_puts(&full_path, "test.txt"));
 
-	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
+	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
 
 	git_buf_dispose(&full_path);
 	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
diff --git a/tests/odb/backend/mempack.c b/tests/odb/backend/mempack.c
index 55cd69f..2eeed51 100644
--- a/tests/odb/backend/mempack.c
+++ b/tests/odb/backend/mempack.c
@@ -51,10 +51,10 @@ void test_odb_backend_mempack__exists_with_existing_objects_succeeds(void)
 	cl_assert(git_odb_exists(_odb, &_oid) == 1);
 }
 
-void test_odb_backend_mempack__blob_create_frombuffer_succeeds(void)
+void test_odb_backend_mempack__blob_create_from_buffer_succeeds(void)
 {
 	const char *data = "data";
 
-	cl_git_pass(git_blob_create_frombuffer(&_oid, _repo, data, strlen(data) + 1));
+	cl_git_pass(git_blob_create_from_buffer(&_oid, _repo, data, strlen(data) + 1));
 	cl_assert(git_odb_exists(_odb, &_oid) == 1);
 }
diff --git a/tests/odb/freshen.c b/tests/odb/freshen.c
index 1fe6430..1ecd92a 100644
--- a/tests/odb/freshen.c
+++ b/tests/odb/freshen.c
@@ -47,7 +47,7 @@ void test_odb_freshen__loose_blob(void)
 	set_time_wayback(&before, LOOSE_BLOB_FN);
 
 	/* make sure we freshen a blob */
-	cl_git_pass(git_blob_create_frombuffer(&id, repo, LOOSE_STR, CONST_STRLEN(LOOSE_STR)));
+	cl_git_pass(git_blob_create_from_buffer(&id, repo, LOOSE_STR, CONST_STRLEN(LOOSE_STR)));
 	cl_assert_equal_oid(&expected_id, &id);
 	cl_must_pass(p_lstat("testrepo.git/objects/" LOOSE_BLOB_FN, &after));
 
@@ -66,13 +66,13 @@ void test_odb_freshen__readonly_object(void)
 
 	cl_git_pass(git_oid_fromstr(&expected_id, UNIQUE_BLOB_ID));
 
-	cl_git_pass(git_blob_create_frombuffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
+	cl_git_pass(git_blob_create_from_buffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
 	cl_assert_equal_oid(&expected_id, &id);
 
 	set_time_wayback(&before, UNIQUE_BLOB_FN);
 	cl_assert((before.st_mode & S_IWUSR) == 0);
 
-	cl_git_pass(git_blob_create_frombuffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
+	cl_git_pass(git_blob_create_from_buffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
 	cl_assert_equal_oid(&expected_id, &id);
 	cl_must_pass(p_lstat("testrepo.git/objects/" UNIQUE_BLOB_FN, &after));