git/xdiff
Jeff King 12a58f9014 xdiff: drop unused mmfile parameters from xdl_do_patience_diff()
The entry point to the patience-diff algorithm takes two mmfile_t
structs with the original file contents, but it doesn't actually do
anything useful with them. This is similar to the case recently cleaned
up in the histogram code via f1d019071e (xdiff: drop unused mmfile
parameters from xdl_do_histogram_diff(), 2022-08-19), but there's a bit
more subtlety going on.

We pass them into the recursive patience_diff(), which in turn passes
them into fill_hashmap(), which stuffs the pointers into a struct. But
the only thing which reads the struct fields is our recursion into
patience_diff()!

So it's unlikely that something like -Wunused-parameter could find this
case: it would have to detect the circular dependency caused by the
recursion (not to mention tracing across struct field assignments).

But once found, it's easy to have the compiler confirm what's going on:

  1. Drop the "file1" and "file2" fields from the hashmap struct
     definition. Remove the assignments in fill_hashmap(), and
     temporarily substitute NULL in the recursive call to
     patience_diff(). Compiling shows that no other code touched those
     fields.

  2. Now fill_hashmap() will trigger -Wunused-parameter. Drop "file1"
     and "file2" from its definition and callsite.

  3. Now patience_diff() will trigger -Wunused-parameter. Drop them
     there, too. One of the callsites is the recursion with our
     NULL values, so those temporary values go away.

  4. Now xdl_do_patience_diff() will trigger -Wunused-parameter. Drop
     them there. And we're done.

Suggested-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-08-20 14:14:55 -07:00
..
xdiff.h xdiff: introduce xdl_calloc 2022-07-08 09:34:30 -07:00
xdiffi.c xdiff: drop unused mmfile parameters from xdl_do_patience_diff() 2022-08-20 14:14:55 -07:00
xdiffi.h xdiff: drop unused mmfile parameters from xdl_do_patience_diff() 2022-08-20 14:14:55 -07:00
xemit.c tree-wide: apply equals-null.cocci 2022-05-02 09:50:37 -07:00
xemit.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xhistogram.c xdiff: drop unused mmfile parameters from xdl_do_histogram_diff() 2022-08-19 12:20:24 -07:00
xinclude.h xdiff: use git-compat-util 2019-04-12 13:34:17 +09:00
xmacros.h xdiff: introduce XDL_ALLOC_GROW() 2022-07-08 09:34:30 -07:00
xmerge.c xdiff: handle allocation failure when merging 2022-02-16 10:58:16 -08:00
xpatience.c xdiff: drop unused mmfile parameters from xdl_do_patience_diff() 2022-08-20 14:14:55 -07:00
xprepare.c xdiff: introduce XDL_ALLOC_GROW() 2022-07-08 09:34:30 -07:00
xprepare.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xtypes.h Replace Free Software Foundation address in license notices 2017-11-09 13:21:21 +09:00
xutils.c xdiff: introduce XDL_ALLOC_GROW() 2022-07-08 09:34:30 -07:00
xutils.h xdiff: introduce XDL_ALLOC_GROW() 2022-07-08 09:34:30 -07:00