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

Re: [PATCH 1/2] merge-recursive: Workaround unused variable warning

From
Elijah Newren <newren@gmail.com>
Date
Aug 18, 2010, 22:02 UTC
Message-ID
<AANLkTik9mho7Pm5m=3dEbtMrH1r81Lc480i_z2_aHCxs@mail.gmail.com>
In-Reply-To
<7veidvagz8.fsf@alter.siamese.dyndns.org>
Hi,

On Wed, Aug 18, 2010 at 12:55 PM, Junio C Hamano <gitster@pobox.com> wrote: <snip>

Show 8 quoted lines
>> Yes, that sounds like a good idea.  The user would probably benefit
>> from knowing what happened.
>
> I'd agree.  This assert() is not about protecting new callers from making
> obvious programming error by passing wrong parameters, but about Elijah
> not being confident enough that the changes made to process_entry() with
> this series really covers all the cases so that only D/F cases are left
> unprocessed.

Actually, it is pretty clear right now that only D/F cases are left unprocessed, and in particular D->F cases. This is because process_entry() starts with unconditionally setting "entry->processed = 1" and only unsets it in the one 'if' block where we know that (!o_sha && !!a_sha != !!b_sha && string_list_has_string(&o->current_directory_set, path)).

So, I'd say it is more about programming errors, in particular ones where people modify the code to make process_entry() leave more cases unprocessed than what is currently possible without also making the necessary modifications to process_df_entry().

Show 5 quoted lines
> Another possibility is to move this assert() out of process_df_entry() and
> have it on the calling side.  Perhaps something like the attached.
>
> BTW, it is not so obvious if (!o_sha && !!a_sha != !!b_sha) is equivalent
> to "we are handling a D-F case".  Can you explain why?

It's not equivalent. Things are slightly confusing, because !<sha> can mean either (a) there is nothing at the given path, or (b) there is a directory at the given path. The only way to tell which of the two it means is to look up the path in o->current_directory_set.

A directory/file conflict ("D-F" in my shorthand) implies !!a_sha != !!b_sha (but not vice versa).

A directory/file conflict where the relevant path was a file in the merge-base ("F->D" in my shorthand) implies (o_sha && !!a_sha != !!b_sha). This case is handled just fine by process_entry() (if the file was unchanged, the correct resolution is to delete it, allowing paths beneath the directory of the same name to be handled by later process_entry() calls -- although this silently relies on the order of entries from get_unmerged() to be such that things do operate in this order. That seems to be correct for the cases I've seen).

A directory/file conflict where the path was a directory in the merge-base ("D->F" in my shorthand) implies (!o_sha && !!a_sha != !!b_sha). This is the case the process_df_entry needs to be invoked to handle. That function was explicitly written explicitly for that one case, hence the assert. The assert might be triggered, for example, if get_unmerged() were changed to return entries in a different order and someone decides to make the F->D case be unprocessed by process_entry() as well (and forgets to update process_df_entry).

Show 30 quoted lines
> diff --git a/merge-recursive.c b/merge-recursive.c
> index b0f055e..7bab728 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1208,9 +1208,8 @@ static int process_df_entry(struct merge_options *o,
>        const char *conf;
>        struct stat st;
>
> -       /* We currently only handle D->F cases */
> -       assert((!o_sha && a_sha && !b_sha) ||
> -              (!o_sha && !a_sha && b_sha));
> +       if (! ((!o_sha && a_sha && !b_sha) || (!o_sha && !a_sha && b_sha)))
> +               return 1; /* we don't handle non D-F cases */
>
>        entry->processed = 1;
>
> @@ -1321,6 +1320,12 @@ int merge_trees(struct merge_options *o,
>                                && !process_df_entry(o, path, e))
>                                clean = 0;
>                }
> +               for (i = 0; i < entries->nr; i++) {
> +                       struct stage_data *e = entries->items[i].util;
> +                       if (!e->processed)
> +                               die("Unprocessed path??? %s",
> +                                   entries->items[i].string);
> +               }
>
>                string_list_clear(re_merge, 0);
>                string_list_clear(re_head, 0);
>

Other than possible wording of the comment ("we only handle directory/file conflicts where the path was not a directory in the merge-base"? "we don't currently handle any other cases"? something else?), the patch looks good to me.

Elijah
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 9 in “Fix windows portability issues in en/d-f-conflict-fix series”
  1. 0/2 Fix windows portability issues in en/d-f-conflict-fix seriesElijah Newren, Aug 13, 2010
  2. 1/2 merge-recursive: Workaround unused variable warningElijah Newren, Aug 13, 2010
  3. Elijah NewrenAug 18, 2010
  4. Jonathan NiederAug 18, 2010
  5. Junio C HamanoAug 18, 2010
  6. Elijah NewrenAug 18, 2010
  7. Junio C HamanoAug 18, 2010
  8. Elijah NewrenAug 18, 2010
  9. 2/2 Mark tests that use symlinks as needing SYMLINKS prerequisiteElijah Newren, Aug 13, 2010

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.