{"thread":{"id":"2769","subject":"[PATCH] Offload most of cg-object-id to git-rev-parse","startedAt":"2005-12-07T21:39:06Z","lastAt":"2005-12-11T18:31:07Z","messageCount":3,"participants":["Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13332","messageId":"20051207213905.GA25890@diku.dk","threadId":"2769","inReplyTo":null,"subject":"[PATCH] Offload most of cg-object-id to git-rev-parse","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-12-07T21:39:06Z","receivedAt":"2005-12-07T21:39:06Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Signed-off-by: Jonas Fonseca <fonseca@diku.dk>\n\n---\ncommit 964e5ec2dd0ff3b073fbb9f3ad6f11c640a96a04\ntree 97f861c24303936f012523a54f3d53f4939ebf52\nparent 554014e31b92c98b35f77b80b19f5b21e8a76cfc\nauthor Jonas Fonseca <fonseca@diku.dk> Wed, 07 Dec 2005 07:44:26 +0100\ncommitter Jonas Fonseca <fonseca@antimatter.localdomain> Wed, 07 Dec 2005 07:44:26 +0100\n\n TODO         |    2 --\n cg-object-id |   29 +++++++++--------------------\n 2 files changed, 9 insertions(+), 22 deletions(-)\n\ndiff --git a/TODO b/TODO\nindex 0658b39..26bb4d0 100644\n--- a/TODO\n+++ b/TODO\n@@ -27,8 +27,6 @@ cg-*patch should be pre-1.0.)\n \n \tIncludes merge-order cg-log and cg-diff checking for renames.\n \n-* Offload most of cg-object-id to git-rev-parse\n-\n * Show only first 12 (or so) nibbles of the hashes everywhere\n \tEven this might be too much, but more than this is really useless\n \tfor anyone remotely human. And it's less scary, too.\ndiff --git a/cg-object-id b/cg-object-id\nindex ec0362a..c7efa8a 100755\n--- a/cg-object-id\n+++ b/cg-object-id\n@@ -40,27 +40,16 @@ deprecated_alias cg-object-id commit-id \n normalize_id()\n {\n \tlocal id=\"$1\"\n+\tlocal revid=\n+\tlocal valid=\n \n-\tif [ \"${id:(-1):1}\" = \"^\" ]; then\n-\t\t# find first parent\n-\t\tnormalize_id \"${id%^}\"\n-\t\tnormid=$(git-cat-file commit \"$normid\" | \\\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/$(git-symbolic-ref 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+\tif [ ! \"$id\" ] || [ \"$id\" = \"this\" ]; then\n+\t\tid=HEAD;\n+\tfi\n \n-\telif [ -r \"$_git/refs/$id\" ]; then\n-\t\tread id < \"$_git/refs/$id\"\n+\trevid=\"$(git-rev-parse --verify \"$id^0\" 2>/dev/null)\"\n+\tif [ \"$revid\" ]; then\n+\t\tid=\"$revid\"\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@@ -146,7 +135,7 @@ fi\n \n \n if [ \"$show_parent\" ]; then\n-\tgit-cat-file commit \"$normid\" | awk '/^parent/{print $2};/^$/{exit}'\n+\tgit-rev-parse \"$normid^\"\n \texit 0\n fi\n \n\n-- \nJonas Fonseca\n"},{"id":"13488","messageId":"20051211181901.GA2960@diku.dk","threadId":"2769","inReplyTo":"20051207213905.GA25890@diku.dk","subject":"[PATCH] Offload most of cg-object-id to git-rev-parse","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-12-11T18:19:01Z","receivedAt":"2005-12-11T18:19:01Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Signed-off-by: Jonas Fonseca <fonseca@diku.dk>\n \n---\n\n Forget the other 4 patches. Here's one that fixes the thing we\n discussed on IRC, i.e. ambiguous ID's are handled correctly\n (unfortunately without giving a proper warning message).\n \n This one also assumes that there is no reason for checking revs\n returned by git-rev-list with git-rev-parse --revs-only.\n\n TODO         |    2 --\n cg-object-id |   58 ++++++++++++++++------------------------------------------\n 2 files changed, 16 insertions(+), 44 deletions(-)\n\ndiff --git a/TODO b/TODO\nindex 0658b39..26bb4d0 100644\n--- a/TODO\n+++ b/TODO\n@@ -27,8 +27,6 @@ cg-*patch should be pre-1.0.)\n \n \tIncludes merge-order cg-log and cg-diff checking for renames.\n \n-* Offload most of cg-object-id to git-rev-parse\n-\n * Show only first 12 (or so) nibbles of the hashes everywhere\n \tEven this might be too much, but more than this is really useless\n \tfor anyone remotely human. And it's less scary, too.\ndiff --git a/cg-object-id b/cg-object-id\nindex 1628e93..49d6d99 100755\n--- a/cg-object-id\n+++ b/cg-object-id\n@@ -40,54 +40,29 @@ deprecated_alias cg-object-id commit-id \n normalize_id()\n {\n \tlocal id=\"$1\"\n+\tlocal revid=\n+\tlocal valid=\n \n-\tif [ \"${id:(-1):1}\" = \"^\" ]; then\n-\t\t# find first parent\n-\t\tnormalize_id \"${id%^}\"\n-\t\tnormid=$(git-cat-file commit \"$normid\" | \\\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/$(git-symbolic-ref 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-\telif [ -r \"$_git/refs/$id\" ]; then\n-\t\tread id < \"$_git/refs/$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\texid=$idpref${idmatch#$_git_objects/$idpref/}\n-\t\t\t[ ${#exid} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$exid\")\" ] && id=\"$exid\"\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+\tif [ ! \"$id\" ] || [ \"$id\" = \"this\" ]; then\n+\t\tid=HEAD;\n+\tfi\n+\n+ \trevid=\"$(git-rev-parse --verify \"$id^0\" 2>/dev/null)\"\n+ \tif [ \"$revid\" ]; then\n+ \t\tid=\"$revid\"\n+\t\tvalid=1\n \tfi\n \n-\tvalid=; [ ${#id} -eq 40 ] && [ \"$(git-rev-parse --revs-only \"$id\")\" ] && valid=1\n \t# date does the wrong thing for empty and single-letter ids\n \tif [ ${#id} -gt 1 ] && [ ! \"$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\t\trevid=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)\n+\t\t\tif [ ${#revid} -eq 40 ]; then\n+\t\t\t\tid=\"$revid\"\n+\t\t\t\tvalid=1\n+\t\t\tfi\n \t\tfi\n \tfi\n \n@@ -147,7 +122,7 @@ fi\n \n \n if [ \"$show_parent\" ]; then\n-\tgit-cat-file commit \"$normid\" | awk '/^parent/{print $2};/^$/{exit}'\n+\tgit-rev-parse \"$normid^\"\n \texit 0\n fi\n \n@@ -170,4 +145,3 @@ else\n fi\n \n echo $normid\n-\n-- \nJonas Fonseca\n"},{"id":"13490","messageId":"20051211183107.GC2960@diku.dk","threadId":"2769","inReplyTo":"20051211181901.GA2960@diku.dk","subject":"[PATCH] cg-object-id: use git-rev-parse(1) for date parsing","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-12-11T18:31:07Z","receivedAt":"2005-12-11T18:31:07Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Using the --until switch, git-rev-parse(1) will first be given the ID.\nIf it cannot make sense of the ID fallback to using date(1).\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n \n---\n \ndiff --git a/cg-object-id b/cg-object-id\nindex 49d6d99..4e3a3e2 100755\n--- a/cg-object-id\n+++ b/cg-object-id\n@@ -55,7 +55,14 @@ normalize_id()\n \n \t# date does the wrong thing for empty and single-letter ids\n \tif [ ${#id} -gt 1 ] && [ ! \"$valid\" ]; then\n-\t\treqsecs=$(date --date=\"$id\" +'%s' 2>/dev/null)\n+\t\tcursecs=$(git-rev-parse --until=yksap); cursecs=${cursecs:10}\n+\t\treqsecs=$(git-rev-parse --until=\"$id\"); reqsecs=${reqsecs:10}\n+ \n+\t\t# git-rev-parse(1) will output the current time if the ID\n+\t\t# doesn't make sense. Workaround it so date(1) can have a try.\n+\t\tif [ \"$cursecs\" -le \"$reqsecs\" ]; then\n+\t\t\treqsecs=$(date --date=\"$id\" +'%s' 2>/dev/null)\n+\t\tfi\n \n \t\tif [ \"$reqsecs\" ]; then\n \t\t\trevid=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)\n\n-- \nJonas Fonseca\n"}]}