mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 14:39:10 +00:00
Return the created entry in git_tree_add_entry()
Yes, we are breaking the API. Alpha software, deal with it. We need a way of getting a pointer to each newly added entry to the index, because manually looking up the entry after creation is outrageously expensive. Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
37c2d54c85
commit
b29e8f1930
@ -132,18 +132,21 @@ GIT_EXTERN(const git_oid *) git_tree_entry_id(git_tree_entry *entry);
|
|||||||
GIT_EXTERN(int) git_tree_entry_2object(git_object **object, git_tree_entry *entry);
|
GIT_EXTERN(int) git_tree_entry_2object(git_object **object, git_tree_entry *entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new entry to a tree.
|
* Add a new entry to a tree and return the new entry.
|
||||||
*
|
*
|
||||||
* This will mark the tree as modified; the new entry will
|
* This will mark the tree as modified; the new entry will
|
||||||
* be written back to disk on the next git_object_write()
|
* be written back to disk on the next git_object_write()
|
||||||
*
|
*
|
||||||
|
* @param entry_out Pointer to the entry that just got
|
||||||
|
* created. May be NULL if you are not interested on
|
||||||
|
* getting the new entry
|
||||||
* @param tree Tree object to store the entry
|
* @param tree Tree object to store the entry
|
||||||
* @iparam id OID for the tree entry
|
* @iparam id OID for the tree entry
|
||||||
* @param filename Filename for the tree entry
|
* @param filename Filename for the tree entry
|
||||||
* @param attributes UNIX file attributes for the entry
|
* @param attributes UNIX file attributes for the entry
|
||||||
* @return 0 on success; otherwise error code
|
* @return 0 on success; otherwise error code
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_tree_add_entry(git_tree *tree, const git_oid *id, const char *filename, int attributes);
|
GIT_EXTERN(int) git_tree_add_entry(git_tree_entry **entry_out, git_tree *tree, const git_oid *id, const char *filename, int attributes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an entry by its index.
|
* Remove an entry by its index.
|
||||||
|
@ -174,7 +174,7 @@ size_t git_tree_entrycount(git_tree *tree)
|
|||||||
return tree->entries.length;
|
return tree->entries.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_tree_add_entry(git_tree *tree, const git_oid *id, const char *filename, int attributes)
|
int git_tree_add_entry(git_tree_entry **entry_out, git_tree *tree, const git_oid *id, const char *filename, int attributes)
|
||||||
{
|
{
|
||||||
git_tree_entry *entry;
|
git_tree_entry *entry;
|
||||||
|
|
||||||
@ -195,6 +195,9 @@ int git_tree_add_entry(git_tree *tree, const git_oid *id, const char *filename,
|
|||||||
|
|
||||||
git_vector_sort(&tree->entries);
|
git_vector_sort(&tree->entries);
|
||||||
|
|
||||||
|
if (entry_out != NULL)
|
||||||
|
*entry_out = entry;
|
||||||
|
|
||||||
tree->object.modified = 1;
|
tree->object.modified = 1;
|
||||||
return GIT_SUCCESS;
|
return GIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,11 @@ BEGIN_TEST(tree_in_memory_add_test)
|
|||||||
git_oid_mkstr(&entry_id, tree_oid);
|
git_oid_mkstr(&entry_id, tree_oid);
|
||||||
for (i = 0; i < entry_count; ++i) {
|
for (i = 0; i < entry_count; ++i) {
|
||||||
char filename[32];
|
char filename[32];
|
||||||
|
git_tree_entry *ent = NULL;
|
||||||
|
|
||||||
sprintf(filename, "file%d.txt", i);
|
sprintf(filename, "file%d.txt", i);
|
||||||
must_pass(git_tree_add_entry(tree, &entry_id, filename, 040000));
|
must_pass(git_tree_add_entry(&ent, tree, &entry_id, filename, 040000));
|
||||||
|
must_be_true(ent != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
must_be_true(git_tree_entrycount(tree) == entry_count);
|
must_be_true(git_tree_entrycount(tree) == entry_count);
|
||||||
@ -51,8 +54,10 @@ BEGIN_TEST(tree_add_entry_test)
|
|||||||
|
|
||||||
must_be_true(git_tree_entrycount(tree) == 3);
|
must_be_true(git_tree_entrycount(tree) == 3);
|
||||||
|
|
||||||
git_tree_add_entry(tree, &id, "zzz_test_entry.dat", 0);
|
/* check there is NP if we don't want the
|
||||||
git_tree_add_entry(tree, &id, "01_test_entry.txt", 0);
|
* created entry back */
|
||||||
|
git_tree_add_entry(NULL, tree, &id, "zzz_test_entry.dat", 0);
|
||||||
|
git_tree_add_entry(NULL, tree, &id, "01_test_entry.txt", 0);
|
||||||
|
|
||||||
must_be_true(git_tree_entrycount(tree) == 5);
|
must_be_true(git_tree_entrycount(tree) == 5);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user