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

Re: [PATCH 1/3] merge-ort: copy a few small helper functions from merge-recursive.c

From
Elijah Newren <newren@gmail.com>
Date
Dec 16, 2020, 19:20 UTC
Message-ID
<CABPp-BG+_4Dv_+HNgQxW8KNe1q04NwuhRpExeOuc=wLeunsj_w@mail.gmail.com>
In-Reply-To
<xmqqim914pfs.fsf@gitster.c.googlers.com>
On Wed, Dec 16, 2020 at 9:43 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 50 quoted lines
>
> Derrick Stolee <stolee@gmail.com> writes:
>
> > On 12/15/2020 12:53 PM, Elijah Newren via GitGitGadget wrote:
> >> From: Elijah Newren <newren@gmail.com>
> >>
> >> In a subsequent commit, we will implement the traditional recursiveness
> >> that gave merge-recursive its name, namely merging non-unique
> >> merge-bases to come up with a single virtual merge base.  Copy a few
> >> helper functions from merge-recursive.c that we will use in the
> >> implementation.
> >
> > I'm sure these are copies, but...
> >
> >> +static struct commit_list *reverse_commit_list(struct commit_list *list)
> >> +{
> >> +    struct commit_list *next = NULL, *current, *backup;
> >> +    for (current = list; current; current = backup) {
> >> +            backup = current->next;
> >> +            current->next = next;
> >> +            next = current;
> >> +    }
> >
> > The naming of 'next' seems backwards to me, since it is really
> > the "previous" node. Using something like 'previous' makes it
> > clear that you are reversing when you say
> >
> >       current->next = previous;
>
> Hmph.  I took "next" commit_list as "list is the original one, and
> next is the reversed list, the next generation of what we received".
>
> Calling it "previous" feels even more backwards when you view among
> three "struct commit_list *" pointers, one (the one that holds the
> eventual return value) is primarily used to denote the resulting
> list itself, and the other two are used to point individual elements
> on the original list.
>
> I wonder if a slightly different codeflow may be easier to follow
>
>         struct commit_list *result = NULL;
>         while (list) {
>                 struct commit_list *next = list->next;
>                 list->next = result;
>                 result = list;
>                 list = next;
>         }
>         return result;
>
> if we were to try improving this for readability?

Looks like Felipe also came up with the same version you did (modulo the temporary variable name).

> I dunno if it matters too much, though.

Yeah, reverse_commit_list() has been unchanged in merge-recursive.c since its introduction in August of 2006. The function's purpose seems obvious from its name, so no one ever needs to look at or modify the implementation. I'm certain I'll never touch it again. So, I personally don't care what the particular implementation is, and I'm happy to take whatever reviewers prefer here.

Since we have three people weighing in with opinions though -- and on a point that's irrelevant to me -- do you want to make the call here Junio?

Otherwise I'll just leave it as-is and not update further.
Previous: Felipe ContrerasNext: Junio C Hamano
Message 14 of 37 in “merge-ort: implement recursive merges”
  1. 0/3 merge-ort: implement recursive mergesElijah Newren via GitGitGadget, Dec 15, 2020
  2. 3/3 merge-ort: implement merge_incore_recursive()Elijah Newren via GitGitGadget, Dec 15, 2020
  3. Junio C HamanoDec 16, 2020
  4. Elijah NewrenDec 16, 2020
  5. Elijah NewrenDec 16, 2020
  6. 2/3 merge-ort: make clear_internal_opts() aware of partial clearingElijah Newren via GitGitGadget, Dec 15, 2020
  7. 1/3 merge-ort: copy a few small helper functions from merge-recursive.cElijah Newren via GitGitGadget, Dec 15, 2020
  8. Junio C HamanoDec 16, 2020
  9. Johannes SchindelinDec 16, 2020
  10. Elijah NewrenDec 16, 2020
  11. Derrick StoleeDec 16, 2020
  12. Junio C HamanoDec 16, 2020
  13. Felipe ContrerasDec 16, 2020
  14. Elijah NewrenDec 16, 2020
  15. Junio C HamanoDec 16, 2020
  16. Felipe ContrerasDec 16, 2020
  17. Elijah NewrenDec 16, 2020
  18. 0/3 merge-ort: implement recursive mergesElijah Newren via GitGitGadget, Dec 16, 2020
  19. 2/3 merge-ort: make clear_internal_opts() aware of partial clearingElijah Newren via GitGitGadget, Dec 16, 2020
  20. 3/3 merge-ort: implement merge_incore_recursive()Elijah Newren via GitGitGadget, Dec 16, 2020
  21. Junio C HamanoDec 16, 2020
  22. Elijah NewrenDec 16, 2020
  23. 1/3 merge-ort: copy a few small helper functions from merge-recursive.cElijah Newren via GitGitGadget, Dec 16, 2020
  24. 0/3 merge-ort: implement recursive mergesElijah Newren via GitGitGadget, Dec 16, 2020
  25. 1/3 merge-ort: copy a few small helper functions from merge-recursive.cElijah Newren via GitGitGadget, Dec 16, 2020
  26. 2/3 merge-ort: make clear_internal_opts() aware of partial clearingElijah Newren via GitGitGadget, Dec 16, 2020
  27. 3/3 merge-ort: implement merge_incore_recursive()Elijah Newren via GitGitGadget, Dec 16, 2020
  28. 0/3 merge-ort: implement recursive mergesElijah Newren via GitGitGadget, Dec 16, 2020
  29. 1/3 merge-ort: copy a few small helper functions from merge-recursive.cElijah Newren via GitGitGadget, Dec 16, 2020
  30. 2/3 merge-ort: make clear_internal_opts() aware of partial clearingElijah Newren via GitGitGadget, Dec 16, 2020
  31. 3/3 merge-ort: implement merge_incore_recursive()Elijah Newren via GitGitGadget, Dec 16, 2020
  32. 0/4 merge-ort: implement recursive mergesElijah Newren via GitGitGadget, Dec 16, 2020
  33. 1/4 commit: move reverse_commit_list() from merge-recursiveElijah Newren via GitGitGadget, Dec 16, 2020
  34. Derrick StoleeDec 17, 2020
  35. 2/4 merge-ort: copy a few small helper functions from merge-recursive.cElijah Newren via GitGitGadget, Dec 16, 2020
  36. 3/4 merge-ort: make clear_internal_opts() aware of partial clearingElijah Newren via GitGitGadget, Dec 16, 2020
  37. 4/4 merge-ort: implement merge_incore_recursive()Elijah Newren via GitGitGadget, Dec 16, 2020

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.