git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] sh-setup: add new peel_committish() helper

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 13, 2013, 18:16 UTC
Message-ID
<1371147362-26962-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371147362-26962-1-git-send-email-artagnon@gmail.com>

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>
---
 git-sh-setup.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 2f78359..6ae19a6 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -313,3 +313,16 @@ then
 	}
 	: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
 fi
+
+peel_committish () {
+	test $# -gt 1 && quiet="--quiet" || quiet=""
+	case "$1" in
+	:/*)
+		peeltmp=$(git rev-parse --verify $quiet "$1") &&
+		git rev-parse --verify "${peeltmp}^0"
+		;;
+	*)
+		git rev-parse --verify "${1}^0"
+		;;
+	esac
+}
-- 
1.8.3.1.381.g31c8856.dirty
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 3 of 4 in “Support :/quuxery in rebase (early preview)”
  1. 0/3 Support :/quuxery in rebase (early preview)Ramkumar Ramachandra, Jun 13, 2013
  2. 1/3 t/rebase: add failing tests for a peculiar revisionRamkumar Ramachandra, Jun 13, 2013
  3. 2/3 sh-setup: add new peel_committish() helperRamkumar Ramachandra, Jun 13, 2013
  4. 3/3 rebase: use peel_committish() where appropriateRamkumar Ramachandra, Jun 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.