git/list[1] front-page[2] threads[3] people[4] search[5] about
 

A case where diff.colorMoved=plain is more sensible than diff.colorMoved=zebra & others

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 6, 2018, 13:54 UTC
Message-ID
<87zhtiyd45.fsf@evledraar.gmail.com>

Let's ignore how bad this patch is for git.git, and just focus on how diff.colorMoved treats it:

    diff --git a/builtin/add.c b/builtin/add.c
    index f65c172299..d1155322ef 100644
    --- a/builtin/add.c
    +++ b/builtin/add.c
    @@ -6,5 +6,3 @@
     #include "cache.h"
    -#include "config.h"
     #include "builtin.h"
    -#include "lockfile.h"
     #include "dir.h"
    diff --git a/builtin/am.c b/builtin/am.c
    index 8f27f3375b..eded15aa8a 100644
    --- a/builtin/am.c
    +++ b/builtin/am.c
    @@ -6,3 +6,2 @@
     #include "cache.h"
    -#include "config.h"
     #include "builtin.h"
    diff --git a/builtin/blame.c b/builtin/blame.c
    index 06a7163ffe..44a754f190 100644
    --- a/builtin/blame.c
    +++ b/builtin/blame.c
    @@ -8,3 +8,2 @@
     #include "cache.h"
    -#include "config.h"
     #include "color.h"
    diff --git a/cache.h b/cache.h
    index ca36b44ee0..ea8d60b94a 100644
    --- a/cache.h
    +++ b/cache.h
    @@ -4,2 +4,4 @@
     #include "git-compat-util.h"
    +#include "config.h"
    +#include "new.h"
     #include "strbuf.h"

This is a common thing that's useful to have highlighted, e.g. we move includes of config.h to some common file, so I want to se all the deleted config.h lines as moved into the cache.h line, and then the "lockfile.h" I removed while I was at it plain remove, and the new "new.h" plain added.

Exactly that is what you get with diff.colorMoved=plain, but the default of diff.colorMoved=zebra gets confused by this and highlights no moves at all, same or "blocks" and "dimmed-zebra".

So at first I thought this had something to do with the many->one detection, but it seems to be simpler, we just don't detect a move of 1-line with anything but plain, e.g. this works as expected in all modes and detects the many->one:

    diff --git a/builtin/add.c b/builtin/add.c
    index f65c172299..f4fda75890 100644
    --- a/builtin/add.c
    +++ b/builtin/add.c
    @@ -5,4 +5,2 @@
      */
    -#include "cache.h"
    -#include "config.h"
     #include "builtin.h"
    diff --git a/builtin/branch.c b/builtin/branch.c
    index 0c55f7f065..52e39924d3 100644
    --- a/builtin/branch.c
    +++ b/builtin/branch.c
    @@ -7,4 +7,2 @@
    -#include "cache.h"
    -#include "config.h"
     #include "color.h"
    diff --git a/cache.h b/cache.h
    index ca36b44ee0..d4146dbf8a 100644
    --- a/cache.h
    +++ b/cache.h
    @@ -3,2 +3,4 @@
    +#include "cache.h"
    +#include "config.h"
     #include "git-compat-util.h"

So is there some "must be at least two consecutive lines" condition for not-plain, or is something else going on here?

Next: Phillip Wood
Message 1 of 5 in “A case where diff.colorMoved=plain is more sensible than diff.colorMoved=zebra & others”
  1. Ævar Arnfjörð BjarmasonDec 6, 2018
  2. Phillip WoodDec 6, 2018
  3. Stefan BellerDec 6, 2018
  4. Phillip WoodDec 10, 2018
  5. Stefan BellerDec 11, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.