Re: [PATCH v6 1/5] branch: move --set-upstream-to behavior to dwim_and_setup_tracking()
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Jan 11, 2022, 20:03 UTC
- Message-ID
- <20220111200330.23366-1-jonathantanmy@google.com>
- In-Reply-To
- <kl6la6g2kwp5.fsf@chooglen-macbookpro.roam.corp.google.com>
Glen Choo <chooglen@google.com> writes:
Show 18 quoted lines
> >> @@ -401,7 +410,34 @@ void create_branch(struct repository *r,
> >>
> >> if ((commit = lookup_commit_reference(r, &oid)) == NULL)
> >> die(_("Not a valid branch point: '%s'."), start_name);
> >> - oidcpy(&oid, &commit->object.oid);
> >> + if (out_real_ref)
> >> + *out_real_ref = real_ref ? xstrdup(real_ref) : NULL;
> >
> > I think you can just write "*out_real_ref = real_ref; real_ref = NULL;"
> > here, and then not need to xstrdup.
>
> Hm, you are right. The xstrdup was added because the original function
> calls FREE_AND_NULL(real_ref) and then checks if real_ref is NULL. But
> after the refactor, real_ref is not referenced after the
> FREE_AND_NULL(real_ref), so that call can be removed.
>
> I intend to remove the xstrdup, though it will introduce a bit of noise
> because that block will no longer be moved wholesale.Ah, thanks for watching out for the diff. I think in this case, we'll be fine, since the xstrdup line is a new line ("xstrdup" only appears once in the diff, here).