[PATCH 7/8] cogito: Fix cg-tag to use cg-object-id
From: Pavel Roskin <hidden>
Date: 2016-06-15 22:42:06
Subsystem:
the rest · Maintainer:
Linus Torvalds
Fix cg-tag to use cg-object-id Add new option -n (normalize only) to cg-object-id. Mark all options as mutually exclusive and check it. Call 'cg-object-id -n' from cg-tag.
diff --git a/cg-object-id b/cg-object-id
--- a/cg-object-id
+++ b/cg-object-id@@ -8,10 +8,13 @@ # If the ID is not provided, HEAD is used. The default behavior is to # show the commit ID. # # OPTIONS # ------- +# -n:: +# Normalize only - don't check the object type. +# # -p:: # Get ID of parent commit(s) to a given revision or HEAD. # NOTE: Multiple SHA1s separated by newlines will be returned for # commits with multiple parents. #
@@ -19,11 +22,11 @@ # Get ID of tree associated with given commit or HEAD. # # OBJECT_ID:: # An ID resolving to a commit. -USAGE="cg-object-id [-p] [-t] [OBJECT_ID]" +USAGE="cg-object-id [-n | -p | -t] [OBJECT_ID]" . ${COGITO_LIB}cg-Xlib # Normalize argument. The normalized SHA1 ID is put to $normid.
@@ -95,12 +98,15 @@ normalize_id() show_parent= show_tree= +normalize_only= while optparse; do - if optparse -p; then + if optparse -n; then + normalize_only=1 + elif optparse -p; then show_parent=1 elif optparse -t; then show_tree=1 else optfail
@@ -111,17 +117,22 @@ done case $_cg_cmd in *parent*) show_parent=1;; *tree*) show_tree=1;; esac -if [ "$show_parent" -a "$show_tree" ]; then - echo "Cannot show parent and tree ID at the same time." >&2 - exit 1 -fi +case "$show_parent$show_tree$normalize_only" in + 11*) usage;; +esac id="${ARGS[0]}" normalize_id "$id" + +if [ "$normalize_only" ]; then + echo $normid + exit 0 +fi + [ "$type" ] || type=$(git-cat-file -t "$normid") if [ -z "$show_tree" ]; then if [ "$type" != "commit" ]; then echo "Invalid commit id: $normid" >&2
diff --git a/cg-tag b/cg-tag
--- a/cg-tag
+++ b/cg-tag@@ -45,12 +45,12 @@ done name="${ARGS[0]}" id="${ARGS[1]}" [ "$name" ] || usage -id=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1 -type=${id#* }; [ "$type" ] || type=$(git-cat-file -t "$id") +id=$(cg-object-id -n "$id") || exit 1 +type=$(git-cat-file -t "$id") id=${id% *} (echo $name | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \ die "name contains invalid characters"
--
Regards,
Pavel Roskin