Re: [PATCH] stash: strip "refs/heads/" with skip_prefix
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 25, 2022, 07:13 UTC
- Message-ID
- <xmqq7dao1e5m.fsf@gitster.g>
- In-Reply-To
- <20220124205342.41450-1-chooglen@google.com>
Glen Choo <chooglen@google.com> writes:
> branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
> if (flags & REF_ISSYMREF)
> - branch_name = strrchr(branch_ref, '/') + 1;
> + skip_prefix(branch_ref, "refs/heads/", &branch_name);The branch_name variable is initialized to a constant string "(no branch)", so if HEAD is poihnting elsewhere (which you could do manually), skip_prefix() would fail and leave branch_name intact, which would give us the desirable outcome, too.
Looking good.