-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[RFC] basic note iterator implementation #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* git_note_iterator_new() - create a new note iterator * git_note_next() - retrieves the next item of the iterator
error = retrieve_note_tree_and_commit(&tree, &commit, repo, ¬es_ref); | ||
if (!error) { | ||
*it = (git_note_iterator *)git__malloc(sizeof(git_iterator)); | ||
GITERR_CHECK_ALLOC(*it); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git_iterator_for_tree()
will do this allocation for you. You don't need to preallocate the object.
@cholin ❤️ Thanks for this! Looking pretty good! ⭐ ⭐ All my comments are small things. In addition to the other comments, I'd love to see you rewrite int git_note_foreach(
git_repository *repo,
const char *notes_ref,
git_note_foreach_cb note_cb,
void *payload)
{
int error;
git_note_iterator *iter = NULL;
git_oid note_id, annotated_id;
if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0)
return error;
while (!(error = git_note_iterator_next(¬e_id, &annotated_id, iter))) {
if (note_cb(¬e_id, &annotated_id, payload)) {
error = GIT_EUSER;
break;
}
}
if (error == GIT_ITEROVER)
error = 0;
git_note_iterator_free(iter);
return error;
} (Sorry, I didn't really test that code, but it should be something like that.) It's not that that is so much less code, but just that it means there will be only one version of the logic to setup and advance through the list. In some cases (e.g. diff), the foreach API doesn't use the iterator API because there is a significant performance or memory cost for doing so, but in this case, the two versions are identical. |
These are great news. Thanks @cholin for heading this project of adding more iterator objects to libgit2. I know you're specially interested on this for Python bindings, but other languages will certainly benefit from this. :) |
cl_git_pass(git_note_iterator_new(&iter, _repo, "refs/notes/beer")); | ||
|
||
for (i = 0; git_note_next(¬e_id, &annotated_id, iter) != GIT_ITEROVER; ++i) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise for this.
@arrbee: How would you feel if all iterators in the external API were generic |
* fixed style issues * use new iterator functions for git_note_foreach()
@vmg That's an interesting thought, but I'm not sure. This notes case is pretty special because it can directly use a tree iterator. I suspect that few of the other public iterators will map cleanly to the internal iterator objects. And right now, those internal iterator objects have a very specific semantics. For example, if we have a If you want to repurpose the Additionally, because of how I'm using them, it is more convenient for the internal iterator classes to support independent "look up the current value" and "advance to the next value" actions. This public notes API opts for a simpler "get current and advance to next" design, which I think is good for a public API since it keeps the number of functions small. |
I'd been thinking of doing that when writing the ref iterator. As no iterators are going to hold any common data, you'd have to |
I think if we were going to do it, we'd do something like: But again, I don't see a huge win from doing this. I'd rather agree on common naming and behaviors that we'll use consistently (e.g. |
Larger discussion aside, this looks good to go. Thanks @cholin ! |
[RFC] basic note iterator implementation
@vmg isn't the file ( |
yea accidently added it. my fault - sry. perhaps someone can remove it and add it to `.gitignore?. |
Damn, GitHub diff didn't show the content of that file and I overlooked it when I merged. :-( |
It's no longer used with clar2 so I just removed it. |
That at least explains why it's not any longer in the I strongly suggest that you fellows at github rethink that feature for not-showing too large diffs. Heck, this was a real source file - with the CMake-globs actually anything could have gone into the codebase without further notice... 🎱 |
[RFC] basic note iterator implementation
This is a basic note iterator implementation (regarding #1384). I would be happy about comments, as this is my first contribution to libgit2.
This pull requests adds the following functions:
git_note_iterator_new()
- create a new note iteratorgit_note_iterator_free()
git_note_next()
- retrieves the next item of the iterator