{"thread":{"id":"1092","subject":"[PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","startedAt":"2005-07-03T05:59:42Z","lastAt":"2005-07-03T23:03:51Z","messageCount":8,"participants":["Brian Gerst","Petr Baudis","Sven Verdoolaege","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"5591","messageId":"42C77ECE.2080903@didntduck.org","threadId":"1092","inReplyTo":null,"subject":"[PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Brian Gerst","fromEmail":"bgerst@didntduck.org","sentAt":"2005-07-03T05:59:42Z","receivedAt":"2005-07-03T05:59:42Z","isPatch":true,"sender":{"key":"bgerst@didntduck.org","avatar":null},"body":"Use git-rev-parse instead of cg-Xnormid.  This allows Cogito to work \nproperly with packed objects.\n\nSigned off by: Brian Gerst <bgerst@didntduck.org>\n\n\n\nUse git-rev-parse instead of cg-Xnormid.  This allows Cogito to work properly with packed objects.\n\nSigned off by: Brian Gerst <bgerst@didntduck.org>\n\n---\ncommit 32c6125190d7d183110790b556a8e1128f29c52d\ntree 0e53bc37eb8ad12f093cfb0e903689ef95c54ece\nparent 266e27c48ba20c1af33f6a3eb966e8cd0d3c8b65\nauthor Brian Gerst <bgerst@didntduck.org> Sun, 03 Jul 2005 01:53:22 -0400\ncommitter Brian Gerst <bgerst@didntduck.org> Sun, 03 Jul 2005 01:53:22 -0400\n\n Makefile   |    2 +-\n cg-Xnormid |   63 ------------------------------------------------------------\n commit-id  |   12 +----------\n parent-id  |    4 +---\n tree-id    |    4 ++--\n 5 files changed, 5 insertions(+), 80 deletions(-)\n\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -67,7 +67,7 @@ SCRIPT=\tcommit-id tree-id parent-id cg-a\n \tcg-pull cg-restore cg-rm cg-seek cg-status cg-tag cg-tag-ls cg-update \\\n \tcg cg-admin-ls cg-push cg-branch-chg\n \n-LIB_SCRIPT=cg-Xlib cg-Xmergefile cg-Xnormid\n+LIB_SCRIPT=cg-Xlib cg-Xmergefile\n \n GEN_SCRIPT= cg-version\n \ndiff --git a/cg-Xnormid b/cg-Xnormid\ndeleted file mode 100755\n--- a/cg-Xnormid\n+++ /dev/null\n@@ -1,63 +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\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-\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\texit 1\n-\tfi\n-fi\n-\n-if ([ \"$id\" ] && [ \"$id\" != \" \" ]) && ([ ${#id} -ne 40 ] || [ ! -f .git/objects/${id:0:2}/${id:2} ]); 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-\tfi\n-fi\n-\n-# If we don't have a 40-char ID by now, it's an error\n-if [ ${#id} -ne 40 ] || [ ! -f $_git_objects/${id:0:2}/${id:2} ]; then\n-\techo \"Invalid id: $id\" >&2\n-\texit 1\n-fi\n-\n-if [ \"$(git-cat-file -t \"$id\")\" = \"tag\" ]; then\n-\tid=$(git-cat-file tag \"$id\" | head -n 1)\n-\tid=\"${id#object }\"\n-fi\n-\n-echo $id\ndiff --git a/commit-id b/commit-id\n--- a/commit-id\n+++ b/commit-id\n@@ -5,14 +5,4 @@\n #\n # Takes the appropriate ID, defaults to HEAD.\n \n-. ${COGITO_LIB}cg-Xlib\n-\n-id=\"$1\"\n-normid=$(${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n-\n-if [ \"$(git-cat-file -t \"$normid\")\" != \"commit\" ]; then\n-\techo \"Invalid commit id: $id\" >&2\n-\texit 1\n-fi\n-\n-echo $normid\n+git-rev-parse \"${1:-HEAD}\"\ndiff --git a/parent-id b/parent-id\n--- a/parent-id\n+++ b/parent-id\n@@ -7,6 +7,4 @@\n #\n # NOTE: Will return multiple SHA1s if ID is a commit with multiple parents.\n \n-id=$(commit-id \"$1\") || exit 1\n-\n-git-cat-file commit $id | awk '/^parent/{print $2};/^$/{exit}'\n+git-rev-parse \"${1:-HEAD}^\"\ndiff --git a/tree-id b/tree-id\n--- a/tree-id\n+++ b/tree-id\n@@ -5,8 +5,8 @@\n #\n # Takes ID of the appropriate commit, defaults to HEAD.\n \n-id=\"$1\"\n-normid=$(${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n+id=\"${1:-HEAD}\"\n+normid=$(git-rev-parse \"$id\")\n type=$(git-cat-file -t \"$normid\")\n \n if [ \"$type\" = \"commit\" ]; then\n"},{"id":"5592","messageId":"20050703065920.GA11765@pasky.ji.cz","threadId":"1092","inReplyTo":"42C77ECE.2080903@didntduck.org","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-07-03T06:59:20Z","receivedAt":"2005-07-03T06:59:20Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sun, Jul 03, 2005 at 07:59:42AM CEST, I got a letter\nwhere Brian Gerst <bgerst@didntduck.org> told me that...\n> Use git-rev-parse instead of cg-Xnormid.  This allows Cogito to work \n> properly with packed objects.\n> \n> Signed off by: Brian Gerst <bgerst@didntduck.org>\n\nBut git-rev-parse sucks. It won't detect invalid IDs (--revs-only?), and\ndoes not support short object IDs (that's a must, it's tremendously\nuseful). You need to add that for it to be useful first.\n\n> diff --git a/tree-id b/tree-id\n> --- a/tree-id\n> +++ b/tree-id\n> @@ -5,8 +5,8 @@\n>  #\n>  # Takes ID of the appropriate commit, defaults to HEAD.\n>  \n> -id=\"$1\"\n> -normid=$(${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n> +id=\"${1:-HEAD}\"\n> +normid=$(git-rev-parse \"$id\")\n>  type=$(git-cat-file -t \"$normid\")\n>  \n>  if [ \"$type\" = \"commit\" ]; then\n\nThis is broken too. You need to be able to pass _tree_ ID to tree-id too,\nnot just commit ID. Hmm, or is git-rev-parse able to process any ids?\nThen it's terribly misnamed too. :-) A comment would be useful in that\ncase. (Or better a patch to rename it.)\n\nThanks,\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n<Espy> be careful, some twit might quote you out of context..\n"},{"id":"5601","messageId":"42C7D925.2070007@didntduck.org","threadId":"1092","inReplyTo":"20050703065920.GA11765@pasky.ji.cz","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Brian Gerst","fromEmail":"bgerst@didntduck.org","sentAt":"2005-07-03T12:25:09Z","receivedAt":"2005-07-03T12:25:09Z","isPatch":true,"sender":{"key":"bgerst@didntduck.org","avatar":null},"body":"Petr Baudis wrote:\n> Dear diary, on Sun, Jul 03, 2005 at 07:59:42AM CEST, I got a letter\n> where Brian Gerst <bgerst@didntduck.org> told me that...\n> \n>>Use git-rev-parse instead of cg-Xnormid.  This allows Cogito to work \n>>properly with packed objects.\n>>\n>>Signed off by: Brian Gerst <bgerst@didntduck.org>\n> \n> \n> But git-rev-parse sucks. It won't detect invalid IDs (--revs-only?), and\n> does not support short object IDs (that's a must, it's tremendously\n> useful). You need to add that for it to be useful first.\n\ncg-Xnormid is terminally broken in the presence of packed files, since \nit cannot look into them to find objects.  Moreover, many uses of \ncommit-id in the scripts can be eliminated because the underlying git \ncommands can already understand tags directly, and will check for \ninvalid ids then.  The only thing missing is the short id matching.\n\n> \n> \n>>diff --git a/tree-id b/tree-id\n>>--- a/tree-id\n>>+++ b/tree-id\n>>@@ -5,8 +5,8 @@\n>> #\n>> # Takes ID of the appropriate commit, defaults to HEAD.\n>> \n>>-id=\"$1\"\n>>-normid=$(${COGITO_LIB}cg-Xnormid \"$id\") || exit 1\n>>+id=\"${1:-HEAD}\"\n>>+normid=$(git-rev-parse \"$id\")\n>> type=$(git-cat-file -t \"$normid\")\n>> \n>> if [ \"$type\" = \"commit\" ]; then\n> \n> \n> This is broken too. You need to be able to pass _tree_ ID to tree-id too,\n> not just commit ID. Hmm, or is git-rev-parse able to process any ids?\n> Then it's terribly misnamed too. :-) A comment would be useful in that\n> case. (Or better a patch to rename it.)\n\nYes you can still pass in the tree id.\n\n--\n\t\t\t\tBrian Gerst\n"},{"id":"5606","messageId":"20050703154049.GD18608MdfPADPa@garage.linux.student.kuleuven.ac.be","threadId":"1092","inReplyTo":"20050703154127.GA31848@pasky.ji.cz","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2005-07-03T15:40:49Z","receivedAt":"2005-07-03T15:40:49Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Sun, Jul 03, 2005 at 05:41:27PM +0200, Petr Baudis wrote:\n> That's right. Well, for everything but the short id matching we could\n> just check the ID validity by git-rev-parse instead of peeking into\n> the object store - I just did that. \n\nWhy not use it to actually resolve ids ?\nI really miss the '^' parent notation in cogito.\n\nskimo\n"},{"id":"5605","messageId":"20050703154127.GA31848@pasky.ji.cz","threadId":"1092","inReplyTo":"42C7D925.2070007@didntduck.org","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-07-03T15:41:27Z","receivedAt":"2005-07-03T15:41:27Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sun, Jul 03, 2005 at 02:25:09PM CEST, I got a letter\nwhere Brian Gerst <bgerst@didntduck.org> told me that...\n> Petr Baudis wrote:\n> >Dear diary, on Sun, Jul 03, 2005 at 07:59:42AM CEST, I got a letter\n> >where Brian Gerst <bgerst@didntduck.org> told me that...\n> >\n> >>Use git-rev-parse instead of cg-Xnormid.  This allows Cogito to work \n> >>properly with packed objects.\n> >>\n> >>Signed off by: Brian Gerst <bgerst@didntduck.org>\n> >\n> >\n> >But git-rev-parse sucks. It won't detect invalid IDs (--revs-only?), and\n> >does not support short object IDs (that's a must, it's tremendously\n> >useful). You need to add that for it to be useful first.\n> \n> cg-Xnormid is terminally broken in the presence of packed files, since \n> it cannot look into them to find objects.\n\nThat's right. Well, for everything but the short id matching we could\njust check the ID validity by git-rev-parse instead of peeking into\nthe object store - I just did that. If I'm not missing anything, that\nwill just make the short id matching for packed objects impossible, but\nworks fine otherwise...?\n\n> Moreover, many uses of commit-id in the scripts can be eliminated because\n> the underlying git commands can already understand tags directly, and will\n> check for invalid ids then.\n\nI feel reserved about that. I want to have custom error handling here to\ngive the user less confusing output (no core GIT command name, since\nthat confuses users), and as I said, Cogito's rev resolving is more\npowerful than Core Git's.\n\n> The only thing missing is the short id matching.\n\nYes, but as I said, I think it's very important to have. BTW, another\ncool thing cg-Xnormid does and git-rev-parse does not: time specifiers.\nE.g. you could specify revisions as \"2 days ago\" or so, very useful for\ncg-log, cg-diff and such.\n\nThanks for pointing this out, BTW.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n<Espy> be careful, some twit might quote you out of context..\n"},{"id":"5609","messageId":"20050703223118.GD13848@pasky.ji.cz","threadId":"1092","inReplyTo":"20050703154049.GD18608MdfPADPa@garage.linux.student.kuleuven.ac.be","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-07-03T22:31:18Z","receivedAt":"2005-07-03T22:31:18Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sun, Jul 03, 2005 at 05:40:49PM CEST, I got a letter\nwhere Sven Verdoolaege <skimo@kotnet.org> told me that...\n> On Sun, Jul 03, 2005 at 05:41:27PM +0200, Petr Baudis wrote:\n> > That's right. Well, for everything but the short id matching we could\n> > just check the ID validity by git-rev-parse instead of peeking into\n> > the object store - I just did that. \n> \n> Why not use it to actually resolve ids ?\n> I really miss the '^' parent notation in cogito.\n\nI've decided to go the less troublesome way and just teach cg-Xnormid\nabout the ^ prefix. ;-)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n<Espy> be careful, some twit might quote you out of context..\n"},{"id":"5611","messageId":"Pine.LNX.4.58.0507031535420.3570@g5.osdl.org","threadId":"1092","inReplyTo":"20050703154127.GA31848@pasky.ji.cz","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-07-03T22:40:52Z","receivedAt":"2005-07-03T22:40:52Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sun, 3 Jul 2005, Petr Baudis wrote:\n> \n> That's right. Well, for everything but the short id matching we could\n> just check the ID validity by git-rev-parse instead of peeking into\n> the object store - I just did that.\n\nWhat's the format of the short ID? Minimum 6 characters of the SHA1 or\nsomething?\n\nPack-files in many ways should be even easier to look up the ID in, since\nthe pack-file index has all the SHA1's for that pack file listed in sorted\norder, so it should be fairly easy to just look it up based on the first\nfew bytes.. If somebody sends me a patch, that should be fine.\n\n> > The only thing missing is the short id matching.\n> \n> Yes, but as I said, I think it's very important to have. BTW, another\n> cool thing cg-Xnormid does and git-rev-parse does not: time specifiers.\n> E.g. you could specify revisions as \"2 days ago\" or so, very useful for\n> cg-log, cg-diff and such.\n\nThat is indeed something that seems to make more sense in cg-Xnormid.\n\n\t\tLinus\n"},{"id":"5613","messageId":"20050703230351.GE13848@pasky.ji.cz","threadId":"1092","inReplyTo":"Pine.LNX.4.58.0507031535420.3570@g5.osdl.org","subject":"Re: [PATCH] Cogito: Use git-rev-parse instead of cg-Xnormid.","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-07-03T23:03:51Z","receivedAt":"2005-07-03T23:03:51Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, Jul 04, 2005 at 12:40:52AM CEST, I got a letter\nwhere Linus Torvalds <torvalds@osdl.org> told me that...\n> \n> \n> On Sun, 3 Jul 2005, Petr Baudis wrote:\n> > \n> > That's right. Well, for everything but the short id matching we could\n> > just check the ID validity by git-rev-parse instead of peeking into\n> > the object store - I just did that.\n> \n> What's the format of the short ID? Minimum 6 characters of the SHA1 or\n> something?\n> \n> Pack-files in many ways should be even easier to look up the ID in, since\n> the pack-file index has all the SHA1's for that pack file listed in sorted\n> order, so it should be fairly easy to just look it up based on the first\n> few bytes.. If somebody sends me a patch, that should be fine.\n\nActually, the minimum is 4 characters, but that shouldn't be much of an\nissue. Cogito's behaviour is to raise an error in case of multiple\nmatches; but that could be controlled by a switch too...\n\n\tbash$ complete -C git-rev-parse git* cg*\n\n\nI will cook up a patch in a day or two if noone outruns me.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n<Espy> be careful, some twit might quote you out of context..\n"}]}