threads / discuss / 61006

[Question] How to parse range-diff output

Subject: [Question] How to parse range-diff output

## tl;dr

4 messages between Feb 26, 2024 and Feb 29, 2024.

replies: 3people: 3as markdown or json

ZheNing Hu· Feb 26, 2024, 07:25 UTC · lore
Hi,

I am currently looking to implement a service that provides a version range comparison based on git range-diff. I can easily parse out commit pair headers like "3: 0bf6289 ! 3: a076e88 dev5," but I am unsure how to parse the details in the subsequent diff patch body.

It is not a standard diff output where one can parse out the filename from the diff header, It should be called a diff of diffs. We can see various headers with file names such as "@@ File1 (new)", "## File2 (new) ##", or "@@ File3: function3" in different formats. This is confusing. How should we correctly parse a range-diff patch, and do you have any good suggestions?

Thanks for any help. -- ZheNing Hu

Kristoffer Haugsbakk· Feb 26, 2024, 13:16 UTC · re: ZheNing Hu · lore

Re: [Question] How to parse range-diff output

On Mon, Feb 26, 2024, at 08:25, ZheNing Hu wrote:
Show 17 quoted lines
> Hi,
>
> I am currently looking to implement a service that provides a version
> range comparison based on git range-diff. I can easily parse out
> commit pair headers like "3: 0bf6289 ! 3: a076e88 dev5," but I am
> unsure how to parse the details in the subsequent diff patch body.
>
> It is not a standard diff output where one can parse out the filename
> from the diff header, It should be called a diff of diffs. We can see
> various headers with file names such as "@@ File1 (new)", "## File2
> (new) ##", or "@@ File3: function3" in different formats. This is
> confusing. How should we correctly parse a range-diff patch, and do
> you have any good suggestions?
>
> Thanks for any help.
> --
> ZheNing Hu
Hi

Note that “Output Stability” says that this output is not meant to be machine-readable. It’s for human consumption. It’s not textually stable.

So a new version of Git might break your implementation without warning.
-- 
Kristoffer Haugsbakk
Junio C Hamano· Feb 26, 2024, 16:16 UTC · re: Kristoffer Haugsbakk · lore

Re: [Question] How to parse range-diff output

"Kristoffer Haugsbakk" <code@khaugsbakk.name> writes:
Show 25 quoted lines
> On Mon, Feb 26, 2024, at 08:25, ZheNing Hu wrote:
>> Hi,
>>
>> I am currently looking to implement a service that provides a version
>> range comparison based on git range-diff. I can easily parse out
>> commit pair headers like "3: 0bf6289 ! 3: a076e88 dev5," but I am
>> unsure how to parse the details in the subsequent diff patch body.
>>
>> It is not a standard diff output where one can parse out the filename
>> from the diff header, It should be called a diff of diffs. We can see
>> various headers with file names such as "@@ File1 (new)", "## File2
>> (new) ##", or "@@ File3: function3" in different formats. This is
>> confusing. How should we correctly parse a range-diff patch, and do
>> you have any good suggestions?
>>
>> Thanks for any help.
>> --
>> ZheNing Hu
>
> Hi
>
> Note that “Output Stability” says that this output is not meant to be
> machine-readable. It’s for human consumption. It’s not textually stable.
>
> So a new version of Git might break your implementation without warning.
Good point.

In fact, those "##" things came long after the command was introduced for exactly the purpose of helping human users to locate which part of a "diff" the "diff of diff" is talking about, and the output from the command has been unstable for the exact reason.

ZheNing Hu· Feb 29, 2024, 11:00 UTC · re: Kristoffer Haugsbakk · lore

Re: [Question] How to parse range-diff output

Kristoffer Haugsbakk <code@khaugsbakk.name> 于2024年2月26日周一 21:16写道:
Show 27 quoted lines
>
> On Mon, Feb 26, 2024, at 08:25, ZheNing Hu wrote:
> > Hi,
> >
> > I am currently looking to implement a service that provides a version
> > range comparison based on git range-diff. I can easily parse out
> > commit pair headers like "3: 0bf6289 ! 3: a076e88 dev5," but I am
> > unsure how to parse the details in the subsequent diff patch body.
> >
> > It is not a standard diff output where one can parse out the filename
> > from the diff header, It should be called a diff of diffs. We can see
> > various headers with file names such as "@@ File1 (new)", "## File2
> > (new) ##", or "@@ File3: function3" in different formats. This is
> > confusing. How should we correctly parse a range-diff patch, and do
> > you have any good suggestions?
> >
> > Thanks for any help.
> > --
> > ZheNing Hu
>
> Hi
>
> Note that “Output Stability” says that this output is not meant to be
> machine-readable. It’s for human consumption. It’s not textually stable.
>
> So a new version of Git might break your implementation without warning.
>

It is very regrettable that some crucial metadata from the range-diff patch cannot be extracted. I can only hope that future range-diff will have the capability of being machine-readable. Thank you!

> --
> Kristoffer Haugsbakk

← back to recent threads