Re: [PATCH v2 1/1] branch: introduce --show-current display option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniels Umanovskis <daniels@xxxxxxxxxxxxx> writes:

> +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?



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux