sh-setup: add new peel_committish() helper

The normal way to check whether a certain revision resolves to a valid commit is: $ git rev-parse --verify $REV^0 Unfortunately, this does not work when $REV is of the type :/quuxery. Write a helper to work around this limitation. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Jun 14, 2013 at 18:47 UTC bac1ddd0f86bc5955c24f89e402de80d2844efb5
1 file changed +12
git-sh-setup.sh
+12
@@ -313,3 +313,15 @@ then
313 }
314 : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
315 fi
316 +
317 +peel_committish () {
318 + case "$1" in
319 + :/*)
320 + peeltmp=$(git rev-parse --verify "$1") &&
321 + git rev-parse --verify "${peeltmp}^0"
322 + ;;
323 + *)
324 + git rev-parse --verify "${1}^0"
325 + ;;
326 + esac
327 +}