Skip to content
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

radicle-surf: Repository.blob_at() to retrieve a blob using its oid. #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keepsimple1
Copy link
Contributor

This is motived by a discussion on zulip.

Signed-off-by: Han Xu <keepsimple@gmail.com>
/// Retrieves the blob with `oid` in `commit`.
pub fn blob_at<'a, C: ToCommit>(
&'a self,
commit: C,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input commit is not required if we only wanted to retrieve the blob content. It is here as we also need to retrieve the Blob.commit that created the blob (oid).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't expecting to have the commit as a parameter, so what if we changed the result type to just BlobRef<'a>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, and I chose to have the commit parameter for a couple of reasons:

  1. To be consistent in the API (similar to blob()), including the return type Blob. The intent of Blob.commit was helping the caller to identify the last_commit easily without having to do another HTTP call. That is the same for both blob() and blob_at().

  2. From the zulip discussion linked in Description, the caller would (most likely) have the commit info available.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the zulip discussion linked in Description, the caller would (most likely) have the commit info available.

My reading of the discussion was that we should be able to get a blob without the commit[0]. So if something doesn't know about a commit but does have a blob id, then it can just retrieve the blob content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the original request message.

Yeah, like we discussed so far, there are two options that I can see:

a) Get the blob content only (input: Oid). If the caller wanted to find the commit that created the blob, they make another HTTP call. This is not consistent with existing blob() method.

b) Get the blob content and the commit that created the blob. (input: Oid and a Commit that has the blob. ) . Both info are retrieved in one call. This is consistent with existing blob() method.

For the blob content part, b) does more involved work than a), because it also retrieves the commit.

It's a trade-off. My preference is to go with option b) based on the reasons I mentioned earlier. And if we did want to go with a), I would suggest to re-visit Blob struct and see if it makes sense to separate Blob.commit out, and then change blob() to be consistent with blob_at().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the original request message.

Sure and within that thread, I mentioned how I imagined the URL being '.../blob/<oid>' :)

I don't mind going down this route, but I don't understand why we have to go fetch the commit that created the blob. Can you explain why that's necessary?

I'd expect that we just check the Blob's Oid exists with the Commit's tree, either via diff or using a tree walk.

Copy link
Contributor Author

@keepsimple1 keepsimple1 Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind going down this route, but I don't understand why we have to go fetch the commit that created the blob. Can you explain why that's necessary?

It's because this existing Blob struct and its API:

/// Returns the commit that created this blob.
pub fn commit(&self) -> &Commit {
&self.commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants