{"thread":{"id":"12427","subject":"[PATCH] git-submodule: Don't blame when git-describe fails","startedAt":"2008-03-02T14:45:52Z","lastAt":"2008-03-02T22:41:52Z","messageCount":4,"participants":["Ping Yin","Junio C Hamano","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"70641","messageId":"1204469152-24227-1-git-send-email-pkufranky@gmail.com","threadId":"12427","inReplyTo":null,"subject":"[PATCH] git-submodule: Don't blame when git-describe fails","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-03-02T14:45:52Z","receivedAt":"2008-03-02T14:45:52Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"Avoid 'fatal: cannot describe' message\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex a6aaf40..5e8b84f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -315,7 +315,7 @@ set_name_rev () {\n \t\tcd \"$1\" && {\n \t\t\tgit describe \"$2\" 2>/dev/null ||\n \t\t\tgit describe --tags \"$2\" 2>/dev/null ||\n-\t\t\tgit describe --contains --tags \"$2\"\n+\t\t\tgit describe --contains --tags \"$2\" 2>/dev/null\n \t\t}\n \t) )\n \ttest -z \"$revname\" || revname=\" ($revname)\"\n-- \n1.5.4.3.347.g5314c\n\n"},{"id":"70662","messageId":"7vy791oyqa.fsf@gitster.siamese.dyndns.org","threadId":"12427","inReplyTo":"1204469152-24227-1-git-send-email-pkufranky@gmail.com","subject":"Re* [PATCH] git-submodule: Don't blame when git-describe fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-02T16:51:57Z","receivedAt":"2008-03-02T16:51:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ping Yin <pkufranky@gmail.com> writes:\n\n> Avoid 'fatal: cannot describe' message\n>\n> Signed-off-by: Ping Yin <pkufranky@gmail.com>\n\nI see you reworded the commit log somewhat in your second attempt.  I\nwould have written it this way, though:\n\n    git-submodule: Avoid 'fatal: cannot describe' message\n    \n    When \"git submodule status\" command tries to show the name of the\n    submodule HEAD revision more descriptively, but the submodule\n    repository lacked a suitable tag to do so, it leaked \"fatal: cannot\n    describe\" message to the UI.  Squelch it.\n\nThis however makes me wonder if describe or name-rev already has a\nsuitable option to fall back on showing a unique abbrev when the thing\ncannot be described.\n\nIf not already, perhaps it should learn how.  This is untested, does not\ncome with tests nor documentation, but I'll leave them to interested\nreaders as exercises ;-)\n\n-- >8 --\ndescribe --always: fall back to showing an abbreviated object name\n\nSome callers may find it useful if \"git describe\" always gave back a\nstring that can be used as a shorter name for a commit object, rather than\nchecking its exit status (while squelching its error message, which could\npotentially talk about more grave errors that should not be squelched) and\nimplementing a fallback themselves.\n\nThis teaches describe/name-rev a new option, --always, to use an\nabbreviated object name when no tags or refs to use is found.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-describe.c |   20 +++++++++++++++-\n builtin-name-rev.c |   59 ++++++++++++++++++++++++++-------------------------\n 2 files changed, 48 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex 05e309f..c1182a3 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -20,6 +20,7 @@ static int tags;\t/* But allow any tags if --tags is specified */\n static int abbrev = DEFAULT_ABBREV;\n static int max_candidates = 10;\n const char *pattern = NULL;\n+static int always;\n \n struct commit_name {\n \tint prio; /* annotated tag = 2, tag = 1, head = 0 */\n@@ -146,6 +147,17 @@ static unsigned long finish_depth_computation(\n \treturn seen_commits;\n }\n \n+static void cannot_describe(const unsigned char *sha1) NORETURN;\n+\n+static void cannot_describe(const unsigned char *sha1)\n+{\n+\tif (always) {\n+\t\tprintf(\"%s\\n\", find_unique_abbrev(sha1, DEFAULT_ABBREV));\n+\t\texit(0);\n+\t}\n+\tdie(\"cannot describe '%s'\", sha1_to_hex(sha1));\n+}\n+\n static void describe(const char *arg, int last_one)\n {\n \tunsigned char sha1[20];\n@@ -225,7 +237,7 @@ static void describe(const char *arg, int last_one)\n \t}\n \n \tif (!match_cnt)\n-\t\tdie(\"cannot describe '%s'\", sha1_to_hex(cmit->object.sha1));\n+\t\tcannot_describe(cmit->object.sha1);\n \n \tqsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);\n \n@@ -278,6 +290,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\t    \"consider <n> most recent tags (default: 10)\"),\n \t\tOPT_STRING(0, \"match\",       &pattern, \"pattern\",\n \t\t\t   \"only consider tags matching <pattern>\"),\n+\t\tOPT_BOOLEAN(0, \"always\",     &always,\n+\t\t\t   \"show abbreviated commit object as fallback\"),\n \t\tOPT_END(),\n \t};\n \n@@ -290,11 +304,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \tsave_commit_buffer = 0;\n \n \tif (contains) {\n-\t\tconst char **args = xmalloc((6 + argc) * sizeof(char*));\n+\t\tconst char **args = xmalloc((7 + argc) * sizeof(char*));\n \t\tint i = 0;\n \t\targs[i++] = \"name-rev\";\n \t\targs[i++] = \"--name-only\";\n \t\targs[i++] = \"--no-undefined\";\n+\t\tif (always)\n+\t\t\targs[i++] = \"--always\";\n \t\tif (!all) {\n \t\t\targs[i++] = \"--tags\";\n \t\t\tif (pattern) {\ndiff --git a/builtin-name-rev.c b/builtin-name-rev.c\nindex f22c8b5..384da4d 100644\n--- a/builtin-name-rev.c\n+++ b/builtin-name-rev.c\n@@ -125,7 +125,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n }\n \n /* returns a static buffer */\n-static const char *get_rev_name(struct object *o)\n+static const char *get_rev_name(const struct object *o)\n {\n \tstatic char buffer[1024];\n \tstruct rev_name *n;\n@@ -151,6 +151,26 @@ static const char *get_rev_name(struct object *o)\n \t}\n }\n \n+static void show_name(const struct object *obj,\n+\t\t      const char *caller_name,\n+\t\t      int always, int allow_undefined, int name_only)\n+{\n+\tconst char *name;\n+\tconst unsigned char *sha1 = obj->sha1;\n+\n+\tif (!name_only)\n+\t\tprintf(\"%s \", caller_name ? caller_name : sha1_to_hex(sha1));\n+\tname = get_rev_name(obj);\n+\tif (name)\n+\t\tprintf(\"%s\\n\", name);\n+\telse if (allow_undefined)\n+\t\tprintf(\"undefined\\n\");\n+\telse if (always)\n+\t\tprintf(\"%s\\n\", find_unique_abbrev(sha1, DEFAULT_ABBREV));\n+\telse\n+\t\tdie(\"cannot describe '%s'\", sha1_to_hex(sha1));\n+}\n+\n static char const * const name_rev_usage[] = {\n \t\"git-name-rev [options] ( --all | --stdin | <commit>... )\",\n \tNULL\n@@ -159,7 +179,7 @@ static char const * const name_rev_usage[] = {\n int cmd_name_rev(int argc, const char **argv, const char *prefix)\n {\n \tstruct object_array revs = { 0, 0, NULL };\n-\tint all = 0, transform_stdin = 0, allow_undefined = 1;\n+\tint all = 0, transform_stdin = 0, allow_undefined = 1, always = 0;\n \tstruct name_ref_data data = { 0, 0, NULL };\n \tstruct option opts[] = {\n \t\tOPT_BOOLEAN(0, \"name-only\", &data.name_only, \"print only names (no SHA-1)\"),\n@@ -170,6 +190,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOLEAN(0, \"all\", &all, \"list all commits reachable from all refs\"),\n \t\tOPT_BOOLEAN(0, \"stdin\", &transform_stdin, \"read from stdin\"),\n \t\tOPT_BOOLEAN(0, \"undefined\", &allow_undefined, \"allow to print `undefined` names\"),\n+\t\tOPT_BOOLEAN(0, \"always\",     &always,\n+\t\t\t   \"show abbreviated commit object as fallback\"),\n \t\tOPT_END(),\n \t};\n \n@@ -258,35 +280,14 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)\n \t\tint i, max;\n \n \t\tmax = get_max_object_index();\n-\t\tfor (i = 0; i < max; i++) {\n-\t\t\tstruct object * obj = get_indexed_object(i);\n-\t\t\tconst char *name;\n-\t\t\tif (!obj)\n-\t\t\t\tcontinue;\n-\t\t\tif (!data.name_only)\n-\t\t\t\tprintf(\"%s \", sha1_to_hex(obj->sha1));\n-\t\t\tname = get_rev_name(obj);\n-\t\t\tif (name)\n-\t\t\t\tprintf(\"%s\\n\", name);\n-\t\t\telse if (allow_undefined)\n-\t\t\t\tprintf(\"undefined\\n\");\n-\t\t\telse\n-\t\t\t\tdie(\"cannot describe '%s'\", sha1_to_hex(obj->sha1));\n-\t\t}\n+\t\tfor (i = 0; i < max; i++)\n+\t\t\tshow_name(get_indexed_object(i), NULL,\n+\t\t\t\t  always, allow_undefined, data.name_only);\n \t} else {\n \t\tint i;\n-\t\tfor (i = 0; i < revs.nr; i++) {\n-\t\t\tconst char *name;\n-\t\t\tif (!data.name_only)\n-\t\t\t\tprintf(\"%s \", revs.objects[i].name);\n-\t\t\tname = get_rev_name(revs.objects[i].item);\n-\t\t\tif (name)\n-\t\t\t\tprintf(\"%s\\n\", name);\n-\t\t\telse if (allow_undefined)\n-\t\t\t\tprintf(\"undefined\\n\");\n-\t\t\telse\n-\t\t\t\tdie(\"cannot describe '%s'\", sha1_to_hex(revs.objects[i].item->sha1));\n-\t\t}\n+\t\tfor (i = 0; i < revs.nr; i++)\n+\t\t\tshow_name(revs.objects[i].item, revs.objects[i].name,\n+\t\t\t\t  always, allow_undefined, data.name_only);\n \t}\n \n \treturn 0;\n"},{"id":"70671","messageId":"46dff0320803020917s154c204cl56d85e47de892173@mail.gmail.com","threadId":"12427","inReplyTo":"7vy791oyqa.fsf@gitster.siamese.dyndns.org","subject":"Re: Re* [PATCH] git-submodule: Don't blame when git-describe fails","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-03-02T17:17:16Z","receivedAt":"2008-03-02T17:17:16Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On 3/3/08, Junio C Hamano <gitster@pobox.com> wrote:\n> Ping Yin <pkufranky@gmail.com> writes:\n>\n> > Avoid 'fatal: cannot describe' message\n> >\n> > Signed-off-by: Ping Yin <pkufranky@gmail.com>\n>\n> I see you reworded the commit log somewhat in your second attempt.  I\n> would have written it this way, though:\n>\n>    git-submodule: Avoid 'fatal: cannot describe' message\n>\n>    When \"git submodule status\" command tries to show the name of the\n>    submodule HEAD revision more descriptively, but the submodule\n>    repository lacked a suitable tag to do so, it leaked \"fatal: cannot\n>    describe\" message to the UI.  Squelch it.\n>\nThat's ok. You can sign off it.\n\n-- \nPing Yin\n"},{"id":"70708","messageId":"20080302224152.GC8410@spearce.org","threadId":"12427","inReplyTo":"7vy791oyqa.fsf@gitster.siamese.dyndns.org","subject":"Re: Re* [PATCH] git-submodule: Don't blame when git-describe fails","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-03-02T22:41:52Z","receivedAt":"2008-03-02T22:41:52Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> -- >8 --\n> describe --always: fall back to showing an abbreviated object name\n...\n> diff --git a/builtin-describe.c b/builtin-describe.c\n> index 05e309f..c1182a3 100644\n> --- a/builtin-describe.c\n> +++ b/builtin-describe.c\n> @@ -146,6 +147,17 @@ static unsigned long finish_depth_computation(\n>  \treturn seen_commits;\n>  }\n>  \n> +static void cannot_describe(const unsigned char *sha1) NORETURN;\n> +\n> +static void cannot_describe(const unsigned char *sha1)\n> +{\n> +\tif (always) {\n> +\t\tprintf(\"%s\\n\", find_unique_abbrev(sha1, DEFAULT_ABBREV));\n\nThis should be \"abbrev\" not \"DEFAULT_ABBREV\" as then we honor the\ncommand line \"describe --always --abbrev=16\" (for example).\n\n> @@ -278,6 +290,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>  \t\t\t    \"consider <n> most recent tags (default: 10)\"),\n>  \t\tOPT_STRING(0, \"match\",       &pattern, \"pattern\",\n>  \t\t\t   \"only consider tags matching <pattern>\"),\n> +\t\tOPT_BOOLEAN(0, \"always\",     &always,\n> +\t\t\t   \"show abbreviated commit object as fallback\"),\n>  \t\tOPT_END(),\n>  \t};\n  \nSadly I cannot come up with a better name for this option.  :-(\n\n-- \nShawn.\n"}]}