{"thread":{"id":"1874","subject":"[PATCH 4/8] cogito: Integrate cg-Xnormid into cg-object-id","startedAt":"2005-09-20T02:18:51Z","lastAt":"2005-09-20T02:18:51Z","messageCount":1,"participants":["Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"8950","messageId":"1127182731.31115.25.camel@dv","threadId":"1874","inReplyTo":null,"subject":"[PATCH 4/8] cogito: Integrate cg-Xnormid into cg-object-id","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-09-20T02:18:51Z","receivedAt":"2005-09-20T02:18:51Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Integrate cg-Xnormid into cg-object-id.\n\nConvert it to a function normalize_id().  Change it to return at most\none ID.  Use the first parent if parent is requested.  \"cg-object-id -p\"\nnow uses separate code to return more than one parent ID.\n\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -16,11 +16,11 @@ SCRIPT=\tcg-object-id cg-add cg-admin-lso\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-LIB_SCRIPT=cg-Xlib cg-Xmergefile cg-Xnormid\n+LIB_SCRIPT=cg-Xlib cg-Xmergefile\n \n GEN_SCRIPT= cg-version\n \n VERSION= VERSION\n \ndiff --git a/cg-Xnormid b/cg-Xnormid\ndeleted file mode 100755\n--- a/cg-Xnormid\n+++ /dev/null\n@@ -1,75 +0,0 @@\n-#!/usr/bin/env bash\n-#\n-# Normalize an ID to an SHA1 hash value.\n-# Copyright (c) Petr Baudis, 2005\n-# Copyright (c) Philip Pokorny, 2005\n-#\n-# Strings resolve in this order:\n-# \tNULL, this, HEAD  => .git/HEAD\n-# \t<tags>\n-# \t<heads>\n-# \tshort SHA1 (4 or more hex digits)\n-#\n-# Takes the ID to normalize and returns the normalized ID.\n-\n-. ${COGITO_LIB}cg-Xlib || exit 1\n-\n-id=\"$1\"\n-\n-if [ \"${id:(-1):1}\" = \"^\" ]; then\n-\t# find parent\n-\tid=$(cg-object-id \"${id%^}\") || exit 1\n-\tgit-cat-file commit \"$id\" | awk '/^parent/{print $2};/^$/{exit}' || exit 1\n-\texit\n-fi\n-\n-if [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n-\tread id < \"$_git/HEAD\"\n-\n-elif [ -r \"$_git/refs/tags/$id\" ]; then\n-\tread id < \"$_git/refs/tags/$id\"\n-\n-elif [ -r \"$_git/refs/heads/$id\" ]; then\n-\tread id < \"$_git/refs/heads/$id\"\n-\n-# Short id's must be lower case and at least 4 digits.\n-elif [[ \"$id\" == [0-9a-f][0-9a-f][0-9a-f][0-9a-f]* ]]; then\n-\tidpref=${id:0:2}\n-\tidpost=${id:2}\n-\n-\t# Assign array elements to matching names\n-\tidmatch=($_git_objects/$idpref/$idpost*)\n-\n-\tif [ ${#idmatch[*]} -eq 1 ] && [ -r \"$idmatch\" ]; then\n-\t\tid=$idpref${idmatch#$_git_objects/$idpref/}\n-\telif [ ${#idmatch[*]} -gt 1 ]; then\n-\t\techo \"Ambiguous id: $id\" >&2\n-\t\techo \"${idmatch[@]}\" >&2\n-\t\texit 1\n-\tfi\n-fi\n-\n-valid=; [ ${#id} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$id\")\" ] && valid=1\n-if ([ \"$id\" ] && [ \"$id\" != \" \" ]) && [ ! \"$valid\" ]; then\n-\treqsecs=$(date --date=\"$id\" +'%s' 2>/dev/null)\n-\n-\tif [ \"$reqsecs\" ]; then\n-\t\tid=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)\n-\t\tvalid=; [ ${#id} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$id\")\" ] && valid=1\n-\tfi\n-fi\n-\n-# If we don't have a 40-char ID by now, it's an error\n-if [ ! \"$valid\" ]; then\n-\techo \"Invalid id: $id\" >&2\n-\texit 1\n-fi\n-\n-type=\"$(git-cat-file -t \"$id\")\"\n-if [ \"$type\" = \"tag\" ]; then\n-\tid=$(git-cat-file tag \"$id\" | head -n 1)\n-\tid=\"${id#object }\"\n-\ttype=\n-fi\n-\n-echo \"$id $type\"\ndiff --git a/cg-object-id b/cg-object-id\n--- a/cg-object-id\n+++ b/cg-object-id\n@@ -1,10 +1,11 @@\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+# Copyright (c) Pavel Roskin, 2005\n+# Copyright (c) Philip Pokorny, 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@@ -22,10 +23,80 @@\n \n USAGE=\"cg-object-id [-p] [-t] [OBJECT_ID]\"\n \n . ${COGITO_LIB}cg-Xlib\n \n+\n+# Normalize argument.  The normalized SHA1 ID is put to $normid,\n+# type is put to $type.\n+normalize_id()\n+{\n+\tlocal id=\"$1\"\n+\n+\tif [ \"${id:(-1):1}\" = \"^\" ]; then\n+\t\t# find first parent\n+\t\tid=$(cg-object-id \"${id%^}\") || exit 1\n+\t\tnormid=$(git-cat-file commit \"$id\" | \\\n+\t\t\t awk '/^parent/{print $2; exit};/^$/{exit}') || exit 1\n+\t\ttype=\"commit\"\n+\t\treturn\n+\tfi\n+\n+\tif [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n+\t\tread id < \"$_git/HEAD\"\n+\n+\telif [ -r \"$_git/refs/tags/$id\" ]; then\n+\t\tread id < \"$_git/refs/tags/$id\"\n+\n+\telif [ -r \"$_git/refs/heads/$id\" ]; then\n+\t\tread id < \"$_git/refs/heads/$id\"\n+\n+\t# Short id's must be lower case and at least 4 digits.\n+\telif [[ \"$id\" == [0-9a-f][0-9a-f][0-9a-f][0-9a-f]* ]]; then\n+\t\tidpref=${id:0:2}\n+\t\tidpost=${id:2}\n+\n+\t\t# Assign array elements to matching names\n+\t\tidmatch=($_git_objects/$idpref/$idpost*)\n+\n+\t\tif [ ${#idmatch[*]} -eq 1 ] && [ -r \"$idmatch\" ]; then\n+\t\t\tid=$idpref${idmatch#$_git_objects/$idpref/}\n+\t\telif [ ${#idmatch[*]} -gt 1 ]; then\n+\t\t\techo \"Ambiguous id: $id\" >&2\n+\t\t\techo \"${idmatch[@]}\" >&2\n+\t\t\texit 1\n+\t\tfi\n+\tfi\n+\n+\tvalid=; [ ${#id} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$id\")\" ] && valid=1\n+\tif ([ \"$id\" ] && [ \"$id\" != \" \" ]) && [ ! \"$valid\" ]; then\n+\t\treqsecs=$(date --date=\"$id\" +'%s' 2>/dev/null)\n+\n+\t\tif [ \"$reqsecs\" ]; then\n+\t\t\tid=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)\n+\t\t\tvalid=; [ ${#id} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$id\")\" ] && valid=1\n+\t\tfi\n+\tfi\n+\n+\t# If we don't have a 40-char ID by now, it's an error\n+\tif [ ! \"$valid\" ]; then\n+\t\techo \"Invalid id: $id\" >&2\n+\t\texit 1\n+\tfi\n+\n+\ttype=\"$(git-cat-file -t \"$id\")\"\n+\tif [ \"$type\" = \"tag\" ]; then\n+\t\tid=$(git-cat-file tag \"$id\" | head -n 1)\n+\t\tid=\"${id#object }\"\n+\t\ttype=\n+\tfi\n+\n+\tnormid=\"$id\"\n+}\n+\n+\n+\n show_parent=\n show_tree=\n while optparse; do\n \tif optparse -p; then\n \t\tshow_parent=1\n@@ -46,23 +117,17 @@ if [ \"$show_parent\" -a \"$show_tree\" ]; t\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+normalize_id \"$id\"\n \n if [ \"$show_parent\" ]; then\n-\techo \"${normid% *}\"\n+\tgit-cat-file commit \"$normid\" | awk '/^parent/{print $2};/^$/{exit}'\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\n\n-- \nRegards,\nPavel Roskin\n"}]}