{"thread":{"id":"351","subject":"PATCH: Allow tree-id to return the ID of a tree object","startedAt":"2005-04-27T16:20:55Z","lastAt":"2005-05-02T05:46:53Z","messageCount":8,"participants":["Philip Pokorny","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"1872","messageId":"426FBBE7.1090806@mindspring.com","threadId":"351","inReplyTo":null,"subject":"PATCH: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-27T16:20:55Z","receivedAt":"2005-04-27T16:20:55Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"While playing with cg-ls, I tried:\n\n% cg-ls\n... snip ...\n100644  blob    bc607fd55f6ce4e56ce87766369b5d4d55ec79af        object.h\n100755  blob    f35877a6aa5b68d2fb4a388dcfa9b3e64262604e        parent-id\n040000  tree    bfb75011c32589b282dd9c86621dadb0f0bb3866        ppc\n100644  blob    d922305ee0f5583bdfcb629f6d4061e11e0fa859        read-cache.c\n100644  blob    1ad7ffc555b635fe57fa7834b12d71ff576be065        read-tree.c\n... snip ...\n% cg-ls bfb75011c32589b282dd9c86621dadb0f0bb3866       <-- the ppc tree ID\nInvalid id: bfb75011c32589b282dd9c86621dadb0f0bb3866\nusage: cat-file [-t | tagname] <sha1>\nusage: cat-file [-t | tagname] <sha1>\nInvalid id:\n\n\nShouldn't cg-ls give a listing of a sub-tree?  The cg-help says it takes\na TREE-ID?\n\nThe problem seems to be that tree-id really only accepts a commit-id and\nreturns the TREE-ID of that commit.\n\nSo I modified commit-id, tree-id and parent-id to make them more similar\nin coding style, force \"short-id\" names to be at least 4 lower case\nletters, and have tree-id accept short, unambiguous ID's and bare SHA1-ID's.\n\nPatch attached.\n\n\n\n\n\nIndex: commit-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/commit-id  (mode:100755 sha1:4efcb6bdfdb2b2c5744f5d4d47d92beb7777ed59)\n+++ uncommitted/commit-id  (mode:100775)\n@@ -9,22 +9,30 @@\n SHA1ONLY=\"^$SHA1$\"\n \n id=$1\n+\n if [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n \tid=$(cat .git/HEAD)\n-fi\n \n-if (echo $id | egrep -vq \"$SHA1ONLY\") && [ -r \".git/refs/tags/$id\" ]; then\n+elif [ -r \".git/refs/tags/$id\" ]; then\n \tid=$(cat \".git/refs/tags/$id\")\n-fi\n \n-if (echo $id | egrep -vq \"$SHA1ONLY\") && [ -r \".git/refs/heads/$id\" ]; then\n+elif [ -r \".git/refs/heads/$id\" ]; then\n \tid=$(cat \".git/refs/heads/$id\")\n-fi\n \n-idpref=$(echo \"$id\" | cut -c -2)\n-idpost=$(echo \"$id\" | cut -c 3-)\n-if [ $(find \".git/objects/$idpref\" -name \"$idpost*\" 2>/dev/null | wc -l) -eq 1 ]; then\n-\tid=$idpref$(basename $(echo .git/objects/$idpref/$idpost*))\n+# Short id's must be lower case and at least 4 digits.\n+elif [[ \"$id\" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then\n+\tidpost=${id#??}\n+\tidpref=${id%$idpost}\n+\n+\t# Assign array elements to matching names\n+\tidmatch=($(echo .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\texit 1\n+\tfi\n fi\n \n if echo $id | egrep -vq \"$SHA1ONLY\"; then\nIndex: tree-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/tree-id  (mode:100755 sha1:1495ff78af71b57e21653512932bcda88fe05454)\n+++ uncommitted/tree-id  (mode:100775)\n@@ -7,8 +7,35 @@\n \n SHA1=\"[A-Za-z0-9]{40}\"\n TREE=\"^tree $SHA1$\"\n+SHA1ONLY=\"^$SHA1$\"\n \n-id=$(cat-file commit $(commit-id \"$1\") | egrep \"$TREE\" | cut -d ' ' -f 2)\n+id=$1\n+\n+# Is it a commit?\n+commit=$(commit-id $id 2>/dev/null)\n+if [ \"$commit\" ]; then\n+\tid=$(cat-file commit \"$commit\") | egrep \"$TREE\" | cut -d ' ' -f 2)\n+\n+# Short id's must be lower case and at least 4 digits.\n+elif [[ \"$id\" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then\n+\tidpost=${id#??}\n+\tidpref=${id%$idpost}\n+\n+\t# Assign array elements to matching names\n+\tidmatch=($(echo .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\texit 1\n+\tfi\n+fi\n+\n+if echo $id | egrep -vq \"$SHA1ONLY\"; then\n+\techo \"Invalid id: $id\" >&2\n+\texit 1\n+fi\n \n if [ \"$(cat-file -t \"$id\")\" != \"tree\" ]; then\n \techo \"Invalid id: $id\" >&2\nIndex: parent-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/parent-id  (mode:100755 sha1:f35877a6aa5b68d2fb4a388dcfa9b3e64262604e)\n+++ uncommitted/parent-id  (mode:100775)\n@@ -5,7 +5,8 @@\n #\n # Takes ID of the current commit, defaults to HEAD.\n \n-PARENT=\"^parent [A-Za-z0-9]{40}$\"\n+SHA1=\"[A-Za-z0-9]{40}\"\n+PARENT=\"^parent $SHA1$\"\n \n id=$(commit-id $1) || exit 1\n \n\n"},{"id":"1934","messageId":"20050427232223.GM22956@pasky.ji.cz","threadId":"351","inReplyTo":"426FBBE7.1090806@mindspring.com","subject":"Re: PATCH: Allow tree-id to return the ID of a tree object","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-04-27T23:22:23Z","receivedAt":"2005-04-27T23:22:23Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Wed, Apr 27, 2005 at 06:20:55PM CEST, I got a letter\nwhere Philip Pokorny <ppokorny@mindspring.com> told me that...\n> While playing with cg-ls, I tried:\n> \n> % cg-ls\n> ... snip ...\n> 100644  blob    bc607fd55f6ce4e56ce87766369b5d4d55ec79af        object.h\n> 100755  blob    f35877a6aa5b68d2fb4a388dcfa9b3e64262604e        parent-id\n> 040000  tree    bfb75011c32589b282dd9c86621dadb0f0bb3866        ppc\n> 100644  blob    d922305ee0f5583bdfcb629f6d4061e11e0fa859        read-cache.c\n> 100644  blob    1ad7ffc555b635fe57fa7834b12d71ff576be065        read-tree.c\n> ... snip ...\n> % cg-ls bfb75011c32589b282dd9c86621dadb0f0bb3866       <-- the ppc tree ID\n> Invalid id: bfb75011c32589b282dd9c86621dadb0f0bb3866\n> usage: cat-file [-t | tagname] <sha1>\n> usage: cat-file [-t | tagname] <sha1>\n> Invalid id:\n> \n> \n> Shouldn't cg-ls give a listing of a sub-tree?  The cg-help says it takes\n> a TREE-ID?\n> \n> The problem seems to be that tree-id really only accepts a commit-id and\n> returns the TREE-ID of that commit.\n> \n> So I modified commit-id, tree-id and parent-id to make them more similar\n> in coding style, force \"short-id\" names to be at least 4 lower case\n> letters, and have tree-id accept short, unambiguous ID's and bare SHA1-ID's.\n> \n> Patch attached.\n\nCould you please functionally split and sign off your patch?\n\nAlso, I'd prefer not to have the sha1 completion logic duplicated; what\nabout just having commit-id take a parameter not to validate its id?\nActually, that's ugly too. I think the cleanest solution would be to\nreintroduce the cg-Xnormid, now to only really do the _common_ stuff -\nbasically everything up to the typecheck (exclusively) in commit-id.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"},{"id":"2008","messageId":"42708CA9.2050201@mindspring.com","threadId":"351","inReplyTo":"20050427232223.GM22956@pasky.ji.cz","subject":"Re: PATCH[0/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-28T07:11:37Z","receivedAt":"2005-04-28T07:11:37Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Petr Baudis wrote:\n\n>Could you please functionally split and sign off your patch?\n>  \n>\nApologies, I'm still a bit new to LKML etiquette...\n\n>Also, I'd prefer not to have the sha1 completion logic duplicated; what\n>about just having commit-id take a parameter not to validate its id?\n>Actually, that's ugly too. I think the cleanest solution would be to\n>reintroduce the cg-Xnormid, now to only really do the _common_ stuff -\n>basically everything up to the typecheck (exclusively) in commit-id.\n>  \n>\nOK, so following this will be a new set of patches (I assume you mean \none patch per file changed when you asked for a \"functional split\") that \nre-introduce cg-Xnormid, and then convert commit-id, tree-id, and \nparent-id to use the new core.\n\nIn re-writing these, I've put great effort into making the scripts *not* \nexec a sub-shell or process, so the bash constructs may look strange. \nI'm sure Linux can exec very quickly, but bash parses and executes even \nfaster when it doesn't have to fork.\n"},{"id":"2009","messageId":"42708D45.8070303@mindspring.com","threadId":"351","inReplyTo":"20050427232223.GM22956@pasky.ji.cz","subject":"Re: PATCH[1/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-28T07:14:13Z","receivedAt":"2005-04-28T07:14:13Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Patch to re-introduce cg-Xnormid for common ID normalizing.\n\nSigned-off-by: Philip Pokorny <ppokorny@mindspring.com>\n\n\n\n\nIndex: cg-Xnormid\n===================================================================\n--- /dev/null  (tree:6ad600e20c89323c1d3049f75b8ca9b0a2d72167)\n+++ uncommitted/cg-Xnormid  (mode:100755 sha1:6dc089c8d571f330e2e01d96f79616d6146840ee)\n@@ -0,0 +1,47 @@\n+#!/usr/bin/env bash\n+#\n+# Normalize an ID to an SHA1 hash value\n+#    Strings resolve in order:\n+#       NULL, this, HEAD  => .git/HEAD\n+#       <tags>\n+#       <heads>\n+#       short SHA1 (4 or more hex digits)\n+#\n+# Copyright (c) Philip Pokorny, 2005\n+\n+id=\"$1\"\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-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then\n+\tidpost=${id#??}\n+\tidpref=${id%$idpost}\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\texit 1\n+\tfi\n+fi\n+\n+# FIXME? Should we verify the existance of the ID in the object cache?\n+\n+# If we don't have a 40-char ID by now, it's an error\n+if [ ${#id} -ne 40 ]; then\n+\techo \"Invalid id: $id\" >&2\n+\texit 1\n+fi\n+\n+echo $id\nIndex: Makefile\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/Makefile  (mode:100644 sha1:d73bea1cbb9451a89b03d6066bf2ed7fec32fd31)\n+++ uncommitted/Makefile  (mode:100664)\n@@ -44,7 +44,7 @@\n \tcg-add cg-admin-lsobj cg-cancel cg-clone cg-commit cg-diff \\\n \tcg-export cg-help cg-init cg-log cg-ls cg-merge cg-mkpatch \\\n \tcg-patch cg-pull cg-branch-add cg-branch-ls cg-rm cg-seek cg-status \\\n-\tcg-tag cg-update cg-Xlib\n+\tcg-tag cg-update cg-Xlib cg-Xnormid\n \n COMMON=\tread-cache.o\n \n"},{"id":"2011","messageId":"42708D8E.10003@mindspring.com","threadId":"351","inReplyTo":"20050427232223.GM22956@pasky.ji.cz","subject":"Re: PATCH[2/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-28T07:15:26Z","receivedAt":"2005-04-28T07:15:26Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Convert commit-id to use the new cg-Xnormid internal script\n\nSigned-off-by: Philip Pokorny <ppokorny@mindspring.com>\n\n\nIndex: commit-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/commit-id  (mode:100755 sha1:4efcb6bdfdb2b2c5744f5d4d47d92beb7777ed59)\n+++ uncommitted/commit-id  (mode:100775)\n@@ -1,39 +1,25 @@\n #!/usr/bin/env bash\n #\n # Get ID of commit associated with given id or HEAD.\n+#\n # Copyright (c) Petr Baudis, 2005\n #\n-# Takes the appropriate ID, defaults to HEAD.\n-\n-SHA1=\"[A-Za-z0-9]{40}\"\n-SHA1ONLY=\"^$SHA1$\"\n-\n-id=$1\n-if [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n-\tid=$(cat .git/HEAD)\n-fi\n \n-if (echo $id | egrep -vq \"$SHA1ONLY\") && [ -r \".git/refs/tags/$id\" ]; then\n-\tid=$(cat \".git/refs/tags/$id\")\n-fi\n-\n-if (echo $id | egrep -vq \"$SHA1ONLY\") && [ -r \".git/refs/heads/$id\" ]; then\n-\tid=$(cat \".git/refs/heads/$id\")\n-fi\n+# Save for later error message\n+orig=\"$1\"\n \n-idpref=$(echo \"$id\" | cut -c -2)\n-idpost=$(echo \"$id\" | cut -c 3-)\n-if [ $(find \".git/objects/$idpref\" -name \"$idpost*\" 2>/dev/null | wc -l) -eq 1 ]; then\n-\tid=$idpref$(basename $(echo .git/objects/$idpref/$idpost*))\n-fi\n+# Normalize to SHA1 form\n+id=$(cg-Xnormid \"$orig\")\n \n-if echo $id | egrep -vq \"$SHA1ONLY\"; then\n-\techo \"Invalid id: $id\" >&2\n+if [ ! \"$id\" ]; then\n+\t# cg-Xnormid already reported the error\n \texit 1\n fi\n \n-if [ \"$(cat-file -t \"$id\")\" != \"commit\" ]; then\n-\techo \"Invalid id: $id\" >&2\n+# cat-file will verify that $id is a valid SHA1 ID for us\n+# If it isn't, we'll get '' back\n+if [ \"$(cat-file -t \"$id\" 2>/dev/null)\" != \"commit\" ]; then\n+\techo \"Invalid commit id: $orig\" >&2\n \texit 1\n fi\n \n"},{"id":"2010","messageId":"42708DCB.1040007@mindspring.com","threadId":"351","inReplyTo":"20050427232223.GM22956@pasky.ji.cz","subject":"Re: PATCH[3/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-28T07:16:27Z","receivedAt":"2005-04-28T07:16:27Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Convert tree-id to use cg-Xnormid to normalize an ID\n\nSigned-off-by: Philip Pokorny <ppokorny@mindspring.com>\n\n\nIndex: tree-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/tree-id  (mode:100755 sha1:1495ff78af71b57e21653512932bcda88fe05454)\n+++ uncommitted/tree-id  (mode:100775)\n@@ -1,17 +1,31 @@\n #!/usr/bin/env bash\n #\n # Get ID of tree associated with given commit or HEAD.\n+#\n # Copyright (c) Petr Baudis, 2005\n #\n-# Takes ID of the appropriate commit, defaults to HEAD.\n \n-SHA1=\"[A-Za-z0-9]{40}\"\n-TREE=\"^tree $SHA1$\"\n+# Save for later error message\n+orig=\"$1\"\n \n-id=$(cat-file commit $(commit-id \"$1\") | egrep \"$TREE\" | cut -d ' ' -f 2)\n+# Normalize to SHA1 form\n+id=$(cg-Xnormid \"$1\")\n+if [ ! \"$id\" ]; then\n+\t# cg-Xnormid already reported the error\n+\texit 1\n+fi\n+\n+# Is it a commit?\n+idtype=$(cat-file -t $id 2>/dev/null)\n+if [ \"$idtype\" = \"commit\" ]; then\n+\t# Get the tree\n+\tid=$(cat-file commit \"$id\" | sed -e 's/tree //;q')\n+fi\n \n-if [ \"$(cat-file -t \"$id\")\" != \"tree\" ]; then\n-\techo \"Invalid id: $id\" >&2\n+# cat-file will verify that $id is a valid SHA1 ID for us\n+# If it isn't, we'll get '' back\n+if [ \"$(cat-file -t \"$id\" 2>/dev/null)\" != \"tree\" ]; then\n+\techo \"Invalid tree id: $orig\" >&2\n \texit 1\n fi\n \n"},{"id":"2012","messageId":"42708E26.2090803@mindspring.com","threadId":"351","inReplyTo":"20050427232223.GM22956@pasky.ji.cz","subject":"Re: PATCH[4/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-04-28T07:17:58Z","receivedAt":"2005-04-28T07:17:58Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Convert parent-id to similar style and function as the new commit-id and \ntree-id.\n\nNOTE: parent-id uses commit-id rather than cg-Xnormid directly\n\nSigned-off-by: Philip Pokorny <ppokorny@mindspring.com>\n\n\nIndex: parent-id\n===================================================================\n--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/parent-id  (mode:100755 sha1:f35877a6aa5b68d2fb4a388dcfa9b3e64262604e)\n+++ uncommitted/parent-id  (mode:100775)\n@@ -1,12 +1,19 @@\n #!/usr/bin/env bash\n #\n # Get ID of parent commit to a given revision or HEAD.\n+# NOTE: will return multiple SHA1s if ID is a commit with multiple parents\n+#\n # Copyright (c) Petr Baudis, 2005\n #\n-# Takes ID of the current commit, defaults to HEAD.\n \n-PARENT=\"^parent [A-Za-z0-9]{40}$\"\n+# Save for later error message\n+orig=\"$1\"\n \n-id=$(commit-id $1) || exit 1\n+# Normalize to SHA1 form and verify its a commit\n+id=$(commit-id \"$1\")\n+if [ ! \"$id\" ]; then\n+\t# commit-id already reported the error\n+\texit 1\n+fi\n \n-cat-file commit $id | egrep \"$PARENT\" | cut -d ' ' -f 2\n+cat-file commit $id | awk '/^parent/{print $2};/^$/{exit}'\n"},{"id":"2357","messageId":"4275BECD.7070407@mindspring.com","threadId":"351","inReplyTo":"42708D8E.10003@mindspring.com","subject":"Re: PATCH[2/4]: Allow tree-id to return the ID of a tree object","fromName":"Philip Pokorny","fromEmail":"ppokorny@mindspring.com","sentAt":"2005-05-02T05:46:53Z","receivedAt":"2005-05-02T05:46:53Z","isPatch":false,"sender":{"key":"ppokorny@mindspring.com","avatar":null},"body":"Philip Pokorny wrote:\n\n> Convert commit-id to use the new cg-Xnormid internal script\n>\n> Signed-off-by: Philip Pokorny <ppokorny@mindspring.com>\n\n\nWere these patches accepted??  I ask because while I do seem to see the \naddition of the new cg-Xnormid, I don't see that tree-id and friends \nhave been updated to use the new file.\n\nBut then again, I seem to be having trouble getting my git working \ndirectory to track or match the current head.  That would be:\n    49612c471eebd26efe926a71752e254c1cdc382d\nright?\n\nWait...  Perhaps I'm seeing cg-Xnormid because it was an \"other\" file \nand therefore left in my directory.  But that still doesn't explain why \nmy checkedout cache doesn't show the results of the latest changes to \ncg-help...  Even after running 'cg-update origin'\n\nI'm so confused.  It seems difficult to know exactly what the state of \nyour cache actually *is* at any given time.  Shouldn't cg-status tell \nyou that you have modified, but uncommited files in your cache?  Is \nthere any way to know what the tree-id/commit-id your cache is an \ninstance of?  Do you have to 'cat .git/blocked' and 'ls -l .git/HEAD' to \nknow?\n\nIn clearcase, I could 'ct lsview' and 'ct catcs' to see what my current \nview/cache was.  I can't find the equivalent in cogito...\n\n:v)\n"}]}