All of lore.kernel.org
 help / color / mirror / Atom feed
* "git diff" surprising default output
@ 2023-03-01 18:25 Sergey Organov
  2023-03-01 19:40 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Sergey Organov @ 2023-03-01 18:25 UTC (permalink / raw)
  To: git

Hello,

By default, 'git diff' produces an output that is often rather
surprising and difficult to grok, here is a simple example:

$ git diff --no-index -- f0.txt f1.txt
diff --git a/f0.txt b/f1.txt
index 3af00a929..35478f7bd 100644
--- a/f0.txt
+++ b/f1.txt
@@ -3,9 +3,6 @@
 #endif
 #if CANOPEN > 0
     IMD_CANOPEN,
-#endif
-#if MDL_LASER > 0
-    IMD_LASER,
 #endif
     IMD_AUTO,
     IMD_NONE,

I figured the offender is --indent-heuristic that is described in the
manual as:

      Enable the heuristic that shifts diff hunk boundaries to make
      patches easier to read. This is the default.

but apparently rather makes patches harder to read, at least at some
conditions. Turning it off helps to get the expected result:

$ git diff --no-index --no-indent-heuristic -- f0.txt f1.txt
diff --git a/f0.txt b/f1.txt
index 3af00a929..35478f7bd 100644
--- a/f0.txt
+++ b/f1.txt
@@ -4,9 +4,6 @@
 #if CANOPEN > 0
     IMD_CANOPEN,
 #endif
-#if MDL_LASER > 0
-    IMD_LASER,
-#endif
     IMD_AUTO,
     IMD_NONE,
     IMD_COUNT


Changing --diff-algorithm doesn't change the outcome.

So the questions are:

- Is there an example of an advantage the option has?

- Is it possible to flip the default?

Thanks,
-- Sergey Organov

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: "git diff" surprising default output
  2023-03-01 18:25 "git diff" surprising default output Sergey Organov
@ 2023-03-01 19:40 ` Junio C Hamano
  2023-03-01 20:28   ` Sergey Organov
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2023-03-01 19:40 UTC (permalink / raw)
  To: Sergey Organov; +Cc: git, Michael Haggerty

Sergey Organov <sorganov@gmail.com> writes:

> I figured the offender is --indent-heuristic that is described in the
> manual as:
>
>       Enable the heuristic that shifts diff hunk boundaries to make
>       patches easier to read. This is the default.
>
> but apparently rather makes patches harder to read, at least at some
> conditions. Turning it off helps to get the expected result:

As a heuristic, it is not surprising that it has some corner cases
where it does not shine.  I think the version that was eventually
merged starts here

  https://lore.kernel.org/git/cover.1473068229.git.mhagger@alum.mit.edu/

and we should be able to find a few links to the original
observation that motivated the change, e.g.

  https://public-inbox.org/git/cover.1470259583.git.mhagger@alum.mit.edu/



Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: "git diff" surprising default output
  2023-03-01 19:40 ` Junio C Hamano
@ 2023-03-01 20:28   ` Sergey Organov
  0 siblings, 0 replies; 3+ messages in thread
From: Sergey Organov @ 2023-03-01 20:28 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Michael Haggerty

Junio C Hamano <gitster@pobox.com> writes:

> Sergey Organov <sorganov@gmail.com> writes:
>
>> I figured the offender is --indent-heuristic that is described in the
>> manual as:
>>
>>       Enable the heuristic that shifts diff hunk boundaries to make
>>       patches easier to read. This is the default.
>>
>> but apparently rather makes patches harder to read, at least at some
>> conditions. Turning it off helps to get the expected result:
>
> As a heuristic, it is not surprising that it has some corner cases
> where it does not shine.  I think the version that was eventually
> merged starts here
>
>   https://lore.kernel.org/git/cover.1473068229.git.mhagger@alum.mit.edu/
>
> and we should be able to find a few links to the original
> observation that motivated the change, e.g.
>
>   https://public-inbox.org/git/cover.1470259583.git.mhagger@alum.mit.edu/

Thanks a lot for the references!

From what I briefly read there it apparently follows that it'd shine at
regular C code, yet won't shine at preprocessor directives that are
usually out of regular alignment.

It'd be nice to improve this, but I'm not sure it's a simple thing to
fix, or even at all possible, though maybe it'd help to somehow favoring
chunks that start and end at the same alignment?

Or maybe it's just plain bug in the implementation?

Thanks,
-- Sergey Organov

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-01 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 18:25 "git diff" surprising default output Sergey Organov
2023-03-01 19:40 ` Junio C Hamano
2023-03-01 20:28   ` Sergey Organov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.