From 36927d7f57b758064d0245f2e07b87b0b6427b38 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 5 Oct 2015 05:02:18 -0700 Subject: [PATCH] gc.sh: optimize is_dirty test Add a pipe through head so that find will be terminated by a SIGPIPE early once it's found enough results to satisfy the test. In the normal case, spawning the extra head process will be just ever so slightly slower, but in the pathological case of many, many, many objects and/or packs, the test will complete much, much, much more quickly with the head process in there. Signed-off-by: Kyle J. McKay --- jobd/gc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jobd/gc.sh b/jobd/gc.sh index 15272f9..efe455c 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -58,11 +58,11 @@ createlock() { # return true if there's more than one objects/pack-.pack file or # ANY sha-1 files in objects is_dirty() { - _packs=$(find objects/pack -type f -name "pack-$octet20.pack" -print | wc -l) + _packs=$(find objects/pack -type f -name "pack-$octet20.pack" -print | head -n 2 | wc -l) if [ $_packs != 1 ] && [ $_packs != 0 ]; then return 0 fi - _objs=$(find objects/$octet -type f -name "$octet19" -print 2>/dev/null | wc -l) + _objs=$(find objects/$octet -type f -name "$octet19" -print 2>/dev/null | head -n 1 | wc -l) [ $_objs -ne 0 ] } -- 2.11.4.GIT