Re: [PATCH] C version of git-count-objects
From: Peter Hagervall <hidden>
Date: 2016-06-15 22:42:24
On Thu, Apr 27, 2006 at 01:07:27PM -0700, Linus Torvalds wrote:
On Thu, 27 Apr 2006, Peter Hagervall wrote:quoted
quoted
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>
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