0

I want a function that accepts two strings and generates a diff patch string, a la git diff foo.

I am working on a wiki-style system with history. To implement history, I thought it would be effective to store document patch contents only, rather than full copies of each version of the document. Replaying patches seems like a nice way to reproduce any version of the document. git already does this well. I want to use git's version control ability without creating a git index for every document, and instead using my database as a lesser capable version store.

I'm planning on using https://docs.rs/git2/latest/git2/index.html, but cannot figure out yet:

  • how to create an empty, in mem git index
  • load my document v1 into the git index
  • diff my document v1 with document v2
  • extract the patch file text

Any advice would be great! I'm tagging with libcgit2 as well, because despite using rust, I'm confident I could port C examples to the rust bindings.

torek
  • 448,244
  • 59
  • 642
  • 775
cdaringe
  • 1,274
  • 2
  • 15
  • 33

1 Answers1

0

If your data is not stored as a git repository, libgit2 is not the best tool to help you. But it is a good library if you do want to store as a git repo.

If you want to diff two texts in Rust, you're probably better off using something like https://crates.io/crates/diff or https://crates.io/crates/slice-diff-patch.

Tomas Skäre
  • 174
  • 5