-
Notifications
You must be signed in to change notification settings - Fork 132
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
Support relative hashes across the entire API v2 surface #7268
Comments
IIRC, the new reference hash is in the Adding relative hash resolution to JSON payloads has a much bigger scope than making the |
I think we need to agree on what we mean by "the entire API surface":
But are there other cases that need any change apart from item 3 above? Here is a breakdown of all the parameters dealing with hashes:
I marked with Let me know if you agree before I can start working on this. |
If the above is agreed upon, the core change would be to amend I'd note that the current |
My reading of @colan-dremio 's request is that From my POV it generally makes sense, although I do see some rough edges in terminology. For example, the Re: |
I see the positive intent behind this (preventing mistakes), but do not feel this restriction is technically necessary. Especially if we allow relative hashes in the The "expected" hash in committing operations is used as the basis for conflict detection. So, using As for merges, indeed, the base is detected automatically. The commit hash in the |
Indeed that was asked, but I'm not sure I agree here. This endpoint returns information about an existing reference, designated by the path parameter. What would a hash, be it absolute or relative, have to do with that?
Isn't this a resurrection of the RefLog API? I'm not sure this is something we want to/can support. I do think, however, that it's confusing that this endpoint gladly accepts hashes (both absolute and relative), but silently ignores them. This could be improved by using a more restrictive validation regex. And as you pointed out, the docs also need some rewording. |
That's pretty much what's being done already. If we do a
I'm not sure, however, if "the sake of uniformity of URL mappings" buys us any good: I'd rather change the regex to reject anything that the service layer is going to reject anyways. Wdyt? |
Are you suggesting that we should revert #7193? I'm not against it, but that considerably widens the scope: not only we need to revert that PR, but also amend both |
We have two levels of RegEx's here:
I think (1) should be permissive to allow HTTP requests to be routed to the right method even if parameters are invalid. We can certainly use (2) to provide specific validation in each of the endpoints. |
Good point, I take back my proposal to restrict URL mapping regexes. But that makes it even more pressing for |
Not exactly. I mean only the |
There is the case where the relative hash is a timestamp in the future. That would resolve to HEAD. Probably needs some special handling. |
Yes, timestamps are quite special. I think we should certainly reject all future timestamps and perhaps have a time window in the recent past where timestamps are rejected too. This would be similar to I believe in most relevant use cases the timestamp would be provided by the end user and would not be a very recent timestamp. |
To summarize and hopefully clarify my stance:
As for |
As a matter of consistency, I think if we accept relative hashes in |
Yes I can live with that, and I do see the benefit of having the same treatment applied to all path params that denote a reference with or without a hash. That would boil down to also changing Maybe this method can be replaced completely by In any case the expected changes do not look too complex to me. |
Tentative scope of changes, revisited with suggestions from @dimas-b. Let's wait for @colan-dremio's input. EDIT 2023-07-27: added @snazy's suggestions.
|
Not generally opposed to support relative hash-specs per-se, but (possibly) ambiguous ones should be prevented for operations that write (create/assign/delete refs, commiting ops). With ambiguous I mean specs that reference HEAD (or derived ones like HEAD~3, because a concurrent commit would change the expected result, or that use a timestamp, even with some "allowed drift", because we do not know when a caller has actually looked into the branch - it can be hours ago. |
Amending that - non ambiguous specs are for example:
|
Good idea, I will amend the table above for create/assign/delete refs, and commiting ops. But that also brings the question: why not support non-ambiguous relative hashes in E.g. one could be in the below situation and want to merge ---
title: Merging from non-HEAD hash
---
gitGraph
commit id: "c1"
commit id: "c2"
branch etl
checkout main
commit id: "c3"
checkout etl
commit id: "c4"
checkout main
merge etl
checkout etl
commit id: "c5"
This could be achieved with the below request:
But it could also be achieved with the non-ambiguous relative hash
|
This LGTM 👍 |
Re: hash lookup by timestamp: I think those can be disambiguated if a base commit is specified, e.g. Since the base commit hash sets a specific point in history, the timestamp can be resolved strictly from that point on, and that resolution does not depend on local clocks either in the client or in the server. I agree that HEAD-based relative hashes are probably too ambiguous to support for write operations. |
Description:
PR 6932 added support for relative hashes (e.g.
main*10000000000
) to many APIs. It would be good to expose this concept across the entire API surface.For example, the commit log API already supports relative hashes, e.g.
GET http://localhost:19120/api/v2/trees/main*2023-07-17T17:44:36.463564257Z/history
. Since theGET api/v2/{ref}/history
endpoint is logically a child of the getReference endpointGET api/v2/{ref}
, it makes sense to support the same semantics in both. Today,GET http://localhost:19120/api/v2/trees/main*2023-07-17T17:44:36.463564257Z
does not work, but it should.Create reference
POST /api/v2/trees
is another example of a place where this would be useful. This would support operations like "Create branch dev at the state of main as it existed on 2023-07-17".Since all relative hashes evaluate to a real hash, semantically it is similar / the same as specifying a raw commit hash directly (Detached). In some cases, they will evaluate to the commit at the tip of a branch. IMO committing to a relative hash should never be allowed even if it resolves to the tip of a branch. Treating them as resolving to Detached will give us this behavior.
Another edge case is timestamps in the future (barring clock drift). It would be good to throw an error if a timestamp is provided too far into the future. Perhaps this is better as a separate issue.
The text was updated successfully, but these errors were encountered: