Skip to content

Commit 6574cd0

Browse files
committed
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.
1 parent 08f3920 commit 6574cd0

File tree

8 files changed

+38
-23
lines changed

8 files changed

+38
-23
lines changed

include/git2/deprecated.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ GIT_EXTERN(void) giterr_set_oom(void);
191191

192192
/**@}*/
193193

194-
/** @name Deprecated Index Constants
194+
/** @name Deprecated Index Functions and Constants
195195
*
196-
* These enumeration values are retained for backward compatibility.
197-
* The newer versions of these values should be preferred in all new code.
196+
* These functions and enumeration values are retained for backward
197+
* compatibility. The newer versions of these values should be
198+
* preferred in all new code.
198199
*
199200
* There is no plan to remove these backward compatibility values at
200201
* this time.
@@ -234,6 +235,11 @@ GIT_EXTERN(void) giterr_set_oom(void);
234235
#define GIT_INDEXCAP_NO_SYMLINKS GIT_INDEX_CAPABILITY_NO_SYMLINKS
235236
#define GIT_INDEXCAP_FROM_OWNER GIT_INDEX_CAPABILITY_FROM_OWNER
236237

238+
GIT_EXTERN(int) git_index_add_frombuffer(
239+
git_index *index,
240+
const git_index_entry *entry,
241+
const void *buffer, size_t len);
242+
237243
/**@}*/
238244

239245
/** @name Deprecated Object Constants

include/git2/index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
572572
* @param len length of the data
573573
* @return 0 or an error code
574574
*/
575-
GIT_EXTERN(int) git_index_add_frombuffer(
575+
GIT_EXTERN(int) git_index_add_from_buffer(
576576
git_index *index,
577577
const git_index_entry *entry,
578578
const void *buffer, size_t len);

src/index.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ GIT_INLINE(bool) valid_filemode(const int filemode)
14541454
return (is_file_or_link(filemode) || filemode == GIT_FILEMODE_COMMIT);
14551455
}
14561456

1457-
int git_index_add_frombuffer(
1457+
int git_index_add_from_buffer(
14581458
git_index *index, const git_index_entry *source_entry,
14591459
const void *buffer, size_t len)
14601460
{
@@ -3709,3 +3709,12 @@ void git_indexwriter_cleanup(git_indexwriter *writer)
37093709
git_index_free(writer->index);
37103710
writer->index = NULL;
37113711
}
3712+
3713+
/* Deprecated functions */
3714+
3715+
int git_index_add_frombuffer(
3716+
git_index *index, const git_index_entry *source_entry,
3717+
const void *buffer, size_t len)
3718+
{
3719+
return git_index_add_from_buffer(index, source_entry, buffer, len);
3720+
}

tests/index/filemodes.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void add_entry_and_check_mode_(
164164
git_index_entry new_entry;
165165

166166
/* If old_filename exists, we copy that to the new file, and test
167-
* git_index_add(), otherwise create a new entry testing git_index_add_frombuffer
167+
* git_index_add(), otherwise create a new entry testing git_index_add_from_buffer
168168
*/
169169
if (from_file)
170170
{
@@ -189,7 +189,7 @@ static void add_entry_and_check_mode_(
189189
else
190190
{
191191
const char *content = "hey there\n";
192-
clar__assert(!git_index_add_frombuffer(index, &new_entry, content, strlen(content)),
192+
clar__assert(!git_index_add_from_buffer(index, &new_entry, content, strlen(content)),
193193
file, line, "Cannot add index entry from buffer", NULL, 1);
194194
}
195195

@@ -207,7 +207,7 @@ void test_index_filemodes__explicit(void)
207207
git_index *index;
208208

209209
/* These tests should run and work everywhere, as the filemode is
210-
* given explicitly to git_index_add or git_index_add_frombuffer
210+
* given explicitly to git_index_add or git_index_add_from_buffer
211211
*/
212212
cl_repo_set_bool(g_repo, "core.filemode", false);
213213

@@ -271,7 +271,7 @@ void test_index_filemodes__frombuffer_requires_files(void)
271271
new_entry.path = "dummy-file.txt";
272272
new_entry.mode = GIT_FILEMODE_BLOB;
273273

274-
cl_git_pass(git_index_add_frombuffer(index,
274+
cl_git_pass(git_index_add_from_buffer(index,
275275
&new_entry, content, strlen(content)));
276276

277277
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)
282282
new_entry.path = "dummy-file.txt";
283283
new_entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE;
284284

285-
cl_git_pass(git_index_add_frombuffer(index,
285+
cl_git_pass(git_index_add_from_buffer(index,
286286
&new_entry, content, strlen(content)));
287287

288288
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)
293293
new_entry.path = "dummy-link.txt";
294294
new_entry.mode = GIT_FILEMODE_LINK;
295295

296-
cl_git_pass(git_index_add_frombuffer(index,
296+
cl_git_pass(git_index_add_from_buffer(index,
297297
&new_entry, content, strlen(content)));
298298

299299
cl_assert((ret_entry = git_index_get_bypath(index, "dummy-link.txt", 0)));
@@ -304,15 +304,15 @@ void test_index_filemodes__frombuffer_requires_files(void)
304304
new_entry.path = "invalid_mode.txt";
305305
new_entry.mode = GIT_FILEMODE_TREE;
306306

307-
cl_git_fail(git_index_add_frombuffer(index,
307+
cl_git_fail(git_index_add_from_buffer(index,
308308
&new_entry, content, strlen(content)));
309309
cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0));
310310

311311
/* submodules are rejected */
312312
new_entry.path = "invalid_mode.txt";
313313
new_entry.mode = GIT_FILEMODE_COMMIT;
314314

315-
cl_git_fail(git_index_add_frombuffer(index,
315+
cl_git_fail(git_index_add_from_buffer(index,
316316
&new_entry, content, strlen(content)));
317317
cl_assert_equal_p(NULL, git_index_get_bypath(index, "invalid_mode.txt", 0));
318318

tests/index/racy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static void setup_uptodate_files(void)
193193
/* Put 'C' into the index */
194194
new_entry.path = "C";
195195
new_entry.mode = GIT_FILEMODE_BLOB;
196-
cl_git_pass(git_index_add_frombuffer(index, &new_entry, "hello!\n", 7));
196+
cl_git_pass(git_index_add_from_buffer(index, &new_entry, "hello!\n", 7));
197197

198198
git_index_free(index);
199199
git_buf_dispose(&path);

tests/index/tests.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void test_index_tests__add_frombuffer(void)
310310
memset(&entry, 0x0, sizeof(git_index_entry));
311311
entry.mode = GIT_FILEMODE_BLOB;
312312
entry.path = "test.txt";
313-
cl_git_pass(git_index_add_frombuffer(index, &entry,
313+
cl_git_pass(git_index_add_from_buffer(index, &entry,
314314
content, strlen(content)));
315315

316316
/* Wow... it worked! */
@@ -352,7 +352,7 @@ void test_index_tests__dirty_and_clean(void)
352352
/* Index is dirty after adding an entry */
353353
entry.mode = GIT_FILEMODE_BLOB;
354354
entry.path = "test.txt";
355-
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4));
355+
cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
356356
cl_assert(git_index_entrycount(index) == 1);
357357
cl_assert(git_index_is_dirty(index));
358358

@@ -374,7 +374,7 @@ void test_index_tests__dirty_and_clean(void)
374374
cl_assert(!git_index_is_dirty(index));
375375

376376
/* Index is dirty when we do an unforced read with dirty content */
377-
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4));
377+
cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
378378
cl_assert(git_index_entrycount(index) == 1);
379379
cl_assert(git_index_is_dirty(index));
380380

@@ -402,15 +402,15 @@ void test_index_tests__dirty_fails_optionally(void)
402402
/* Index is dirty after adding an entry */
403403
entry.mode = GIT_FILEMODE_BLOB;
404404
entry.path = "test.txt";
405-
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4));
405+
cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
406406
cl_assert(git_index_is_dirty(index));
407407

408408
cl_git_pass(git_checkout_head(repo, NULL));
409409

410410
/* Index is dirty (again) after adding an entry */
411411
entry.mode = GIT_FILEMODE_BLOB;
412412
entry.path = "test.txt";
413-
cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4));
413+
cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
414414
cl_assert(git_index_is_dirty(index));
415415

416416
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)
455455
memset(&entry, 0x0, sizeof(git_index_entry));
456456
entry.mode = GIT_FILEMODE_BLOB;
457457
entry.path = "test.txt";
458-
cl_git_pass(git_index_add_frombuffer(index, &entry,
458+
cl_git_pass(git_index_add_from_buffer(index, &entry,
459459
content, strlen(content)));
460460

461461
/* Wow... it worked! */

tests/index/version.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void test_index_version__can_write_v4(void)
5555
memset(&entry, 0, sizeof(entry));
5656
entry.path = paths[i];
5757
entry.mode = GIT_FILEMODE_BLOB;
58-
cl_git_pass(git_index_add_frombuffer(index, &entry, paths[i],
58+
cl_git_pass(git_index_add_from_buffer(index, &entry, paths[i],
5959
strlen(paths[i]) + 1));
6060
}
6161
cl_assert_equal_sz(git_index_entrycount(index), ARRAY_SIZE(paths));
@@ -100,7 +100,7 @@ void test_index_version__v4_uses_path_compression(void)
100100
path[ARRAY_SIZE(path) - 3] = i;
101101
path[ARRAY_SIZE(path) - 2] = j;
102102
path[ARRAY_SIZE(path) - 1] = '\0';
103-
cl_git_pass(git_index_add_frombuffer(index, &entry, buf, sizeof(buf)));
103+
cl_git_pass(git_index_add_from_buffer(index, &entry, buf, sizeof(buf)));
104104
}
105105
}
106106

tests/object/tree/read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void test_object_tree_read__largefile(void)
9898
ie.path = BIGFILE;
9999

100100
cl_git_pass(git_repository_index(&index, g_repo));
101-
cl_git_pass(git_index_add_frombuffer(index, &ie, buf, BIGFILE_SIZE));
101+
cl_git_pass(git_index_add_from_buffer(index, &ie, buf, BIGFILE_SIZE));
102102
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, BIGFILE);
103103

104104
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));

0 commit comments

Comments
 (0)