{"thread":{"id":"1018","subject":"rev-parse, unknown arguments and extended sha1's","startedAt":"2005-06-24T12:24:36Z","lastAt":"2005-06-24T17:32:13Z","messageCount":5,"participants":["Sven Verdoolaege","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"5215","messageId":"20050624122436.GA15182@pc117b.liacs.nl","threadId":"1018","inReplyTo":null,"subject":"rev-parse, unknown arguments and extended sha1's","fromName":"Sven Verdoolaege","fromEmail":"skimo@liacs.nl","sentAt":"2005-06-24T12:24:36Z","receivedAt":"2005-06-24T12:24:36Z","isPatch":false,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"Is git-rev-parse supposed to echo arguments it doesn't understand ?\nIt currently does, but git-checkout-script seems to think it doesn't:\n\n                rev=$(git-rev-parse \"$arg\")   \n                if [ -z \"$rev\" ]; then\n                        echo \"unknown flag $arg\"\n                        exit 1\n                fi\n\nAlso, is there any reason why the extended sha1 notation\nis restricted to the scripts and not used in the actual\nplumbing ?\n\nskimo\n"},{"id":"5227","messageId":"Pine.LNX.4.58.0506240904240.11175@ppc970.osdl.org","threadId":"1018","inReplyTo":"20050624122436.GA15182@pc117b.liacs.nl","subject":"Re: rev-parse, unknown arguments and extended sha1's","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-24T16:09:23Z","receivedAt":"2005-06-24T16:09:23Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 24 Jun 2005, Sven Verdoolaege wrote:\n>\n> Is git-rev-parse supposed to echo arguments it doesn't understand ?\n> It currently does, but git-checkout-script seems to think it doesn't:\n> \n>                 rev=$(git-rev-parse \"$arg\")   \n>                 if [ -z \"$rev\" ]; then\n>                         echo \"unknown flag $arg\"\n>                         exit 1\n>                 fi\n\nArgh, there's a \"--revs-only\" thing that I was planning to use there, some \nremnant of an ealy plan (unimplemented) to use that to determine if it is \na filename to be checked out, or a revision.\n\nBut then I never got around to do the \"specify individual filenames\" part \nof \"git checkout\".\n\nAnyway, add the --revs-only, and the test against empty should make a bit \nmore sense. In fact, it _should_ test that it's a SHA1 (and not a rev \nargument), but I couldn't come up with a good way to test that in shell.\n\n\t\tLinus\n"},{"id":"5228","messageId":"20050624161718.GA14909@pc117b.liacs.nl","threadId":"1018","inReplyTo":"Pine.LNX.4.58.0506240904240.11175@ppc970.osdl.org","subject":"Re: rev-parse, unknown arguments and extended sha1's","fromName":"Sven Verdoolaege","fromEmail":"skimo@liacs.nl","sentAt":"2005-06-24T16:17:18Z","receivedAt":"2005-06-24T16:17:18Z","isPatch":false,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Fri, Jun 24, 2005 at 09:09:23AM -0700, Linus Torvalds wrote:\n> Anyway, add the --revs-only, and the test against empty should make a bit \n> more sense. In fact, it _should_ test that it's a SHA1 (and not a rev \n> argument), but I couldn't come up with a good way to test that in shell.\n> \n\nThis is what I use:\n\nrev2=`echo $rev | sed -e 's/[^0-9a-f]//'`\nrev3=`echo $rev2 | sed -e 's/........................................//'`\nif test \"x$rev3\" = \"x\" -a \"x$rev\" = \"x$rev2\"; then\n\techo \"valid SHA1\"\nfi\n\nskimo\n"},{"id":"5230","messageId":"Pine.LNX.4.58.0506240941520.11175@ppc970.osdl.org","threadId":"1018","inReplyTo":"20050624161718.GA14909@pc117b.liacs.nl","subject":"Re: rev-parse, unknown arguments and extended sha1's","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-24T16:43:12Z","receivedAt":"2005-06-24T16:43:12Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 24 Jun 2005, Sven Verdoolaege wrote:\n>\n> This is what I use:\n> \n> rev2=`echo $rev | sed -e 's/[^0-9a-f]//'`\n> rev3=`echo $rev2 | sed -e 's/........................................//'`\n> if test \"x$rev3\" = \"x\" -a \"x$rev\" = \"x$rev2\"; then\n> \techo \"valid SHA1\"\n> fi\n\nOooh. UGGHLEE.\n\nThis is one reason I don't do much shell.\n\nAnyway, I think I'll make git-rev-parse have some option to \"error out if \nthe result is anything but a single revision number\", since this is really \nthe only reason for git-rev-parse in the first place: to make readable \nscripts.\n\n\t\tLinus\n"},{"id":"5232","messageId":"Pine.LNX.4.58.0506241026490.11175@ppc970.osdl.org","threadId":"1018","inReplyTo":"Pine.LNX.4.58.0506240941520.11175@ppc970.osdl.org","subject":"Re: rev-parse, unknown arguments and extended sha1's","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-24T17:32:13Z","receivedAt":"2005-06-24T17:32:13Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 24 Jun 2005, Linus Torvalds wrote:\n> \n> Anyway, I think I'll make git-rev-parse have some option to \"error out if \n> the result is anything but a single revision number\", since this is really \n> the only reason for git-rev-parse in the first place: to make readable \n> scripts.\n\nHow about something like\n\n\trev=$(git-rev-parse --default HEAD --revs-only --verify \"$@\") || exit 1\n\nwhich now should work correctly.\n\nIn particular, the \"--default\" field is now expanded properly as a\nrevision, instead of just output raw, so the \"HEAD\" actually gets\ntranslated into its SHA1 representation (and this also means that you can\nnow use SHA1 expressions in \"default\", ie you don't need to do two\ngit-rev-parse phases to do \"--default HEAD^\" etc).\n\nThe \"--verify\" thing then checks that the end result isn't a revision\nargument (ie \"--max-age=..\" isn't accepted), and that there's exactly one\nrevision in the result (ie no ranges or multiple revisions some other\nway).\n\nSo now you shouldn't need to check the result any more. You know that if\nit worked, \"rev\" will be a nice SHA1 (of course, it might still be an\n_invalid_ SHA1, that's a different issue. But it's at least syntactically\nok)\n\n\t\tLinus\n"}]}