git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/4] name-ref: factor out name shortening logic from name_ref()

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jul 8, 2013, 08:52 UTC
Message-ID
<51DA7DBD.7070405@alum.mit.edu>
In-Reply-To
<1373236424-25617-2-git-send-email-gitster@pobox.com>
On 07/08/2013 12:33 AM, Junio C Hamano wrote:
Show 26 quoted lines
> The logic will be used in a new codepath for showing exact matches.
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/name-rev.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/builtin/name-rev.c b/builtin/name-rev.c
> index 87d4854..1234ebb 100644
> --- a/builtin/name-rev.c
> +++ b/builtin/name-rev.c
> @@ -96,6 +96,17 @@ static int subpath_matches(const char *path, const char *filter)
>  	return -1;
>  }
>  
> +static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
> +{
> +	if (shorten_unambiguous)
> +		refname = shorten_unambiguous_ref(refname, 0);
> +	else if (!prefixcmp(refname, "refs/heads/"))
> +		refname = refname + 11;
> +	else if (!prefixcmp(refname, "refs/"))
> +		refname = refname + 5;
> +	return refname;
> +}
> +

In my opinion this would be a tad clearer if each of the branches of the "if" returned the value directly rather than setting refname and relying on the "return" statement that follows. But it's probably a matter of taste.

Show 19 quoted lines
>  struct name_ref_data {
>  	int tags_only;
>  	int name_only;
> @@ -134,13 +145,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
>  	if (o && o->type == OBJ_COMMIT) {
>  		struct commit *commit = (struct commit *)o;
>  
> -		if (can_abbreviate_output)
> -			path = shorten_unambiguous_ref(path, 0);
> -		else if (!prefixcmp(path, "refs/heads/"))
> -			path = path + 11;
> -		else if (!prefixcmp(path, "refs/"))
> -			path = path + 5;
> -
> +		path = name_ref_abbrev(path, can_abbreviate_output);
>  		name_rev(commit, xstrdup(path), 0, 0, deref);
>  	}
>  	return 0;
> 
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 20 in “Make "git name-rev $(git rev-parse v1.8.3)" work”
  1. 0/4 Make "git name-rev $(git rev-parse v1.8.3)" workJunio C Hamano, Jul 7, 2013
  2. 1/4 name-ref: factor out name shortening logic from name_ref()Junio C Hamano, Jul 7, 2013
  3. Michael HaggertyJul 8, 2013
  4. Junio C HamanoJul 8, 2013
  5. 2/4 name-rev: allow converting the exact object name at the tip of a refJunio C Hamano, Jul 7, 2013
  6. Ramkumar RamachandraJul 8, 2013
  7. Junio C HamanoJul 8, 2013
  8. 3/4 describe: use argv-arrayJunio C Hamano, Jul 7, 2013
  9. Jeff KingJul 9, 2013
  10. Junio C HamanoJul 9, 2013
  11. Junio C HamanoJul 9, 2013
  12. Jeff KingJul 9, 2013
  13. 4/4 describe/name-rev: tell name-rev to peel the incoming object to commit firstJunio C Hamano, Jul 7, 2013
  14. Ramkumar RamachandraJul 8, 2013
  15. Jeff KingJul 9, 2013
  16. Jeff KingJul 9, 2013
  17. Junio C HamanoJul 9, 2013
  18. Jeff KingJul 9, 2013
  19. Junio C HamanoJul 9, 2013
  20. Ramkumar RamachandraJul 9, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.