package duff

  1. Overview
  2. Docs
LibXdiff implementation in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

duff-0.1.tbz
sha256=755d0f2595b0bd4c4183ac153d917692c9cb555e1319a4286b99bfcd9e9ce10a
md5=c42d3fcfd1062a3422012b97ee8f543c

Description

Duff is a little library to implement libXdiff in OCaml. This library is a part of the ocaml-git project. This code is a translation of diff-delta.c available on the git project in OCaml. So, it respects some git's constraints unlike libXdiff.

Published: 20 Apr 2018

README

Duff – libXdiff implementation in OCaml

Duff is a little library to implement libXdiff in OCaml. This library is a part of the ocaml-git project. This code is a translation of diff-delta.c available on the git project in OCaml. So, it respects some git's constraints unlike libXdiff.

Examples

This library let the user to calculate an Index.t from a source (a hash-table) which can be computed with a blob. Then, from Index.t (which represents your source) and a blob, we generate a list of Copy and Insert elements.

  • Copy (off, len) means to take a slice of len bytes from your source at off (absolute offset) and copy it.

  • Insert (off, len) means to store a slice of len bytes from your blob at off (absolute offset) and copy it.

From this information, we can have a tiny representation of your blob which can be reconstruct with your source. The goal is to store Copy opcode with off and len, and Insert opcode which contains entirely slice of your blob.

Finally, to procude a PACK file in git or ocaml-git, we use this algorithm and this representation to optimize representation of your blobs (cf. git gc).

Binary

You can see an example of duff in bin directory. It's an executable to represent a thin representation of your file. Then, you can reconstruct it with patch sub-command.

This is an example to use duff:

$ ./duff.exe diff source target > target.xduff
$ ./duff.exe patch source < target.xduff > target.new
$ diff target target.new
$ echo $?
0

The internal format used is close to what git does internally (without zlib layer). However, it does not correspond to an official format.

Limitations

Because this project is used by ocaml-git, we have some limitations:

  • We compute at most 0xFFFFFFFE bytes from source

  • An insert block can not be bigger than 0x10000 bytes

For example, libXdiff computes a bigger source than this implementation. Then, limitation about insert block depends on the PACK (git) file format. So, don't ask me to compute bigger source or merge and produce bigger insert block - these constraints is outside this library.

From this limitation, Copy opcode have an offset between 0x0 and 0xFFFFFFE and off + len is lower than 0xFFFFFFFE.

Fuzzer

We provide a fuzzer to randomly test this library. Currently (4/9/2018), afl-fuzz did not find any bugs and it computed 67.7k cycles (117 paths).

Dependencies (9)

  1. fpath >= "0.7.0"
  2. bos >= "0.2.0"
  3. fmt >= "0.8.5"
  4. logs >= "0.6.2"
  5. cmdliner >= "1.0.2" & < "1.1.0"
  6. cstruct < "6.1.0"
  7. fmt
  8. jbuilder >= "1.0+beta9"
  9. ocaml >= "4.03.0" & < "5.1"

Dev Dependencies (1)

  1. alcotest with-test

Used by (1)

  1. git >= "2.0.0" & < "3.0.0"

Conflicts

None

OCaml

Innovation. Community. Security.