* [PATCH 7/8] cogito: Fix cg-tag to use cg-object-id
@ 2005-09-20 2:27 Pavel Roskin
0 siblings, 0 replies; only message in thread
From: Pavel Roskin @ 2005-09-20 2:27 UTC (permalink / raw)
To: git
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-09-20 2:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-20 2:27 [PATCH 7/8] cogito: Fix cg-tag to use cg-object-id Pavel Roskin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).