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

Generalization of diff and merge

From
Martin von Zweigbergk <martinvonz@gmail.com>
Date
Nov 17, 2021, 07:45 UTC
Message-ID
<CANiSa6hKPO1toFu-3sM00zj_QbeFWJFE=aEZEjYoW7wq5rPhXQ@mail.gmail.com>
Hi,

Something I'm currently working on at work reminded me of an idea I had a while ago, which I thought may be useful to the Git project.

The idea is simply that diffs and merges can be viewed as special cases of generalized N-way diffs. This N-way diff function takes an arbitrary number of inputs and returns a list of matching and non-matching hunks, where the non-matching hunks have the same number of parts as there were number of inputs. To get a diff, you pass in two inputs and interpret the first part of non-matching hunks as the "before" side and the second part as "after" (assuming that's the order you passed them in, of course). Similarly, to get a normal 3-way merge, you pass in three inputs (base, left, and right) and interpret the parts of the non-matching hunks accordingly. See the tests in [1] for some examples.

One advantage of doing it this way is that the merge algorithm becomes consistent with the diff algorithm, so the user won't see conflicts where the conflicting hunks are in different places than they would appear in diff output. This is probably not much of a problem in practice.

Another advantage that I'm not sure matters in the Git project is that the generalization can help render conflicts from octopus merges.

Sorry if this is an old idea. The fact that there's `git diff --histogram` but no `git merge --histogram` made me think it's not. Or maybe there are simply good reasons to not do the generalization?

[1] https://github.com/martinvonz/jj/commit/987aecc749f82c55cb3481f79680552040f7cf13
Message 1 of 1 in “Generalization of diff and merge”
  1. Martin von ZweigbergkNov 17, 2021

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.