]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
get rid of some subshells when finding checksums of a file
authorRudolf Polzer <divverent@xonotic.org>
Sat, 28 May 2011 06:35:23 +0000 (08:35 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sat, 28 May 2011 06:35:23 +0000 (08:35 +0200)
misc/tools/cached-converter.sh

index 43aa5b2cd3d00327be2cbe6510a260abd12b70cc..104b657d2bfd8188ff69264b1bb6e66f824c1546 100755 (executable)
@@ -39,6 +39,36 @@ tmpdir=`mktemp -d -t cached-converter.XXXXXX`
 trap 'exit 1' INT
 trap 'rm -rf "$tmpdir"' EXIT
 
+
+use_magnet_to_acquire_checksum_faster()
+#             ___________________
+#        ,--'' ~~~~~~~^^^~._     '.
+#    ,.-' ~~~~~~~~~~^^^^^~~~._._   \
+#    |   /^^^^^|    /^^^^^^^^\\ \   \
+#  ,/___  <  o>      <  (OO) > _     \
+# /'/,         |-         .       ----.\
+# |(|-'^^;,-  ,|     __    ^~~^^^^^^^; |\
+# \\`  |    <;_    __ |`---  ..-^^/- | ||
+#  \`-|Oq-.____`________~='^^|__,/  ' //
+#   \ || | |   |  |    \ ..-;|  /    '/
+#   | ||#|#|the|==|game!|'^` |/'    /'
+#   | \\\\^\***|***|    \ ,,;'     /
+#   |  `-=\_\__\___\__..-' ,.- - ,/
+#   | . `-_  ------   _,-'^-'^,-'
+#   | `-._________..--''^,-''^
+#   \             ,...-'^
+#    `----------'^              PROBLEM?
+{
+       magnet=`GIT_DIR="$git_src_repo/.git" git ls-files -s "$1"`
+       if [ -n "$magnet" ]; then
+               magnet=${magnet#* }
+               magnet=${magnet%% *}
+               sum=$sum$magnet
+       else
+               sum=$sum`git hash-object "$1"`
+       fi
+}
+
 lastinfiles=
 lastinfileshash=
 cached()
@@ -70,9 +100,10 @@ cached()
                        esac
                done
                if [ -n "$git_src_repo" ] && ! $evil; then
-                       sum=`( cd "$git_src_repo"; git ls-files -s "${infile1#./}" | cut -d ' ' -f 2 | grep . ) || { echo >&2 "git-ls-files failed on $infile1"; git hash-object "$infile1"; }`
+                       sum=
+                       use_magnet_to_acquire_checksum_faster "${infile1#./}"
                        if [ -n "$infile2" ]; then
-                               sum=$sum`( cd "$git_src_repo"; git ls-files -s "${infile2#./}" | cut -d ' ' -f 2 | grep . ) || { echo >&2 "git-ls-files failed on $infile2"; git hash-object "$infile2"; }`
+                               use_magnet_to_acquire_checksum_faster "${infile2#./}"
                        fi
                else
                        sum=`git hash-object "$infile1"`