remote: drop const return of tracking_for_push_dest()

The string returned from tracking_for_push_dest() comes from
apply_refspec(), and thus is always an allocated string (or NULL). We
should return a non-const pointer so that the caller knows that
ownership of the string is being transferred.

This goes back to the function's origin in e291c75a95 (remote.c: add
branch_get_push, 2015-05-21). It never really mattered because our
return is just forwarded through branch_get_push_1(), which returns a
const string as part of an intentionally hacky memory management scheme
(see that commit for details).

As the first step of untangling that hackery, let's drop the extra const
from this helper function (and from the variables that store its
result). There should be no functional change (yet).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2026-01-19 00:20:26 -05:00 committed by Junio C Hamano
parent 9500b2131d
commit 782a719e99

View File

@ -1876,9 +1876,9 @@ const char *branch_get_upstream(struct branch *branch, struct strbuf *err)
return branch->merge[0]->dst;
}
static const char *tracking_for_push_dest(struct remote *remote,
const char *refname,
struct strbuf *err)
static char *tracking_for_push_dest(struct remote *remote,
const char *refname,
struct strbuf *err)
{
char *ret;
@ -1906,7 +1906,7 @@ static const char *branch_get_push_1(struct repository *repo,
if (remote->push.nr) {
char *dst;
const char *ret;
char *ret;
dst = apply_refspecs(&remote->push, branch->refname);
if (!dst)
@ -1936,7 +1936,8 @@ static const char *branch_get_push_1(struct repository *repo,
case PUSH_DEFAULT_UNSPECIFIED:
case PUSH_DEFAULT_SIMPLE:
{
const char *up, *cur;
const char *up;
char *cur;
up = branch_get_upstream(branch, err);
if (!up)