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

Re: [PATCH] C version of git-count-objects

From
PHPeter Hagervall <hager@cs.umu.se>
Date
Apr 27, 2006, 20:51 UTC
Message-ID
<20060427205155.GA26856@brainysmurf.cs.umu.se>
In-Reply-To
<Pine.LNX.4.64.0604271257010.3701@g5.osdl.org>
On Thu, Apr 27, 2006 at 01:07:27PM -0700, Linus Torvalds wrote:
Show 19 quoted lines
> 
> 
> On Thu, 27 Apr 2006, Peter Hagervall wrote:
> > > 
> > > To avoid appending the filename to the path before each lstat() I'd 
> > > guess.
> > 
> > Yes, that's pretty much the reason.
> 
> It's a bad reason, though.
> 
> For one thing, it just doesn't work. You'll have to chdir() back, and you 
> can't use ".." in case the user has set up some symlink thing. So you end 
> up doing other really strange things.
> 
> You can do this much more efficiently with something like this:
> 
> 	const char *obj = git_object_directory();
> 	int len = strlen(obj);
<snip>
Show 14 quoted lines
> 				continue;
> 			strcpy(prefix + len, de->d_name);
> 			fd = open(prefix, O_RDONLY);
> 			.. check if it's ok, perhaps.. ?
> 			if (ok)
> 				nr++;
> 			close(fd);
> 		}
> 		return nr;
> 	}
> 
> and you're done. Efficient, and it's easy to add the endign to the 
> pathname, because you're passing in a buffer that is big enough, and 
> you're telling people where they should put their suffixes..

Thanks, I'll make a third stab at it tomorrow, if anyone is interested that is?

	Peter
Previous: Linus TorvaldsNext: Junio C Hamano
Message 9 of 12 in “C version of git-count-objects”
  1. C version of git-count-objectsPeter Hagervall, Apr 27, 2006
  2. Morten WelinderApr 27, 2006
  3. Nicolas PitreApr 27, 2006
  4. C version of git-count-objects, second tryPeter Hagervall, Apr 27, 2006
  5. Junio C HamanoApr 27, 2006
  6. Nicolas PitreApr 27, 2006
  7. Peter HagervallApr 27, 2006
  8. Linus TorvaldsApr 27, 2006
  9. Peter HagervallApr 27, 2006
  10. Junio C HamanoApr 27, 2006
  11. Peter HagervallApr 28, 2006
  12. Junio C HamanoApr 28, 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.