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

Re: [PATCH 2/5] sequencer: always roll back lock in `do_recursive_merge()`

From
Jeff King <peff@peff.net>
Date
Feb 27, 2018, 21:44 UTC
Message-ID
<20180227214430.GC6899@sigill.intra.peff.net>
In-Reply-To
<5d657ac87d1e71fd95175faed2b591fa609b8f1c.1519763396.git.martin.agren@gmail.com>
On Tue, Feb 27, 2018 at 10:30:10PM +0100, Martin Ågren wrote:
Show 16 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index 90807c4559..e6bac4692a 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -465,8 +465,10 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
>  		fputs(o.obuf.buf, stdout);
>  	strbuf_release(&o.obuf);
>  	diff_warn_rename_limit("merge.renamelimit", o.needed_rename_limit, 0);
> -	if (clean < 0)
> +	if (clean < 0) {
> +		rollback_lock_file(&index_lock);
>  		return clean;
> +	}
>  
>  	if (active_cache_changed &&
>  	    write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
This addition is obviously correct.

I want to note one thing that confused me while reviewing. While looking to see if there were other returns, I noticed that the lines right near the end of your context are funny:

        if (active_cache_changed &&
              write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
                  /*
                   * TRANSLATORS: %s will be "revert", "cherry-pick" or
                   * "rebase -i".
                   */
                  return error(_("%s: Unable to write new index file"),
                          _(action_name(opts)));
          rollback_lock_file(&index_lock);

At first I thought that rollback was a noop, since write_locked_index() would always either commit or rollback. But it's needed for the case when we active_cache_changed isn't true.

So I think it's correct as-is, but I wonder if writing it as:
  if (!active_cache_changed)
	rollback_lock_file(&index_lock);
  else if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
	return error(...);

might be easier to follow. I'm OK with leaving it, too, but thought I'd mention it in case it confused other reviewers.

-Peff
Previous: Martin ÅgrenNext: Martin Ågren
Message 4 of 26 in “roll back locks in various code paths”
  1. 0/5 roll back locks in various code pathsMartin Ågren, Feb 27, 2018
  2. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 27, 2018
  3. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 27, 2018
  4. Jeff KingFeb 27, 2018
  5. Martin ÅgrenFeb 27, 2018
  6. Jeff KingFeb 27, 2018
  7. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 27, 2018
  8. Martin ÅgrenFeb 28, 2018
  9. 0/5 roll back locks in various code pathsMartin Ågren, Feb 28, 2018
  10. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 28, 2018
  11. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 28, 2018
  12. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 28, 2018
  13. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 28, 2018
  14. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 28, 2018
  15. Martin ÅgrenFeb 28, 2018
  16. Junio C HamanoFeb 28, 2018
  17. Martin ÅgrenMar 1, 2018
  18. Jeff KingMar 1, 2018
  19. Junio C HamanoMar 1, 2018
  20. Martin ÅgrenMar 1, 2018
  21. Jeff KingMar 2, 2018
  22. Jeff KingMar 1, 2018
  23. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 27, 2018
  24. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 27, 2018
  25. Jeff KingFeb 27, 2018
  26. Junio C HamanoFeb 27, 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.