From: Peter Hagervall Date: Thu, 27 Apr 2006 20:51:56 GMT Subject: Re: [PATCH] C version of git-count-objects Message-ID: <20060427205155.GA26856@brainysmurf.cs.umu.se> In-Reply-To: On Thu, Apr 27, 2006 at 01:07:27PM -0700, Linus Torvalds wrote: > > > 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); > 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