-
Notifications
You must be signed in to change notification settings - Fork 906
Exposing clearing the index #814
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
3fc143b
to
a5bc9f0
Compare
Could you please take a look at this test? Empty Tree looks supported 😉 @carlosmn From an index perspective, what would be the difference between clearing it and replacing its content by reading an empty Tree? |
I'm sorry for being unclear. I wasn't saying that it isn't supported, merely that core Git has special case support for the empty tree sha libgit2/libgit2#1713 (comment)
It is indeed possible to do |
They are practically the same thing, as you first clear out the index anyway and then you just don't refill it. But this is more about how to best make the method call expressive. I would go with |
I agree with @carlosmn regarding However, regarding He/Her may not understand exactly what is the However, it's possible that I may be lacking some perspective on this subject. How would one perform such operation with git.git? Is it a common operation that git users rely on frequently? /cc @dahlbyk @KindDragon |
I took the inspiration from this from @arrbee's comment about empty trees in libgit2 — "in most cases where you would use the empty tree in core Git, we just allow you to pass NULL to indicate an empty tree"
This was my concern as well and before I submitted this PR I asked some of the other native devs at GitHub what they thought an
Yes, and that's why I suggest that if/when libgit2 gains the same level of fake-object support for the empty tree hash libgit2sharp can expose a static readonly property on the
No, definitely not. I can only think of a select few cases which is why I tried to make it slightly obfuscated. |
I am of the mind that libgit2 should not do this. This seems very porcelainy to me, though that's just my opinion. How hard would it be to make a static empty tree without libgit2's assistance? I suspect this is a lot of churn, presumably I guess |
I feel like this discussion is becoming bigger than the scope of this PR. I would like to be able to use While I personally like that |
That's the plumbing way. The porcelain way would be While we use
If someone things the index is log-based, would think anything differently from clear to destroy or erase? |
a5bc9f0
to
9b82ad9
Compare
Thanks, this context is most useful.
Unclear, maybe? As I said I'm pro |
I think that's the point. Unless I'm wrong, "unstaging" is different from "clearing" the index.
What's the drawback of creating one when you need it? Then GHfW could hold on the generated |
It is.
We didn't have to create a tree when we were shelling out and now we do. That is the drawback. Why should we have to create a tree when there's a way to do it that doesn't require jumping through hoops? The way I see this there's a right way to do it and then there's a workaround for the right way not being exposed through libgit2sharp. How can we move this PR forward to address that? |
@niik I'm not sure to understand the drawback you're referring to. I don't think creating the
I'm not sure there's a definitive "right way' 😉 However, one proposal may be for instance, to make the Clearing the index, would then involve a call to Later, when libgit2 exposes way to cope with this magic empty tree (without requiring it to actually exist in the odb), we'll just have to tweak the LibGit2Sharp implementation without changes to the consumed API. Thoughts? |
I'm sorry, but I don't understand what's really being discussed here. Is there a philosophical objection to exposing functionality that exists in libgit2? If so, that seems really unfortunate for a wrapper library. If the concern is that it might be offputting to newbie users, that can be solved with documentation, or a separate API that is akin to libgit2's As with any framework, I strongly believe that things should be safe/easy/simple by default. However, in general—and especially for our product (GitHub for Windows)—there needs to be a way to break out of that box and access “advanced user” features when necessary. If libgit2sharp can't or won't provide this, we'll effectively need a different wrapper library for libgit2. |
libgit2sharp fulfills a role on Windows which would often be fulfilled by the git tool on other operating systems. The main concern is how to expose something that's not too dangerous for someone who isn't familiar with the Git system. This presents an issue of where to put the delineation.
Indeed. Though the thing with documentation is that you barely read it before you get into trouble (well, at least the cases you often end up having to support). Chatting with @nulltoken about where to draw lines between providing helpers and direct access to the data structures, it appears we have reached an understanding. The methods under I think we shouldn't deleay this and merge this as-is (minus the leftover comments about |
/// <param name="source"> | ||
/// The <see cref="Tree"/> to read the entries from. | ||
/// If null the index will be reset to an empty tree. | ||
/// </param> |
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.
This documentation change is no longer accurate.
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.
Good catch, I'll fix this asap
9b82ad9
to
3842999
Compare
3842999
to
e335cd0
Compare
Fixed the documentation leftovers and rebased on top of vNext! |
Yeah, that's more or less the concern. I feel wary of making the same type exposing high level operations user friendly operations and low level bare-bone ones. I was thinking about something along the lines of keeping the high level ones under @carlosmn's proposal (moving |
@niik ✨ |
Sweet, that sounds like a great way forward. ✨ |
GitHub for Windows needs a way to blow away the entire index (undoing the initial commit). Up until now we've done this through shelling out but I'm moving that over to libgit2sharp now.
Clearing the index can be done right now in l2gs by explicitly creating an empty tree object and resetting to that but that involves a few more moving parts of actually creating the object in the odb and I was thinking there should be a way to explicitly clear as well.
Initially I though about adding an
Index.Clear
that callsgit_index_clear
but I'm concerned that people will confuseIndex.Clear
with something that just unstages everything, not clearing the index completely so I opted for allowing passing in null toIndex.Reset
and clearly documenting it.There has been some discussion of libgit2 supporting the empty tree sha (libgit2/libgit2#1713 (comment)). If libgit2 ends up supporting that a Tree.Empty static property might be a nice touch.