mv: factor out empty src_dir removal
commitd58a687705d3920464c786b4f7b837d620f8d8b1
authorJeff King <peff@peff.net>
Thu, 30 May 2024 06:45:21 +0000 (30 02:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 May 2024 15:55:29 +0000 (30 08:55 -0700)
tree56c54f8a62f0cd6519fe0295c4cab3558f351801
parentcc65e085e413c7b837e46169ff543c6c8bfcae1f
mv: factor out empty src_dir removal

This pulls the loop added by b6f51e3db9 (mv: cleanup empty
WORKING_DIRECTORY, 2022-08-09) into a sub-function. That reduces clutter
in cmd_mv() and makes it easier to see that the lifetime of the
a_src_dir strbuf is limited to this code (and thus its cleanup doesn't
need to go after the "out" label).

Another option would be to just declare the strbuf inside the loop,
since it is only used there. But this refactor retains the existing
property that we can reuse the allocated buffer for each iteration of
the loop. That optimization is probably overkill, but I think the
sub-function is more readable anyway, and then keeping the optimization
is basically free.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c