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

Re: [PATCH 3/8] git-merge-recursive-{ours,theirs}

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 30, 2009, 06:21 UTC
Message-ID
<7vvdgs1qip.fsf@alter.siamese.dyndns.org>
In-Reply-To
<32541b130911261405q6564d8f2o30b7d7fd6f708d05@mail.gmail.com>
Avery Pennarun <apenwarr@gmail.com> writes:
Show 10 quoted lines
>>  - I think we should avoid adding the extra argument to ll_merge_fn() by
>>   combining virtual_ancestor and favor into one "flags" parameter.  If
>>   you do so, we do not have to change the callsites again next time we
>>   need to add new optional features that needs only a few bits.
>>
>>   I vaguely recall that I did the counterpart of this patch that way
>>   exactly for the above reason, but it is more than a year ago, so maybe
>>   I didn't do it that way.
>
> You did do that, in fact,... <<rationale omitted>>

Think of the "flag" parameter as a mini "struct option". When you add a feature to a function at or near the leaf level of call chains that are potentially deep, you add one element to the option structure, and take advantage of the fact that existing callers put a sane default value in the new field, i.e. 0, by doing a "memset(&opt, 0, sizeof(opt))" already, so that the callsites that do not even have to know about the new feature will keep working the same old way without breakage. You saw this exact pattern in the [1/8] patch in your series to cram new "favor this side" information into an existing parameter.

As you mentioned, sometimes changing function signature is preferred to catch semantic differences at compilation time. The report given by the compiler of extra or missing parameter at the call site is a wonderful way to find out that you forgot to convert them to the new semantics of the function. This also helps when there is an in-flight patch that adds a new callsite to the function whose semantics you are changing. The semantic conflict is caught when compiling the result of a merge with a branch with such a patch. It is a trick worth knowing about.

The approach however cuts both ways. When you are adding an optional feature that is used only in a very few call sites, the semantic merge conflict resulting from such a function signature change is rarely worth it.

As long as you choose the default "no-op" value carefully enough so that existing callers will naturally use it without modification, the old code will work the way they did before the new optional feature was added. In other words, "let's implement this as purely an opt-in feature" is often preferrable over "let's force semantic conflict and compilation failure, just in case existing callsites may also want to trigger this new feature".

That is why [1/8] patch in your series uses 0 to mean "don't do the funny 'favor' trick, but just leave the conflicts there".

I've queued the series with minor fixes to 'pu' and pushed it out.
Previous: Avery PennarunNext: Avery Pennarun
Message 15 of 26 in “The return of -Xours, -Xtheirs, -Xsubtree=dir”
  1. 0/8 The return of -Xours, -Xtheirs, -Xsubtree=dirAvery Pennarun, Nov 26, 2009
  2. 1/8 git-merge-file --ours, --theirsAvery Pennarun, Nov 26, 2009
  3. 2/8 builtin-merge.c: call exclude_cmds() correctly.Avery Pennarun, Nov 26, 2009
  4. 3/8 git-merge-recursive-{ours,theirs}Avery Pennarun, Nov 26, 2009
  5. 4/8 Teach git-merge to pass -X<option> to the backend strategy moduleAvery Pennarun, Nov 26, 2009
  6. 5/8 Teach git-pull to pass -X<option> to git-mergeAvery Pennarun, Nov 26, 2009
  7. 6/8 Make "subtree" part more orthogonal to the rest of merge-recursive.Avery Pennarun, Nov 26, 2009
  8. 7/8 Extend merge-subtree tests to test -Xsubtree=dir.Avery Pennarun, Nov 26, 2009
  9. 8/8 Document that merge strategies can now take their own optionsAvery Pennarun, Nov 26, 2009
  10. Junio C HamanoNov 26, 2009
  11. Junio C HamanoNov 26, 2009
  12. Junio C HamanoNov 26, 2009
  13. Junio C HamanoNov 26, 2009
  14. Avery PennarunNov 26, 2009
  15. Junio C HamanoNov 30, 2009
  16. Avery PennarunNov 30, 2009
  17. Junio C HamanoNov 30, 2009
  18. Junio C HamanoNov 30, 2009
  19. Avery PennarunNov 30, 2009
  20. Junio C HamanoNov 26, 2009
  21. Avery PennarunNov 26, 2009
  22. Junio C HamanoNov 26, 2009
  23. Nanako ShiraishiNov 26, 2009
  24. Junio C HamanoNov 26, 2009
  25. Nanako ShiraishiNov 26, 2009
  26. Avery PennarunNov 26, 2009

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.