Re: [PATCH v7 15/31] merge-recursive: make !o->detect_rename codepath more obvious
- From
Stefan Beller <sbeller@google.com>
- Date
- Feb 2, 2018, 23:48 UTC
- Message-ID
- <CAGZ79kYynYT9NWEDYx46MQXP0sufsUPH045nk+7jJ+ND7QPiog@mail.gmail.com>
- In-Reply-To
- <20180130232533.25846-16-newren@gmail.com>
On Tue, Jan 30, 2018 at 3:25 PM, Elijah Newren <newren@gmail.com> wrote:
Show 35 quoted lines
> Previously, if !o->detect_rename then get_renames() would return an
> empty string_list, and then process_renames() would have nothing to
> iterate over. It seems more straightforward to simply avoid calling
> either function in that case.
>
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
> merge-recursive.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 1986af79a9..4e6d0c248e 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -1338,8 +1338,6 @@ static struct string_list *get_renames(struct merge_options *o,
> struct diff_options opts;
>
> renames = xcalloc(1, sizeof(struct string_list));
> - if (!o->detect_rename)
> - return renames;
>
> diff_setup(&opts);
> opts.flags.recursive = 1;
> @@ -1657,6 +1655,12 @@ static int handle_renames(struct merge_options *o,
> struct string_list *entries,
> struct rename_info *ri)
> {
> + ri->head_renames = NULL;
> + ri->merge_renames = NULL;
> +
> + if (!o->detect_rename)
> + return 1;
> +
> ri->head_renames = get_renames(o, head, common, head, merge, entries);
> ri->merge_renames = get_renames(o, merge, common, head, merge, entries);So this pulls the condition out and we just do not call get_renames. Makes sense as then we also do not allocate memory for the stringlists in get_renames
Reviewed-by: Stefan Beller <sbeller@google.com>