RangerMauve / hypercore-fetch

Implementation of Fetch that uses the Hyper SDK for loading p2p content
MIT License
36 stars 12 forks source link

Navigate version history on a per-file basis #36

Closed josephmturner closed 1 year ago

josephmturner commented 1 year ago

One way to explore the history of a particular file:

Loop through hyperdrive version numbers, starting with the current version and going backwards. Check if drive.diff(...) returns non-null (we could use a HEAD request for this?). If so, checkout that version and display the file at that version or inform the user that the file didn't exist before that version.

What about the edge-case where a file was created, deleted, then created again? Can we just continue checking back in time until we get a non-null diff or we get to the beginning of the history?

Do you know of a better approach? I imagine that sending a new HTTP request to hyper-gateway on each loop could be slow.

RangerMauve commented 1 year ago

Hmm, not sure if HEAD would make sense here.

Let me think about diffs for a week or two.

josephmturner commented 1 year ago

To accomplish this, we could extrapolate on the ideas discussed here and here.

If the latest version of the drive is version 100 and user wants to checkout the version of /example.txt before the last change, send a GET request to hyper://public-key/$/previous/100/example.txt. Assuming that the most recent different version of /example.txt is version 42, this would have the same effect as GET hyper://public-key/$/version/42/example.txt. A HEAD request should return just the headers, allowing for a quick overview of the version history of particular file, including file sizes, modification dates, and version numbers.

Going forward through version history, GET hyper://public-key/$/previous/42/example.txt should give version 43. GET hyper://public-key/$/previous/42/example.txt should give version 100 (current).

RangerMauve commented 1 year ago

To get a diff we can use the ETag versins returned on a HEAD for a file.