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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Wed, Aug 18, 2010 at 12:55 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
<snip>
>> 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().

> 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).

> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]