diff.rs icon indicating copy to clipboard operation
diff.rs copied to clipboard

Support diffing against the original repo

Open epage opened this issue 1 year ago • 6 comments

The information is usually present.

For context for the use case, see https://rust-lang.zulipchat.com/#narrow/stream/318791-t-crates-io/topic/Link.20to.20where.20the.20sources.20of.20a.20crate.20are.20located.20in.20git/near/429819690

epage avatar Mar 27 '24 13:03 epage

I can look into this, it sounds like something that could be useful.

Just for my understanding: do you mean that diff.rs should diff a released version of a crate with the commit in git?

One idea I had was to be able to diff a released version of a crate vs a specific branch. As in: compare v0.3.1 vs master. But that sounds like a slightly different use-case to the one that you are describing.

xfbs avatar Mar 28 '24 20:03 xfbs

Just for my understanding: do you mean that diff.rs should diff a released version of a crate with the commit in git?

Yes, particularly the commit used when publishing. On publish, cargo records

  • commit hash
  • path within repo

So long as the user set their repo in the metadata, we can diff against that commit. Diffing against tags and branches could also be nice; I just don't have as concrete of use cases for doing so.

epage avatar Mar 28 '24 21:03 epage

So, one way to get this done is:

  • parse the Cargo.toml in the diff version (left)
  • check if repository is in the metadata
  • in the right version dropdown, show an entry for git
  • if selected, attempt to fetch an archive of the commit (like https://github.com/$user/$repo/archive/aef66c462abe817e33aad91d97aa782a1e2ad2c7.tar.gz)
  • when doing the diff, have to account for the fact that the crate might live in a subfolder in the repo (in case of a cargo workspace)

xfbs avatar Mar 28 '24 21:03 xfbs

Yes and for

when doing the diff, have to account for the fact that the crate might live in a subfolder in the repo (in case of a cargo workspace)

the vcs info contains that path

epage avatar Mar 28 '24 21:03 epage

I've picked this up again, I might get something working this weekend. Currently need to do a bit maintenance work (replace yewprint with tailwind css, fix some visual bugs, get dark mode working, get mobile working) but it's on my queue!

xfbs avatar Oct 12 '24 15:10 xfbs

I have a partial implementation of this. So far, it's a little ugly. You can check it out by this link:

https://diff.rs/repo/serde/1.0.209/files/Cargo.toml

(There is only a partial UI for it atm, no navigation bar, will add later. also the file browser doesn't fully work, it will route you elsewhere, will fix that at some point)

One of the issues I have come across is that there are CORS permission issues. I cannot fetch the archives from the frontend directly, neither for github nor for gitlab.

My current workaround is to use https://corsproxy.io/ as a man-in-the-middle to fetch the archives, which works. But I'm not super happy with it.

For this feature to work properly, we need to do one of two things:

  • Convince GitHub, GitLab and other code hosts to set CORS headers that allow the frontend to make GET requests (hard)
  • Host a small API server that is used to fetch them (maybe also caches them)

It seems to me that option 2 is the easier one, although it is a bit sad because it means diff.rs is not completely backendless (although, that is not the highest priority, just happens to be a cool property).

xfbs avatar Oct 20 '24 20:10 xfbs