sh-setup: add new peel_committish() helper
authorRamkumar Ramachandra <artagnon@gmail.com>
Fri, 14 Jun 2013 13:17:51 +0000 (18:47 +0530)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2013 16:41:03 +0000 (09:41 -0700)
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>
git-sh-setup.sh
index 2f7835941ecaa48be17b6dd64e64fb0df3db37e2..7a964ad2ff70a8746c52ab30d945ebff95246edd 100644 (file)
@@ -313,3 +313,15 @@ then
        }
        : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
 fi
+
+peel_committish () {
+       case "$1" in
+       :/*)
+               peeltmp=$(git rev-parse --verify "$1") &&
+               git rev-parse --verify "${peeltmp}^0"
+               ;;
+       *)
+               git rev-parse --verify "${1}^0"
+               ;;
+       esac
+}