Commit 08f39208 by Edward Thomson

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.
parent 5d92e547
...@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_blob_filtered_content( ...@@ -136,7 +136,7 @@ GIT_EXTERN(int) git_blob_filtered_content(
* relative to the repository's working dir * relative to the repository's working dir
* @return 0 or an error code * @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 * 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 ...@@ -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 * @param path file from which the blob will be created
* @return 0 or an error code * @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 * 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 ...@@ -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 * 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 * general not be the right choice if you know the size of the data
* to write. If you have data in memory, use * 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 * the contents (and don't want/need to perform filtering), use
* `git_odb_open_wstream()`. * `git_odb_open_wstream()`.
* *
* Don't close this stream yourself but pass it to * 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. * object db and get the object id.
* *
* If the `hintpath` parameter is filled, it will be used to determine * 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 ...@@ -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. * to apply onto the content of the blob to be created.
* @return 0 or error code * @return 0 or error code
*/ */
GIT_EXTERN(int) git_blob_create_fromstream( GIT_EXTERN(int) git_blob_create_from_stream(
git_writestream **out, git_writestream **out,
git_repository *repo, git_repository *repo,
const char *hintpath); const char *hintpath);
...@@ -189,7 +189,7 @@ GIT_EXTERN(int) git_blob_create_fromstream( ...@@ -189,7 +189,7 @@ GIT_EXTERN(int) git_blob_create_fromstream(
* @param stream the stream to close * @param stream the stream to close
* @return 0 or an error code * @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_oid *out,
git_writestream *stream); git_writestream *stream);
...@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_blob_create_fromstream_commit( ...@@ -202,7 +202,7 @@ GIT_EXTERN(int) git_blob_create_fromstream_commit(
* @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_blob_create_frombuffer( GIT_EXTERN(int) git_blob_create_from_buffer(
git_oid *id, git_repository *repo, const void *buffer, size_t len); git_oid *id, git_repository *repo, const void *buffer, size_t len);
/** /**
......
...@@ -45,6 +45,30 @@ ...@@ -45,6 +45,30 @@
*/ */
GIT_BEGIN_DECL 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 /** @name Deprecated Buffer Functions
* *
* These functions and enumeration values are retained for backward * These functions and enumeration values are retained for backward
......
...@@ -532,7 +532,7 @@ static int apply_one( ...@@ -532,7 +532,7 @@ static int apply_one(
if (delta->status != GIT_DELTA_DELETED) { if (delta->status != GIT_DELTA_DELETED) {
if ((error = git_apply__patch(&post_contents, &filename, &mode, if ((error = git_apply__patch(&post_contents, &filename, &mode,
pre_contents.ptr, pre_contents.size, patch, opts)) < 0 || 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) post_contents.ptr, post_contents.size)) < 0)
goto done; goto done;
......
...@@ -70,7 +70,7 @@ int git_blob__parse(void *_blob, git_odb_object *odb_obj) ...@@ -70,7 +70,7 @@ int git_blob__parse(void *_blob, git_odb_object *odb_obj)
return 0; 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) git_oid *id, git_repository *repo, const void *buffer, size_t len)
{ {
int error; int error;
...@@ -263,13 +263,13 @@ done: ...@@ -263,13 +263,13 @@ done:
return error; return error;
} }
int git_blob_create_fromworkdir( int git_blob_create_from_workdir(
git_oid *id, git_repository *repo, const char *path) git_oid *id, git_repository *repo, const char *path)
{ {
return git_blob__create_from_paths(id, NULL, repo, NULL, path, 0, true); 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) git_oid *id, git_repository *repo, const char *path)
{ {
int error; int error;
...@@ -325,7 +325,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer, ...@@ -325,7 +325,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer,
return git_filebuf_write(&stream->fbuf, buffer, len); 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; int error;
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
...@@ -364,7 +364,7 @@ cleanup: ...@@ -364,7 +364,7 @@ cleanup:
return error; 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; int error;
blob_writestream *stream = (blob_writestream *) _stream; blob_writestream *stream = (blob_writestream *) _stream;
...@@ -427,3 +427,36 @@ int git_blob_filtered_content( ...@@ -427,3 +427,36 @@ int git_blob_filtered_content(
return error; 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);
}
...@@ -1477,7 +1477,7 @@ int git_index_add_frombuffer( ...@@ -1477,7 +1477,7 @@ int git_index_add_frombuffer(
if (index_entry_dup(&entry, index, source_entry) < 0) if (index_entry_dup(&entry, index, source_entry) < 0)
return -1; 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) { if (error < 0) {
index_entry_free(entry); index_entry_free(entry);
return error; return error;
......
...@@ -288,7 +288,7 @@ static int note_write( ...@@ -288,7 +288,7 @@ static int note_write(
/* TODO: should we apply filters? */ /* TODO: should we apply filters? */
/* create note object */ /* 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; goto cleanup;
if ((error = manipulate_note_in_tree_r( if ((error = manipulate_note_in_tree_r(
......
...@@ -87,14 +87,14 @@ void test_filter_blob__ident(void) ...@@ -87,14 +87,14 @@ void test_filter_blob__ident(void)
git_buf buf = { 0 }; git_buf buf = { 0 };
cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n"); 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_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_assert_equal_s( cl_assert_equal_s(
"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob)); "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
git_blob_free(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_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_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_assert_equal_s( cl_assert_equal_s(
"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob)); "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
......
...@@ -23,7 +23,7 @@ static void add_blob_and_filter( ...@@ -23,7 +23,7 @@ static void add_blob_and_filter(
git_buf out = { 0 }; git_buf out = { 0 };
cl_git_mkfile("crlf/identtest", data); 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_blob_lookup(&blob, g_repo, &id));
cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob)); cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
......
...@@ -352,7 +352,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe ...@@ -352,7 +352,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
return 0; return 0;
for (i = 0; i < expected_len; i++) { 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); git_oid_fromstr(&expected_oid, expected[i].oid_str);
if (git_oid_cmp(&actual_oid, &expected_oid) != 0) if (git_oid_cmp(&actual_oid, &expected_oid) != 0)
......
...@@ -59,7 +59,7 @@ void test_object_blob_filter__initialize(void) ...@@ -59,7 +59,7 @@ void test_object_blob_filter__initialize(void)
if (g_crlf_raw_len[i] < 0) if (g_crlf_raw_len[i] < 0)
g_crlf_raw_len[i] = strlen(g_crlf_raw[i]); 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])); &g_crlf_oids[i], g_repo, g_crlf_raw[i], (size_t)g_crlf_raw_len[i]));
} }
} }
......
...@@ -29,12 +29,12 @@ void test_object_blob_fromstream__multiple_write(void) ...@@ -29,12 +29,12 @@ void test_object_blob_fromstream__multiple_write(void)
cl_git_fail_with(GIT_ENOTFOUND, cl_git_fail_with(GIT_ENOTFOUND,
git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_ANY)); 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++) for (i = 0; i < howmany; i++)
cl_git_pass(stream->write(stream, textual_content, strlen(textual_content))); 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_assert_equal_oid(&expected_id, &id);
cl_git_pass(git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_BLOB)); 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 ...@@ -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_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++) for (i = 0; i < howmany; i++)
cl_git_pass(stream->write(stream, textual_content, strlen(textual_content))); 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_assert_equal_oid(&expected_id, &id);
} }
......
...@@ -33,7 +33,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_lo ...@@ -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); 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) 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 ...@@ -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_path_prettify_dir(&full_path, ELSEWHERE, NULL));
cl_must_pass(git_buf_puts(&full_path, "test.txt")); 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); git_buf_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES)); 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 ...@@ -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_path_prettify_dir(&full_path, ELSEWHERE, NULL));
cl_must_pass(git_buf_puts(&full_path, "test.txt")); 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); git_buf_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES)); cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
......
...@@ -51,10 +51,10 @@ void test_odb_backend_mempack__exists_with_existing_objects_succeeds(void) ...@@ -51,10 +51,10 @@ void test_odb_backend_mempack__exists_with_existing_objects_succeeds(void)
cl_assert(git_odb_exists(_odb, &_oid) == 1); 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"; 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); cl_assert(git_odb_exists(_odb, &_oid) == 1);
} }
...@@ -47,7 +47,7 @@ void test_odb_freshen__loose_blob(void) ...@@ -47,7 +47,7 @@ void test_odb_freshen__loose_blob(void)
set_time_wayback(&before, LOOSE_BLOB_FN); set_time_wayback(&before, LOOSE_BLOB_FN);
/* make sure we freshen a blob */ /* 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_assert_equal_oid(&expected_id, &id);
cl_must_pass(p_lstat("testrepo.git/objects/" LOOSE_BLOB_FN, &after)); cl_must_pass(p_lstat("testrepo.git/objects/" LOOSE_BLOB_FN, &after));
...@@ -66,13 +66,13 @@ void test_odb_freshen__readonly_object(void) ...@@ -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_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); cl_assert_equal_oid(&expected_id, &id);
set_time_wayback(&before, UNIQUE_BLOB_FN); set_time_wayback(&before, UNIQUE_BLOB_FN);
cl_assert((before.st_mode & S_IWUSR) == 0); 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_assert_equal_oid(&expected_id, &id);
cl_must_pass(p_lstat("testrepo.git/objects/" UNIQUE_BLOB_FN, &after)); cl_must_pass(p_lstat("testrepo.git/objects/" UNIQUE_BLOB_FN, &after));
......
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