From: Jeff King Date: Mon, 10 Aug 2015 09:36:19 +0000 (-0400) Subject: refs.c: remove extra git_path calls from read_loose_refs X-Git-Tag: v2.6.0-rc0~57^2~8 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f5b2dec1657e09a22f8b2aefa25d022988e3e467?ds=inline;hp=f5b2dec1657e09a22f8b2aefa25d022988e3e467 refs.c: remove extra git_path calls from read_loose_refs In iterating over the loose refs in "refs/foo/", we keep a running strbuf with "refs/foo/one", "refs/foo/two", etc. But we also need to access these files in the filesystem, as ".git/refs/foo/one", etc. For this latter purpose, we make a series of independent calls to git_path(). These are safe (we only use the result to call stat()), but assigning the result of git_path is a suspicious pattern that we'd rather avoid. This patch keeps a running buffer with ".git/refs/foo/", and we can just append/reset each directory element as we loop. This matches how we handle the refnames. It should also be more efficient, as we do not keep formatting the same ".git/refs/foo" prefix (which can be arbitrarily deep). Technically we are dropping a call to strbuf_cleanup() on each generated filename, but that's OK; it wasn't doing anything, as we are putting in single-level names we read from the filesystem (so it could not possibly be cleaning up cruft like "./" in this instance). A clever reader may also note that the running refname buffer ("refs/foo/") is actually a subset of the filesystem path buffer (".git/refs/foo/"). We could get by with one buffer, indexing the length of $GIT_DIR when we want the refname. However, having tried this, the resulting code actually ends up a little more confusing, and the efficiency improvement is tiny (and almost certainly dwarfed by the system calls we are making). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano ---