]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/reflog.c
reflog-expire: Avoid creating new files in a directory inside readdir(3) loop
authorJunio C Hamano <gitster@pobox.com>
Sat, 26 Jan 2008 07:53:05 +0000 (23:53 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Jan 2008 05:48:57 +0000 (21:48 -0800)
commitbda3a31cc7982a7ef8ddb5137359d27c3c75ebed
tree513ecbeda8edf76f131ccca1cbe8296c3d694f95
parent7720224cebde08186627ab7bdb06018905d84e30
reflog-expire: Avoid creating new files in a directory inside readdir(3) loop

"git reflog expire --all" opened a directory in $GIT_DIR/logs/,
read reflog files in there readdir(3), and rewrote the file by
creating a new file and renaming it back inside the loop.  This
code structure can cause the newly created file to be returned
by subsequent call to readdir(3), and fall into an infinite loop
in the worst case.

This separates the processing to two phase.  Running
for_each_reflog() to find out and collect all refs, and then
iterate over them, calling expire_reflog().  This way, the
program would behave exactly the same way as if all the refs
were given by the user from the command line.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-reflog.c