Re: [PATCH v2 1/1] branch: introduce --show-current display option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 11, 2018, 06:54 UTC
- Message-ID
- <xmqq4ldtgehs.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20181010205432.11990-2-daniels@umanovskis.se>
Daniels Umanovskis <daniels@umanovskis.se> writes:
Show 6 quoted lines
> +static void print_current_branch_name()
> +{
> + const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
> + const char *shortname;
> + if (refname == NULL || !strcmp(refname, "HEAD"))
> + return;Is it a normal situation to have refname==NULL, or is it something worth reporting as an error?
Without passing the &flag argument, I do not think there is a reliable way to ask resolve_ref_unsafe() if "HEAD" is a symbolic ref.
int flag;
const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flag);
const char *branchname; if (!refname)
die(...);
else if (!(flag & REF_ISSYMREF))
return; /* detached HEAD */
else if (skip_prefix(refname, "refs/heads/", &branchname))
puts(branchname);
else
die("HEAD (%s) points outside refs/heads/?", refname);or something like that?