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

Re: [PATCH] gitweb: Make git_get_refs_list do work of git_get_references

From
Junio C Hamano <junkio@cox.net>
Date
Sep 17, 2006, 02:12 UTC
Message-ID
<7vejub8cms.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<864pv7tgmx.fsf@blue.stonehenge.com>
merlyn@stonehenge.com (Randal L. Schwartz) writes:
Show 16 quoted lines
>>>>>> "Junio" == Junio C Hamano <junkio@cox.net> writes:
>
> Junio> Jakub Narebski <jnareb@gmail.com> writes:
>>> Make git_get_refs_list do also work of git_get_references, to avoid
>>> calling git-peek-remote twice. It now returns either list of refs as
>>> before in scalar context, or references hash and list of refs in list
>>> context.
>
> Junio> I do not think we want to have too many functions that return
> Junio> different things depending on contexts.  Forcing callers to
> Junio> remember what the function does in which context is bad.
>
> That's even an inaccurate description, so an expert in Perl (I've
> known a few) would just scratch his head.
>
> You cannot ever ever return a list in a scalar context.  Ever.  Never ever.
That much I think I know.

The code I was complaining about tries to do something like this:

	sub that_sub {
        	...
                return wantarray ? (\@bar, \%foo) : \@bar;
	}

and it is not done for optimization purposes (i.e. "if the caller only wants one and we are returning \@bar then we do not have to compute \%foo which is a big win" is not why it does this wantarray business).

So the callers when interested in the sequence of things in 'bar' typically say:

	my $the_list = that_sub(...);
        for (@$the_list) {
        	...
	}
while other callers say:
	my ($the_hash, $the_list) = that_sub(...);
	... use %$the_hash and @$the_list as see fit ...

And I was saying that getting rid of the "return wantwarray ? :" business and write the first class of callers like this

	my ($the_list) = that_sub(...);
        for (@$the_list) {
        	...
	}
would be much less confusing.
Previous: Randal L. SchwartzNext: Randal L. Schwartz
Message 5 of 10 in “gitweb: Make git_get_refs_list do work of git_get_references”
  1. gitweb: Make git_get_refs_list do work of git_get_referencesJakub Narebski, Sep 17, 2006
  2. 1/2 gitweb: Always use git-peek-remote in git_get_referencesJakub Narebski, Sep 17, 2006
  3. Junio C HamanoSep 17, 2006
  4. Randal L. SchwartzSep 17, 2006
  5. Junio C HamanoSep 17, 2006
  6. Randal L. SchwartzSep 17, 2006
  7. Junio C HamanoSep 17, 2006
  8. Jakub NarebskiSep 17, 2006
  9. Jakub NarebskiSep 17, 2006
  10. Jakub NarebskiSep 17, 2006

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.