Format of the diffs returned by the API

I’m requesting the diffs for a certain commit. I get the response in JSON and read the diff field. But I don’t understand the format of the diff. Whatever library or tool I try, none is able to parse it (e.g. GitHub - rtfpessoa/diff2html: Pretty diff to html javascript library (diff2html) or GitHub - thombergs/diffparser: Parse unified diffs with Java.). The format doesn’t seem to be “unified diff” and while it looks similar it’s missing key components.

Getting informaton about diff formats isn’t easy. Is yours specified somewhere, does it have a name?

I saw Compare two commits using gitlab api and get response in `.diff` format but the problem isn’t really with the response being in JSON but with the “diff” field itself.

1 Like

Hi,

I’ve looked into the problem, it is about leaving out the context lines in the diff. They can be constructed from other fields in the response to create a unified diff. Commented on API - Repositories/Compare outputs an incorrectly formatted raw diff result (#24913) · Issues · GitLab.org / GitLab · GitLab to discuss changes to the response.

Cheers,
Michael

1 Like

Hi Michael,

thanks for the response. That works. Would be nice if didn’t need a hack (I saw you reopened the ticket) but it will do for now.

Cheers,

Simon