Re: [PATCHv2 6/7] builtin/describe.c: describe a blob
On Tue, Oct 31, 2017 at 5:18 PM, Stefan Beller <sbeller@google.com> wrote:
> When describing commits, we try to anchor them to tags or refs, as these
> are conceptually on a higher level than the commit. And if there is no ref
> or tag that matches exactly, we're out of luck. So we employ a heuristic
> to make up a name for the commit. These names are ambivalent, there might
I guess you meant s/ambivalent/ambiguous/ ?
Show 5 quoted lines
> be different tags or refs to anchor to, and there might be different
> path in the DAG to travel to arrive at the commit precisely.
>
> [1] https://stackoverflow.com/questions/223678/which-commit-has-this-blob
> Signed-off-by: Stefan Beller <sbeller@google.com>
Blank line before sign-off.
Show 20 quoted lines
> ---
> diff --git a/builtin/describe.c b/builtin/describe.c
> @@ -445,11 +495,16 @@ static void describe(const char *arg, int last_one)
>
> if (get_oid(arg, &oid))
> die(_("Not a valid object name %s"), arg);
> - cmit = lookup_commit_reference(&oid);
> - if (!cmit)
> - die(_("%s is not a valid '%s' object"), arg, commit_type);
> + cmit = lookup_commit_reference_gently(&oid, 1);
>
> - describe_commit(&oid, &sb);
> + if (cmit) {
> + describe_commit(&oid, &sb);
> + } else {
> + if (lookup_blob(&oid))
> + describe_blob(oid, &sb);
> + else
> + die(_("%s is neither a commit nor blob"), arg);
> + }Not at all worth a re-roll, but less nesting and a bit less noisy:
if (cmt)
describe_commit(...);
else if (lookup_blob(...))
describe_blob(...);
else
die(...);