Daniels Umanovskis <dani...@umanovskis.se> 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?

Reply via email to