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

Re: [PATCH] read-tree: Fix regression with creation of a new index file.

From
Stephen Boyd <bebarino@gmail.com>
Date
Aug 18, 2009, 03:37 UTC
Message-ID
<4A8A21E7.7070001@gmail.com>
In-Reply-To
<alpine.DEB.1.00.0908180018020.8306@pacific.mpi-cbg.de>
Johannes Schindelin wrote:
Show 18 quoted lines
> diff --git a/builtin-read-tree.c b/builtin-read-tree.c
> index 9c2d634..d649c56 100644
> --- a/builtin-read-tree.c
> +++ b/builtin-read-tree.c
> @@ -113,14 +113,14 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
>  	argc = parse_options(argc, argv, unused_prefix, read_tree_options,
>  			     read_tree_usage, 0);
>  
> -	if (read_cache_unmerged() && (opts.prefix || opts.merge))
> -		die("You need to resolve your current index first");
> -
>  	prefix_set = opts.prefix ? 1 : 0;
>  	if (1 < opts.merge + opts.reset + prefix_set)
>  		die("Which one? -m, --reset, or --prefix?");
>  	stage = opts.merge = (opts.reset || opts.merge || prefix_set);
>  
> +	if (opts.merge && (read_cache_unmerged() && !prefix_set && !opts.reset))
>   
This looks more compact but I think the !prefix_set check is wrong.

Yes, we want to do read_cache_unmerged() if we're doing some sort of merging operation. But we want to die() when either -m or --prefix is used. Therefore, die() if we're not doing a --reset. So we might as well just check that case and nothing else.

The original patch from Alexandre is correct, but if you want to avoid extra nesting I suppose you could do something like the patch below.

Thanks.
---
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 9c2d634..c6d5b49 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -113,14 +113,14 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        argc = parse_options(argc, argv, unused_prefix, read_tree_options,
                             read_tree_usage, 0);
 
-       if (read_cache_unmerged() && (opts.prefix || opts.merge))
-               die("You need to resolve your current index first");
-
        prefix_set = opts.prefix ? 1 : 0;
        if (1 < opts.merge + opts.reset + prefix_set)
                die("Which one? -m, --reset, or --prefix?");
        stage = opts.merge = (opts.reset || opts.merge || prefix_set);
 
+       if (opts.merge && read_cache_unmerged() && !opts.reset)
+               die("You need to resolve your current index first");
Previous: Johannes Schindelin
Message 3 of 3 in “read-tree: Fix regression with creation of a new index file.”
  1. read-tree: Fix regression with creation of a new index file.Alexandre Julliard, Aug 17, 2009
  2. Johannes SchindelinAug 17, 2009
  3. Stephen BoydAug 18, 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.