Repository navigation
Conversation
Libgit2 doesn't support working with partial clone repositories at the moment, so I'm not sure this is an actual compatibility concern. |
|
I think there might be some more cases that could/should result in GIT_EMISSING:
|
Maybe it would make sense to introduce a macro or inlined function for checking whether an error falls under the "not found"-umbrella. |
|
Addressing comments - @rcoup's suggested cases:
@neithernut re: error checking function - not done. It's a good idea, but might wait on the official reviewer to tell me which option they prefer. |
|
I had another idea - making a separate "error-subtype" int or bitfield or whatever in the thread-local, same as is used to store the last error message. That way all these errors could stay as "GIT_ENOTFOUND" errors, but if you also queried the error subtype you would find out if they were missing / promised. Other frameworks built on top of libgit2 which have exceptions instead of error codes would continue to represent these as "ObjectNotFoundException" or whatever, but those frameworks that chose to could add the the extra data as a field to the exception object - ie, most calling code would still simply catch ObjectNotFoundException, but some clients would then also check the caught exception to find out if the object that wasn't found was missing and/or promised. Or, if these error codes are too tricky, I guess the error messages themselves convey this information in much the same way - you can get it if you really need it. |
Error messages are usually directed at users. I doubt any binding author would willingly depend on a specific message (format). Imo error codes are the way to go, a thread-local error-state if it can't be done without breaking existing users. But I'm not a maintainer, so... |
|
I'm a little curious about the approach: instead of thinking about I feel like we'll get to a place where the This also lets clients keep their existing behavior around not found items (except those that are promised, of course). I wonder how breaking this is. (And this may be why you were thinking through the bitfield?) I would want to do a little more thinking about whether we think that there's a lot of users who are doing something with (I'd love to hear arguments one way or the other. 😁 ) |
|
Trying to design the behaviour - sorry it got a bit long. I will start by saying that these different types of errors have to be sort of best-effort or context-sensitive, unless we seriously redesign the libgit2 API. Looking up an object by its path involves knowing at least its immediate parent, whereas looking up an object by its ID does not involve knowing its immediate parent - nor is there a straight forward way of finding its parent(s) except for searching the entire ODB linearly. So if a client looks an object up by ID, and it's not found, it's always going to be GIT_ENOTFOUND since we don't know anything more than that about whether it "should" be there. As far as I know, finding a parent that references the requested object is the only way of making the distinction. This has two implications for me - the first is that it means that the basic GIT_ENOTFOUND can never go away (there are also other reasons why it can't - it currently mostly means "the object you have asked for clearly doesn't exist at all" which won't go away either, no matter how we divide up PROMISED and MISSING). The second is that it means we should probably make the distinction between these types of errors subtle - making too big a deal of it would indicate that these error codes reliably describe totally distinct situations, which they do not. I'm more and more inclined to return all these possible errors as GIT_ENOTFOUND, and then to have extra information you can query separately, which is filled in when it is available. With this approach, we can have as much or as little extra info as we want - we don't have to decide which new situations are important enough to break existing clients behaviour in the next major version. I've listed lots of possibilities below for how we could surface a little or a lot of information (I got a bit carried away).
Finally, to answer your first question - it feels to me as if information conveyed by GIT_EMISSING should still be surfaced if we have it (particularly if we are surfacing this info without changing existing error codes, so we can be as nuanced as we like). It's true that most clients will gain more value out of knowing if an object is promised or not, but in order to figure out if an object is promised, the information we gather might also tell us that the object is in that strange in-between state - not promised, not-non-existent, but also not present in the repo right now, for reasons unknown. Probably something has gone wrong. Most clients aren't gonna be able to do much about it but it since we went to the effort to find it out, and (when present) it indicates quite a different situation to "the object you have asked for simply doesn't exist", we may as well surface it. But, my feelings here aren't strong - basically any of the possibilities above seem okay for me. |
I don't understand this bit yet - wouldn't any object that is promised be in the promiser pack? Are you saying that the promiser pack is only a subset of the promised object IDs? How does querying by path vs object ID change this calculation? I feel like you're saying that if my partial clone is of depth 1 of a repository, I will get a single tree (the repository root) and a promiser pack with only the object ids referenced by that tree? And I would need to page in multiple trees as I recurse down to I didn't realize that, I thought the promisor pack was basically all the object IDs in the remote - it would do the same walk as before it would just produce a set of complete objects and a set of promised objects. |
|
Yeah sorry I wrote a little bit about this in #5776 but I should have been more clear about it in this PR which is actually implementing it. See https://git-scm.com/docs/partial-clone/2.19.0#_handling_missing_objects - notably "This means that there is no need for the client to explicitly maintain an expensive-to-modify list of missing objects." A promisor packfile is a packfile which contains objects which reference other objects, and those other objects are just missing which means "promised" (as far as I understand it). There's no special placeholders for the missing objects (except for the references themselves) and no lists of missing IDs. Yes so if you have only a single commit-tree in your ODB, without its children, and your plan is to walk the entire commit-tree, then a wise client would refetch the commit up front, this time with the entire depth, before starting the walk. (An unwise client would just start walking and fetch every time it found a missing object, which would fetch every object one by one - and of course, libgit2 simply fails at the moment if you tell it to walk a tree that has missing objects). Or if you just want a single object at I don't actually know much about how fetching missing objects work - it's outside the scope of this change. git will fetch missing objects for you if you do |
|
Hi @ethomson - sorry if the above got a bit philosophical. Is there anything I can do to help this along, or is there anything in particular where you feel we don't know how to proceed? I'm still thinking we can make this work with an extra error "subcode" that attentive-to-detail clients can query to find out what sort of "not-found" error they've encountered. Then divide the "not-found" errors into about 3 or 4 states. Most clients won't do anything with that data, but it's not a breaking change, and it's there for those that need it. |
|
I took the liberty of adding another commit that conveys the extra information we have so far as an error "subcode" - I can revert it if it doesn't make sense. So far the extra subcodes are "OBJECTMISSING" - as in, we have a tree-entry, but we don't have the object that it refers to - and "NOSUCHPATH" - the user supplied a path but we know there is no tree-entry with that name. In a follow-up PR I would add the PROMISED one that would be basically an OBJECTMISSING except it happened in a promisor-packfile. What do you think @ethomson? |
Apart from the object at a particular path simply being not found, there are two more possible cases that we could detect: - the parent tree-entry exists but the object is missing from the ODB - same as above, and the parent tree-entry is in a promisor packfile This sets up tests for both of those cases - right now they both simply result in ENOTFOUND though.
This error is returned when finding the object associated with a tree-entry fails - this will only happen if a) the ODB is corrupt or b) the object isn't fetched yet due to partial clone - the object is not available locally but can be fetched from a promisor remote. These two possibilites are not yet kept distinct from each other - they both get the same error code EMISSING. This change makes them distinct from the existing code ENOTFOUND.
Breaking the NOTFOUND error into different types of error is a backwards incompatible change - clients who check for NOTFOUND errors wouldn't recognise these new codes. Adding subcodes to the NOTFOUND error is backwards compatible - clients can check for these subcodes if they care. Also works well with the fact that different types of operation (eg lookup-by-id vs lookup-by-path) will have different capabilities of providing the extra subcode information.
73827aa to
545c00e
Compare
There are lots of different reasons a git object might not be found, and so far all are reported as GIT_ENOTFOUND.
This change gives one of these possible reasons a distinct error code - the case where we found a tree-entry describing some object, but we can't find the object. The error code is tentatively named GIT_EMISSING.
This shouldn't happen "normally" - "normally" the ODB is guaranteed not to contain such dangling pointers - but can happen for two reasons:
The second reason is probably the more interesting (most libgit2 clients probably don't really care about learning more about if or how the repo is corrupt, but they might want to better support partial clones) - and this reason could be usefully separated out into another code, GIT_EPROMISED. (Unfortunately we can't guarantee that the promisor remote will definitely have the missing object, but, it's pretty likely if the object is referenced but missing from a packfile that is marked as a promisor packfile).
Possible objection:
These error codes are special cases of GIT_ENOTFOUND, but unfortunately there's currently no way to add a subtype to an error. (GIT_EPROMISED would also ideally be a subtype of ENOTFOUND, perhaps even a sub-subtype of EMISSING). Clients who are currently checking for ENOTFOUND may have to update their code to also check for this new error code.
Related to old PR - #5776 - but that one has a faulty algorithm, so I just started over.