From: Shawn O. Pearce Date: Mon, 01 Sep 2008 19:10:51 GMT Subject: Re: [PATCH] for-each-ref: `:short` format for `refname` Message-ID: <20080901191051.GD7482@spearce.org> In-Reply-To: <36ca99e90809011052s568fa6e4y89e56769f63806c1@mail.gmail.com> Bert Wesarg wrote: > IMHO the goal of this new format for refname should be, that it can be > used as an ref on the command line. This isn't given with my current > :short proposal (which I call :strip as of now), as Gábor showed. What > we need is the reverse of what happened with refnames given on the > command line to commands like checkout/merge/... The only thing that > comes near to this is this from refs.c: > > const char *ref_rev_parse_rules[] = { > "%.*s", > "refs/%.*s", > "refs/tags/%.*s", > "refs/heads/%.*s", > "refs/remotes/%.*s", > "refs/remotes/%.*s/HEAD", > NULL > }; > > Which doesn't look very useful, because every ref from for_each_ref > would match rule one. So we probably need to try the reverse of this > list. Yup. If you search the list backwards and extract the part of the ref that matches %.*s you'll get a name that other tools can find, and which is the shortest name possible. You can still get ambiguous names. Avoiding them requires going through all refs and building their short forms, then using the full ref name for any ref which had more than one name shorten to the same string. Ugly, but implementable, and probably something that should be considered. -- Shawn.