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

Re: [PATCH] builtin-revert.c: Make use of merge_recursive()

From
Stephan Beyer <s-beyer@gmx.net>
Date
Aug 11, 2008, 19:01 UTC
Message-ID
<20080811190123.GA14413@leksak.fem-net>
In-Reply-To
<alpine.DEB.1.00.0808111737270.24820@pacific.mpi-cbg.de.mpi-cbg.de>
Hi,
Johannes Schindelin wrote:
Show 16 quoted lines
> Hi,
> 
> On Mon, 11 Aug 2008, Stephan Beyer wrote:
> 
> > diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
> > index 09aa830..d8bd21f 100644
> > --- a/builtin-merge-recursive.c
> > +++ b/builtin-merge-recursive.c
> > @@ -1327,7 +1327,7 @@ static const char *better_branch_name(const char *branch)
> >  	return name ? name : branch;
> >  }
> >  
> > -static struct commit *get_ref(const char *ref)
> > +struct commit *get_ref(const char *ref)
> 
> The name get_ref() is way too generic to be non-static.
That's right.
> But I have a hunch that peel_to_type() does a lot of what we want here,
> if not all of it.

get_ref() has a big advantage over peel_to_type(): it can handle trees, via "virtual commits" (make_virtual_commit()). If you wonder where we need to handle trees on cherry-pick/revert: With the -n (no commit) option you are allowed to have a dirty index. So the recursive merge is not done using the HEAD commit but using the uncommitted tree of the index.

Well, a good alternative could be to just make the really cool make_virtual_commit() function non-static. The name could be generic enough. Is it? :-) Or perhaps: make_virtual_commit_from_tree().

Btw I also need get_ref() (or make_virtual_commit()) for threeway fallback of the sequencer "patch -3" instruction ("git am -3"). ;)

Show 7 quoted lines
> > +	h1 = get_ref(head_sha1);
> > +	h2 = get_ref(next_sha1);
> > +
> > +	index_fd = hold_locked_index(lock, 1);
> > +	clean = merge_recursive(h1, h2, head_name, next_name, ca, &result);
> 
> h1 and h2 are not expressive.  head_commit and next_commit would be.

This is also quite true. Those names, also "ca", were taken from cmd_merge_recursive(). (This is no excuse, just an explanation.)

> Rest looks good to me -- even if I had to spend too much time (therefore 
> being not really thorough in the end) verifying that merge_recursive() 
> does not lock the index itself,

I can't help here. Miklos has the same change in patch v2/2 and I wonder if you really expect that I don't test my patches, because a double lock wouldn't have worked.

> and that GITHEAD_* definitions are not necessary anymore, since merge_recursive()
> takes the arguments directly;

Ok, I hoped that would've been clear by using head_name/next_name directly in the merge_recursive() arguments, but nevertheless thanks for your comment, ...because: using get_ref() the GITHEAD_* definitions *are* still needed, because it takes the GITHEAD_* name for the virtual commits...

Under this additional circumstance, I really tend to make make_virtual_commit() non-static.

Kind regards,
  Stephan
-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
Previous: Johannes SchindelinNext: Miklos Vajna
Message 15 of 38 in “Avoid run_command() for recursive in builtin-merge”
  1. 0/2 Avoid run_command() for recursive in builtin-mergeMiklos Vajna, Aug 10, 2008
  2. 1/2 merge-recursive: prepare merge_recursive() to be called from builtinsMiklos Vajna, Aug 10, 2008
  3. 2/2 builtin-merge: avoid run_command_v_opt() for recursiveMiklos Vajna, Aug 10, 2008
  4. Junio C HamanoAug 11, 2008
  5. Miklos VajnaAug 11, 2008
  6. Junio C HamanoAug 11, 2008
  7. Miklos VajnaAug 11, 2008
  8. Add a new test to ensure merging a submodule is handled properly.Miklos Vajna, Aug 11, 2008
  9. Stephan BeyerAug 11, 2008
  10. Miklos VajnaAug 11, 2008
  11. Junio C HamanoAug 11, 2008
  12. Stephan BeyerAug 11, 2008
  13. builtin-revert.c: Make use of merge_recursive()Stephan Beyer, Aug 11, 2008
  14. Johannes SchindelinAug 11, 2008
  15. Stephan BeyerAug 11, 2008
  16. Miklos VajnaAug 11, 2008
  17. builtin-revert: Make use of merge_recursive()Stephan Beyer, Aug 11, 2008
  18. Stephan BeyerAug 11, 2008
  19. Junio C HamanoAug 11, 2008
  20. Junio C HamanoAug 11, 2008
  21. Stephan BeyerAug 11, 2008
  22. Junio C HamanoAug 11, 2008
  23. Split out merge_recursive() to merge-recursive.cMiklos Vajna, Aug 12, 2008
  24. Stephan BeyerAug 12, 2008
  25. Miklos VajnaAug 12, 2008
  26. merge-recursive.c: Add more generic merge_recursive_generic()Stephan Beyer, Aug 12, 2008
  27. Make builtin-revert.c use merge_recursive_generic()Stephan Beyer, Aug 12, 2008
  28. Miklos VajnaAug 12, 2008
  29. Stephan BeyerAug 13, 2008
  30. Miklos VajnaAug 13, 2008
  31. Daniel BarkalowAug 13, 2008
  32. Stephan BeyerAug 13, 2008
  33. Daniel BarkalowAug 13, 2008
  34. Junio C HamanoAug 13, 2008
  35. Stephan BeyerAug 13, 2008
  36. Daniel BarkalowAug 13, 2008
  37. Junio C HamanoAug 13, 2008
  38. Junio C HamanoAug 14, 2008

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.