{"thread":{"id":"1872","subject":"[PATCH 1/8] cogito: Merge *-id scripts into cg-object-id.","startedAt":"2005-09-20T02:11:42Z","lastAt":"2005-09-20T02:11:42Z","messageCount":1,"participants":["Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"8948","messageId":"1127182302.31115.16.camel@dv","threadId":"1872","inReplyTo":null,"subject":"[PATCH 1/8] cogito: Merge *-id scripts into cg-object-id.","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-09-20T02:11:42Z","receivedAt":"2005-09-20T02:11:42Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Merge *-id scripts into cg-object-id.\n    \nIt's easier to have one script with one manpage.\n\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -10,11 +10,11 @@ INSTALL?=install\n \n ### --- END CONFIGURATION SECTION ---\n \n \n \n-SCRIPT=\tcg-commit-id cg-tree-id cg-parent-id cg-add cg-admin-lsobj cg-admin-uncommit \\\n+SCRIPT=\tcg-object-id cg-add cg-admin-lsobj cg-admin-uncommit \\\n \tcg-branch-add cg-branch-ls cg-reset cg-clone cg-commit cg-diff \\\n \tcg-export cg-help cg-init cg-log cg-merge cg-mkpatch cg-patch \\\n \tcg-fetch cg-restore cg-rm cg-seek cg-status cg-tag cg-tag-ls cg-update \\\n \tcg cg-admin-ls cg-upload cg-branch-chg cg-admin-cat cg-clean\n \n@@ -76,12 +76,14 @@ sedlibdir=$(shell echo $(libdir) | sed '\n install: install-cogito\n \n install-cogito: $(SCRIPT) $(LIB_SCRIPT) $(GEN_SCRIPT)\n \t$(INSTALL) -m755 -d $(DESTDIR)$(bindir)\n \t$(INSTALL) $(SCRIPT) $(GEN_SCRIPT) $(DESTDIR)$(bindir)\n-\tfor i in 'cg-cancel:cg-reset' 'commit-id:cg-commit-id' \\\n-\t\t'tree-id:cg-tree-id' 'parent-id:cg-parent-id' \\\n+\tfor i in 'cg-cancel:cg-reset' 'commit-id:cg-object-id' \\\n+\t\t'tree-id:cg-object-id' 'parent-id:cg-object-id' \\\n+\t\t'cg-commit-id:cg-object-id' \\\n+\t\t'cg-tree-id:cg-object-id' 'cg-parent-id:cg-object-id' \\\n \t\t'cg-pull:cg-fetch' 'cg-push:cg-upload'; do \\\n \t\told=`echo $$i | cut -d : -f 1`; \\\n \t\tnew=`echo $$i | cut -d : -f 2`; \\\n \t\trm -f $(DESTDIR)$(bindir)/$$old; \\\n \t\tln -s $$new $(DESTDIR)$(bindir)/$$old; \\\ndiff --git a/cg-commit-id b/cg-commit-id\ndeleted file mode 100755\n--- a/cg-commit-id\n+++ /dev/null\n@@ -1,21 +0,0 @@\n-#!/usr/bin/env bash\n-#\n-# Get ID of commit associated with given id or HEAD.\n-# Copyright (c) Petr Baudis, 2005\n-#\n-# Takes the appropriate ID, defaults to HEAD.\n-\n-USAGE=\"cg-commit-id [COMMIT_ID]\"\n-\n-id=\"$1\"\n-normid=$(. ${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n-type=${normid#* }\n-normid=${normid% *}\n-[ \"$type\" ] || type=$(git-cat-file -t \"$normid\")\n-\n-if [ \"$type\" != \"commit\" ]; then\n-\techo \"Invalid commit id: $normid\" >&2\n-\texit 1\n-fi\n-\n-echo $normid\ndiff --git a/cg-object-id b/cg-object-id\nnew file mode 100755\n--- /dev/null\n+++ b/cg-object-id\n@@ -0,0 +1,83 @@\n+#!/usr/bin/env bash\n+#\n+# Get SHA1 ID of commit or tree associated with given ID or HEAD.\n+# Copyright (c) Petr Baudis, 2005\n+# Copyright (c) Pavel Roskin 2005\n+#\n+# If the ID is not provided, HEAD is used.  The default behavior is to\n+# show the commit ID.\n+#\n+# OPTIONS\n+# -------\n+# -p::\n+#\tGet ID of parent commit(s) to a given revision or HEAD.\n+#\tNOTE: Multiple SHA1s will be returned for commits with multiple\n+#\tparents.\n+#\n+# -t::\n+#\tGet ID of tree associated with given commit or HEAD.\n+#\n+# OBJECT_ID::\n+#\tAn ID resolving to a commit.\n+\n+USAGE=\"cg-object-id [-p] [-t] [OBJECT_ID]\"\n+\n+. ${COGITO_LIB}cg-Xlib\n+\n+show_parent=\n+show_tree=\n+while optparse; do\n+\tif optparse -p; then\n+\t\tshow_parent=1\n+\telif optparse -t; then\n+\t\tshow_tree=1\n+\telse\n+\t\toptfail\n+\tfi\n+done\n+\n+# Compatibility code\n+case $_cg_cmd in\n+\t*parent*) show_parent=1;;\n+\t*tree*) show_tree=1;;\n+esac\n+\n+if [ \"$show_parent\" -a \"$show_tree\" ]; then\n+\techo \"Cannot show parent and tree ID at the same time.\" >&2\n+\texit 1\n+fi\n+\n+id=\"${ARGS[0]}\"\n+if [ \"$show_parent\" ]; then\n+\tid=\"$id\"^\n+fi\n+\n+normid=$(. ${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n+\n+if [ \"$show_parent\" ]; then\n+\techo ${normid% *}\n+\texit 0\n+fi\n+\n+type=${normid#* }\n+normid=${normid% *}\n+[ \"$type\" ] || type=$(git-cat-file -t \"$normid\")\n+if [ \"$show_tree\" ]; then\n+\tif [ \"$type\" = \"commit\" ]; then\n+\t\tnormid=$(git-cat-file commit \"$normid\" | sed -e 's/tree //;q')\n+\t\ttype=$(git-cat-file -t \"$normid\")\n+\tfi\n+\n+\tif [ \"$type\" != \"tree\" ]; then\n+\t\techo \"Invalid tree id: $normid\" >&2\n+\t\texit 1\n+\tfi\n+else\n+\tif [ \"$type\" != \"commit\" ]; then\n+\t\techo \"Invalid commit id: $normid\" >&2\n+\t\texit 1\n+\tfi\n+fi\n+\n+echo $normid\n+\ndiff --git a/cg-parent-id b/cg-parent-id\ndeleted file mode 100755\n--- a/cg-parent-id\n+++ /dev/null\n@@ -1,13 +0,0 @@\n-#!/usr/bin/env bash\n-#\n-# Get ID of parent commit to a given revision or HEAD.\n-# Copyright (c) Petr Baudis, 2005\n-#\n-# Takes ID of the current commit, defaults to HEAD.\n-#\n-# NOTE: Will return multiple SHA1s if ID is a commit with multiple parents.\n-\n-USAGE=\"cg-parent-id [COMMIT_ID]\"\n-\n-normid=$(. ${COGITO_LIB}cg-Xnormid \"$1\"^)\n-echo ${normid%% *}\ndiff --git a/cg-tree-id b/cg-tree-id\ndeleted file mode 100755\n--- a/cg-tree-id\n+++ /dev/null\n@@ -1,26 +0,0 @@\n-#!/usr/bin/env bash\n-#\n-# Get ID of tree associated with given commit or HEAD.\n-# Copyright (c) Petr Baudis, 2005\n-#\n-# Takes ID of the appropriate commit, defaults to HEAD.\n-\n-USAGE=\"cg-tree-id [COMMIT_ID]\"\n-\n-id=\"$1\"\n-normid=$(. ${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n-type=${normid#* }\n-normid=${normid% *}\n-[ \"$type\" ] || type=$(git-cat-file -t \"$normid\")\n-\n-if [ \"$type\" = \"commit\" ]; then\n-\tnormid=$(git-cat-file commit \"$normid\" | sed -e 's/tree //;q')\n-\ttype=$(git-cat-file -t \"$normid\")\n-fi\n-\n-if [ \"$type\" != \"tree\" ]; then\n-\techo \"Invalid tree id: $normid\" >&2\n-\texit 1\n-fi\n-\n-echo $normid\n\n-- \nRegards,\nPavel Roskin\n"}]}