{"thread":{"id":"590","subject":"[PATCH Cogito] Improve option parsing for cg-log","startedAt":"2005-05-12T20:51:54Z","lastAt":"2005-05-17T20:16:58Z","messageCount":7,"participants":["Marcel Holtmann","Petr Baudis","Dan Holmsand"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"3195","messageId":"1115931114.18499.66.camel@pegasus","threadId":"590","inReplyTo":null,"subject":"[PATCH Cogito] Improve option parsing for cg-log","fromName":"Marcel Holtmann","fromEmail":"marcel@holtmann.org","sentAt":"2005-05-12T20:51:54Z","receivedAt":"2005-05-12T20:51:54Z","isPatch":true,"sender":{"key":"marcel@holtmann.org","avatar":null},"body":"Hi Petr,\n\nthe attached patch changes the option parsing, because otherwise we are\nstuck to a specific order.\n\nRegards\n\nMarcel\n\n\nSigned-off-by: Marcel Holtmann <marcel@holtmann.org>\n\n\n\nIndex: cg-log\n===================================================================\n--- 456fffab323ed972b8e47fa0fb83c3b5cd9243d7/cg-log  (mode:100755)\n+++ uncommitted/cg-log  (mode:100755)\n@@ -27,29 +27,34 @@\n # at least somewhere it does. Bash is broken.\n trap exit SIGPIPE\n \n-if [ \"$1\" = \"-c\" ]; then\n-\tshift\n-\t# See terminfo(5), \"Color Handling\"\n-\tcolheader=\"$(tput setaf 2)\"    # Green\n-\tcolauthor=\"$(tput setaf 6)\"    # Cyan\n-\tcolcommitter=\"$(tput setaf 5)\" # Magenta\n-\tcolfiles=\"$(tput setaf 4)\"     # Blue\n-\tcolsignoff=\"$(tput setaf 3)\"   # Yellow\n-\tcoldefault=\"$(tput op)\"        # Restore default\n-else\n-\tcolheader=\n-\tcolauthor=\n-\tcolcommitter=\n-\tcolfiles=\n-\tcolsignoff=\n-\tcoldefault=\n-fi\n-\n+colheader=\n+colauthor=\n+colcommitter=\n+colfiles=\n+colsignoff=\n+coldefault=\n list_files=\n-if [ \"$1\" = \"-f\" ]; then\n-\tshift\n-\tlist_files=1\n-fi\n+while [ \"$1\" ]; do\n+\tcase \"$1\" in\n+\t-c)\n+\t\t# See terminfo(5), \"Color Handling\"\n+\t\tcolheader=\"$(tput setaf 2)\"    # Green\n+\t\tcolauthor=\"$(tput setaf 6)\"    # Cyan\n+\t\tcolcommitter=\"$(tput setaf 5)\" # Magenta\n+\t\tcolfiles=\"$(tput setaf 4)\"     # Blue\n+\t\tcolsignoff=\"$(tput setaf 3)\"   # Yellow\n+\t\tcoldefault=\"$(tput op)\"        # Restore default\n+\t\tshift\n+\t\t;;\n+\t-f)\n+\t\tlist_files=1\n+\t\tshift\n+\t\t;;\n+\t*)\n+\t\tbreak\n+\t\t;;\n+\tesac\n+done\n \n list_commit_files()\n {\n"},{"id":"3199","messageId":"20050512211315.GP324@pasky.ji.cz","threadId":"590","inReplyTo":"1115931114.18499.66.camel@pegasus","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-12T21:13:15Z","receivedAt":"2005-05-12T21:13:15Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, May 12, 2005 at 10:51:54PM CEST, I got a letter\nwhere Marcel Holtmann <marcel@holtmann.org> told me that...\n> Hi Petr,\n\nHi,\n\n> the attached patch changes the option parsing, because otherwise we are\n> stuck to a specific order.\n\nthanks, applied. However, you didn't include the -r options parsing in\nthere yet.\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":"3207","messageId":"1115934586.18499.70.camel@pegasus","threadId":"590","inReplyTo":"20050512211315.GP324@pasky.ji.cz","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Marcel Holtmann","fromEmail":"marcel@holtmann.org","sentAt":"2005-05-12T21:49:46Z","receivedAt":"2005-05-12T21:49:46Z","isPatch":true,"sender":{"key":"marcel@holtmann.org","avatar":null},"body":"Hi Petr,\n\n> > the attached patch changes the option parsing, because otherwise we are\n> > stuck to a specific order.\n> \n> thanks, applied. However, you didn't include the -r options parsing in\n> there yet.\n\nwhat do you mean by that?\n\nRegards\n\nMarcel\n\n\n"},{"id":"3228","messageId":"20050513054140.GF16464@pasky.ji.cz","threadId":"590","inReplyTo":"1115934586.18499.70.camel@pegasus","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-13T05:41:40Z","receivedAt":"2005-05-13T05:41:40Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Thu, May 12, 2005 at 11:49:46PM CEST, I got a letter\nwhere Marcel Holtmann <marcel@holtmann.org> told me that...\n> Hi Petr,\n> \n> > > the attached patch changes the option parsing, because otherwise we are\n> > > stuck to a specific order.\n> > \n> > thanks, applied. However, you didn't include the -r options parsing in\n> > there yet.\n> \n> what do you mean by that?\n\nThe -r option still must be after all the other options.\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":"3239","messageId":"1115975134.18499.94.camel@pegasus","threadId":"590","inReplyTo":"20050513054140.GF16464@pasky.ji.cz","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Marcel Holtmann","fromEmail":"marcel@holtmann.org","sentAt":"2005-05-13T09:05:34Z","receivedAt":"2005-05-13T09:05:34Z","isPatch":true,"sender":{"key":"marcel@holtmann.org","avatar":null},"body":"Hi Petr,\n\n> > > > the attached patch changes the option parsing, because otherwise we are\n> > > > stuck to a specific order.\n> > > \n> > > thanks, applied. However, you didn't include the -r options parsing in\n> > > there yet.\n> > \n> > what do you mean by that?\n> \n> The -r option still must be after all the other options.\n\nI see what you mean and it seems that I missed that option. Must be\nbecause you put the list_commit_files() between them and I assumed that\nthere is no further option parsing.\n\nDo you really wanna keep the double meaning of -r. Depending on a\nprevious -r it is $log_start or $log_end.\n\nRegards\n\nMarcel\n\n\n"},{"id":"3243","messageId":"42849063.1040003@gmail.com","threadId":"590","inReplyTo":"20050513054140.GF16464@pasky.ji.cz","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Dan Holmsand","fromEmail":"holmsand@gmail.com","sentAt":"2005-05-13T11:32:51Z","receivedAt":"2005-05-13T11:32:51Z","isPatch":true,"sender":{"key":"holmsand@gmail.com","avatar":"https://gravatar.com/avatar/5c722084bafd85e754a02efad01fe69107eb6f393253c49232c5c9f7faa974df?d=mp&s=160"},"body":"Petr Baudis wrote:\n> The -r option still must be after all the other options.\n> \n\nI've been thinking about option parsing as well, and I think cogito \ncould use a more \"getopt-like\" handling of options. \"cg-log -cf\"\nor \"cg-diff -rorigin\" is just so much easier to type...\n\nThe attached patch implements that for cg-log and cg-diff, by means of \ntwo new helper functions in cg-Xlib. It also improves error-handling a bit.\n\nHow about it?\n\n/dan\n\n\nBetter option parsing in cg-diff and cg-log. Uses a new function, optparse,\nin cg-Xlib, that allows for getopt-style option parsing.\n\nThis means that \"cg-log -cf\" is equivalent to \"cg-log -c -f\", as is\n\"cg-log -fc\" and \"cg-log -fc -rHEAD --\" and even\n\"cg-log --file-list --color --revision=HEAD\".\n\n---\n\n cg-Xlib |   33 ++++++++++++++++++++++++++++++\n cg-diff |   53 ++++++++++++++++++++++---------------------------\n cg-log  |   69 ++++++++++++++++++++++++----------------------------------------\n 3 files changed, 83 insertions(+), 72 deletions(-)\n\nIndex: cg-Xlib\n===================================================================\n--- de641904363cd3759f132ee7c0dfaf8a2ee58388/cg-Xlib  (mode:100755)\n+++ 048128149b56f55427713c78a8a3ca9da811e589/cg-Xlib  (mode:100755)\n@@ -62,6 +62,39 @@\n \tfi\n done\n \n+# option parsing\n+\n+opts=($@)\n+\n+optshift() {\n+\tunset opts[0]\n+\topts=(\"${opts[@]}\")\n+\t[ -z \"$1\" -o -n \"$opts\" ] || die \"option \\`$1' requires an argument\"\n+}\n+\n+optparse() {\n+\t[ -z \"$1\" ] && case $opts in\n+\t\t--) optshift; return 1 ;;\n+\t\t-*) return 0 ;;\n+\t\t*)  return 1 ;;\n+\tesac\n+\n+\tlocal match=${1%=} minmatch=${2:-1} o=$opts val\n+\t[[ $1 == *= ]] && val=$match\n+\tcase $match in\n+\t--*)\t[ \"$val\" ] && o=${opts%%=*}\n+\t\t[ ${#o} -ge $((2 + $minmatch)) -a \\\n+\t\t\t\"${match:0:${#o}}\" = \"$o\" ] || return 1\n+\t\t[[ -n \"$val\" && \"$opts\" == *=* ]] && opts[0]=${opts#*=} \\\n+\t\t\t|| optshift $val ;;\n+\t-?)\t[[ $o == $match* ]] || return 1\n+\t\t[[ $o != -?-* || -n \"$val\" ]] || die \"unrecognized option \\`$o'\"\n+\t\topts[0]=${o#$match}\n+\t\t[ \"$opts\" ] && { [ \"$val\" ] || opts[0]=-${opts}; } \\\n+\t\t\t|| optshift $val ;;\n+\t*)\tdie \"optparse cannot handle $1\" ;;\n+\tesac\n+}\n \n # Compatibility hacks:\n # 2005-04-26\nIndex: cg-diff\n===================================================================\n--- de641904363cd3759f132ee7c0dfaf8a2ee58388/cg-diff  (mode:100755)\n+++ 048128149b56f55427713c78a8a3ca9da811e589/cg-diff  (mode:100755)\n@@ -19,34 +19,33 @@\n . ${COGITO_LIB}cg-Xlib\n \n \n-id1=\" \"\n-id2=\" \"\n-parent=\n+unset id1 id2 parent\n \n+while optparse; do\n+\tif optparse -p || optparse --parent; then\n+\t\tparent=1\n+\telif optparse -r= || optparse --revision=; then\n+\t\tif [ set != \"${id1+set}\" ]; then\n+\t\t\tid1=$opts\n+\t\t\tif [[ \"$id1\" == *:* ]]; then\n+\t\t\t\tid2=${id1#*:}\n+\t\t\t\tid1=${id1%:*}\n+\t\t\tfi\n+\t\telse\n+\t\t\t[ set != \"${id2+set}\" ] || die \"too many versions\"\n+\t\t\tid2=$opts\n+\t\tfi\n+\t\toptshift\n+\telse\n+\t\tdie \"unrecognized option \\`$opts'\"\n+\tfi\n+done\n+shift $(( $# - ${#opts[*]} ))\n \n-# FIXME: The commandline parsing is awful.\n-\n-if [ \"$1\" = \"-p\" ]; then\n-\tshift\n-\tparent=1\n-fi\n-\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tid1=$(echo \"$1\": | cut -d : -f 1)\n-\t[ \"$id1\" != \"$1\" ] && id2=$(echo \"$1\": | cut -d : -f 2)\n-\tshift\n-fi\n-\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tid2=\"$1\"\n-\tshift\n-fi\n \n if [ \"$parent\" ]; then\n \tid2=\"$id1\"\n-\tid1=$(parent-id \"$id2\" | head -n 1)\n+\tid1=$(parent-id \"$id2\" | head -n 1) || exit 1\n fi\n \n \n@@ -58,12 +57,8 @@\n \tdone\n fi\n \n-if [ \"$id2\" = \" \" ]; then\n-\tif [ \"$id1\" != \" \" ]; then\n-\t\ttree=$(tree-id \"$id1\")\n-\telse\n-\t\ttree=$(tree-id)\n-\tfi\n+if [ set != \"${id2+set}\" ]; then\n+\ttree=$(tree-id \"${id1:-HEAD}\") || exit 1\n \n \t# Ensure to only diff modified files\n \tgit-update-cache --refresh\nIndex: cg-log\n===================================================================\n--- de641904363cd3759f132ee7c0dfaf8a2ee58388/cg-log  (mode:100755)\n+++ 048128149b56f55427713c78a8a3ca9da811e589/cg-log  (mode:100755)\n@@ -30,18 +30,11 @@\n # at least somewhere it does. Bash is broken.\n trap exit SIGPIPE\n \n-colheader=\n-colauthor=\n-colcommitter=\n-colfiles=\n-colsignoff=\n-coldefault=\n-list_files=\n-user=\n-while [ \"$1\" ]; do\n-\t# TODO: Parse -r here too.\n-\tcase \"$1\" in\n-\t-c)\n+unset colheader colauthor colcommitter colfiles colsignoff coldefault\n+unset list_files log_start log_end files user\n+\n+while optparse; do\n+\tif optparse -c || optparse --color; then\n \t\t# See terminfo(5), \"Color Handling\"\n \t\tcolheader=\"$(tput setaf 2)\"    # Green\n \t\tcolauthor=\"$(tput setaf 6)\"    # Cyan\n@@ -49,21 +42,28 @@\n \t\tcolfiles=\"$(tput setaf 4)\"     # Blue\n \t\tcolsignoff=\"$(tput setaf 3)\"   # Yellow\n \t\tcoldefault=\"$(tput op)\"        # Restore default\n-\t\tshift\n-\t\t;;\n-\t-f)\n+\telif optparse -f || optparse --file-list; then\n \t\tlist_files=1\n-\t\tshift\n-\t\t;;\n-\t-u*)\n-\t\tuser=\"${1#-u}\"\n-\t\tshift\n-\t\t;;\n-\t*)\n-\t\tbreak\n-\t\t;;\n-\tesac\n+\telif optparse -u= || optparse --user=; then\n+\t\tuser=$opts\n+\t\toptshift\n+\telif optparse -r= || optparse --revision=; then\n+\t\tif [ set != \"${log_start+set}\" ]; then\n+\t\t\tlog_start=$opts\n+\t\t\tif [[ \"$log_start\" == *:* ]]; then\n+\t\t\t\tlog_end=${log_start#*:}\n+\t\t\t\tlog_start=${log_start%:*}\n+\t\t\tfi\n+\t\telse\n+\t\t\t[ set != \"${log_end+set}\" ] || die \"too many revisions\"\n+\t\t\tlog_end=$opts\n+\t\tfi\n+\t\toptshift\n+\telse\n+\t\tdie \"unrecognized option \\`$opts'\"\n+\tfi\n done\n+shift $(( $# - ${#opts[*]} ))\n \n list_commit_files()\n {\n@@ -92,24 +92,7 @@\n \techo \"$coldefault:\"\n }\n \n-log_start=\n-log_end=\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tlog_start=\"$1\"\n-\tshift\n-\tif echo \"$log_start\" | grep -q ':'; then\n-\t\tlog_end=$(echo \"$log_start\" | cut -d : -f 2)\n-\t\tlog_start=$(echo \"$log_start\" | cut -d : -f 1)\n-\tfi\n-fi\n-if [ \"$1\" = \"-r\" ]; then\n-\tshift\n-\tlog_end=\"$1\"\n-\tshift\n-fi\n-\n-if [ \"$log_end\" ]; then\n+if [ set = \"${log_end+set}\" ]; then\n \tid1=\"$(commit-id $log_start)\" || exit 1\n \tid2=\"$(commit-id $log_end)\" || exit 1\n \trevls=\"git-rev-tree $id2 ^$id1\"\n"},{"id":"3465","messageId":"20050517201658.GD7136@pasky.ji.cz","threadId":"590","inReplyTo":"1115975134.18499.94.camel@pegasus","subject":"Re: [PATCH Cogito] Improve option parsing for cg-log","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-05-17T20:16:58Z","receivedAt":"2005-05-17T20:16:58Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Fri, May 13, 2005 at 11:05:34AM CEST, I got a letter\nwhere Marcel Holtmann <marcel@holtmann.org> told me that...\n> Hi Petr,\n\nHi,\n\n> > The -r option still must be after all the other options.\n> \n> I see what you mean and it seems that I missed that option. Must be\n> because you put the list_commit_files() between them and I assumed that\n> there is no further option parsing.\n\nUhm, I know. :-) It sorta evolved like that. We didn't yet settle down\non where to actually put the functions. I'd say right after . cg-Xlib.\n\n> Do you really wanna keep the double meaning of -r. Depending on a\n> previous -r it is $log_start or $log_end.\n\nYes, by all means. On one side I like the colon notation, on the other\nside this was always my biggest usability problem with SVN. And it costs\nus nothing and does what the user would after all expect, I think.\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"}]}