Re: [PATCH 4/4] builtin/branch: strip refs/heads/ using skip_prefix
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Nov 19, 2017, 01:04 UTC
- Message-ID
- <CAPig+cRrJVhYMYfoFhSi+FOLv0X4or1-YV=M8_X10_d_Bbt3pA@mail.gmail.com>
- In-Reply-To
- <20171118172648.17918-5-kaartic.sivaraam@gmail.com>
On Sat, Nov 18, 2017 at 12:26 PM, Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:
Show 19 quoted lines
> Instead of hard-coding the offset strlen("refs/heads/") to skip
> the prefix "refs/heads/" use the skip_prefix() function which
> is more communicative and verifies that the string actually
> starts with that prefix.
>
> Though we don't check for the result of verification here as
> it's (almost) always the case that the string does start
> with "refs/heads", it's just better to avoid hard-coding and
> be more communicative.
>
> Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
> ---
> diff --git a/builtin/branch.c b/builtin/branch.c
> @@ -462,6 +462,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
> {
> struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
> struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
> + const char *prefix_free_oldref = NULL;
> + const char *prefix_free_newref = NULL;A bit of a mouthful. Perhaps name these 'oldname' and 'newname' or something?