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

Re: [EGIT PATCH 3/6] Add a method to get refs by object Id

From
Shawn O. Pearce <spearce@spearce.org>
Date
Oct 6, 2008, 22:43 UTC
Message-ID
<20081006224348.GB13687@spearce.org>
In-Reply-To
<200810070037.53841.robin.rosenberg@dewire.com>
Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
Show 12 quoted lines
> måndagen den 6 oktober 2008 10.15.54 skrev Shawn O. Pearce:
> > Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> > >  
> > >  	/**
> > > +	 * @return a map with all objects referenced by a peeled ref.
> > > +	 */
> > > +	public Map<AnyObjectId, List<Ref>> getAllRefsByPeeledObjectId() {
> > 
> > Do we really want to promise List here?  Can we make it just
> > Collection instead?
>
> Sure. Our promise is actually slightly better, it is Set, but Java doesn't have a suitable class for that.
java.util.Set?  java.util.HashSet?
What am I missing?
 
Show 11 quoted lines
> > > +		for (Map.Entry<String,Ref> e : allRefs.entrySet()) {
> > > +			Ref ref = e.getValue();
> > 
> > I think this is cleaner:
> > 
> > 	for (Ref ref : allRefs.values()) {
> > 
> > as you never use the key.
>
> Yes. I was thinking it might be less efficient, but the JDK implementation looks quite well optimized in 1.6 at least
> so values() is slightly faster.
I wasn't concerned about performance, I was going for readability.
This loop is probably not performance critical as its done once
early when the PlotWalk starts.  I just found that grabbing the
entrySet when all you care about is the values was odd.
 
Show 15 quoted lines
> > 	List<Ref> nl = Collections.singletonList(ref);
> > 	List<Ref> ol = ret.put(target, nl);
> > 	if (ol != null) {
> > 		if (ol.size() == 1) {
> > 			nl = new ArrayList<Ref>(2);
> > 			nl.add(ol.get(0));
> > 			nl.add(ref);
> > 			ret.put(target, nl);
> > 		} else {
> > 			ol.add(ref)
> > 			ret.put(target, ol);
> > 		}
> > 	}
> 
> ok, I guess one just has has to include the comment on why for the casual reader. 

I'm probably too used to this pattern of "put, then test" because I use it a lot when the odds of put returning null are very high. Its an odd idiom. I think most developers wouldn't write it. So I guess a comment of some sort is probably a good idea if you chose to use this mess. ;-)

-- 
Shawn.
Previous: Robin RosenbergNext: Shawn O. Pearce
Message 13 of 14 in “(unknown)”
  1. Robin RosenbergOct 5, 2008
  2. 1/6 Keep original ref name when reading refsRobin Rosenberg, Oct 5, 2008
  3. 2/6 Peel annotated tags when getting all refsRobin Rosenberg, Oct 5, 2008
  4. 3/6 Add a method to get refs by object IdRobin Rosenberg, Oct 5, 2008
  5. 4/6 Add tags to the graphical history display.Robin Rosenberg, Oct 5, 2008
  6. 5/6 Add decorate option to log programRobin Rosenberg, Oct 5, 2008
  7. 6/6 Comment the getId method and hint for copy to actually get an ObjectIdRobin Rosenberg, Oct 5, 2008
  8. Shawn O. PearceOct 6, 2008
  9. Robin RosenbergOct 6, 2008
  10. Shawn O. PearceOct 6, 2008
  11. Shawn O. PearceOct 6, 2008
  12. Robin RosenbergOct 6, 2008
  13. Shawn O. PearceOct 6, 2008
  14. Shawn O. PearceOct 6, 2008

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.