{"thread":{"id":"43398","subject":"Re: [PATCH] do_for_each_ref: perform the same sanity check for leftovers.","startedAt":"2006-11-19T06:13:33Z","lastAt":"2006-11-19T06:22:17Z","messageCount":3,"participants":["Shawn Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"296445","messageId":"7vr6w07ylu.fsf@assigned-by-dhcp.cox.net","threadId":"43398","inReplyTo":null,"subject":"[PATCH] do_for_each_ref: perform the same sanity check for leftovers.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-19T06:13:33Z","receivedAt":"2006-11-19T06:13:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"An earlier commit b37a562a added a check to see if the ref\npoints at a valid object (as a part of 'negative ref' support\nwhich we currently do not use), but did so only while iterating\nover both packed and loose refs, and forgot to apply the same\ncheck while iterating over the remaining ones.\n\nWe might want to replace the \"if null then omit it\" check with\n\"eh --- what business does a 0{40} value have here?\" complaint\nlater since we currently do not use negative refs, but that is\na separate issue.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * \"pickaxe -L'/^static int do_for_each_ref/,+40' refs.c\" turns\n   out to be a very handy way to find out why a line I am\n   interested in is in that shape.\n\n   But it might be even better if it allowed us to say\n   '-L/^static int do_for_each_ref/+20,+20'.\n\ndiff --git a/refs.c b/refs.c\nindex f003a0b..6abd12f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -322,6 +322,20 @@ int read_ref(const char *ref, unsigned c\n \treturn -1;\n }\n \n+static inline int do_one_ref(const char *base, each_ref_fn fn, int trim,\n+\t\t\t     void *cb_data, struct ref_list *entry)\n+{\n+\tif (strncmp(base, entry->name, trim))\n+\t\treturn 0;\n+\tif (is_null_sha1(entry->sha1))\n+\t\treturn 0;\n+\tif (!has_sha1_file(entry->sha1)) {\n+\t\terror(\"%s does not point to a valid object!\", entry->name);\n+\t\treturn 0;\n+\t}\n+\treturn fn(entry->name + trim, entry->sha1, entry->flag, cb_data);\n+}\n+\n static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,\n \t\t\t   void *cb_data)\n {\n@@ -343,29 +357,15 @@ static int do_for_each_ref(const char *b\n \t\t\tentry = packed;\n \t\t\tpacked = packed->next;\n \t\t}\n-\t\tif (strncmp(base, entry->name, trim))\n-\t\t\tcontinue;\n-\t\tif (is_null_sha1(entry->sha1))\n-\t\t\tcontinue;\n-\t\tif (!has_sha1_file(entry->sha1)) {\n-\t\t\terror(\"%s does not point to a valid object!\", entry->name);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tretval = fn(entry->name + trim, entry->sha1,\n-\t\t\t    entry->flag, cb_data);\n+\t\tretval = do_one_ref(base, fn, trim, cb_data, entry);\n \t\tif (retval)\n \t\t\treturn retval;\n \t}\n \n-\tpacked = packed ? packed : loose;\n-\twhile (packed) {\n-\t\tif (!strncmp(base, packed->name, trim)) {\n-\t\t\tretval = fn(packed->name + trim, packed->sha1,\n-\t\t\t\t    packed->flag, cb_data);\n-\t\t\tif (retval)\n-\t\t\t\treturn retval;\n-\t\t}\n-\t\tpacked = packed->next;\n+\tfor (packed = packed ? packed : loose; packed; packed = packed->next) {\n+\t\tretval = do_one_ref(base, fn, trim, cb_data, packed);\n+\t\tif (retval)\n+\t\t\treturn retval;\n \t}\n \treturn 0;\n }\n"},{"id":"294616","messageId":"20061119061905.GB26670@spearce.org","threadId":"43398","inReplyTo":"7vr6w07ylu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] do_for_each_ref: perform the same sanity check for leftovers.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-19T06:19:05Z","receivedAt":"2006-11-19T06:19:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n>  * \"pickaxe -L'/^static int do_for_each_ref/,+40' refs.c\" turns\n\nWhat's this pickaxe you speak of?  Last I read you deleted it when\nyou renamed git-pickaxe to git-blame.\n\nHave you reinvented git-pickaxe so soon?  Maybe we could try using\ngit-longblade next time a new comamnd is being developed?  :-)\n\n-- \n"},{"id":"295115","messageId":"7vmz6o7y7a.fsf@assigned-by-dhcp.cox.net","threadId":"43398","inReplyTo":"20061119061905.GB26670@spearce.org","subject":"Re: [PATCH] do_for_each_ref: perform the same sanity check for leftovers.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-19T06:22:17Z","receivedAt":"2006-11-19T06:22:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>>  * \"pickaxe -L'/^static int do_for_each_ref/,+40' refs.c\" turns\n>\n> What's this pickaxe you speak of?  Last I read you deleted it when\n> you renamed git-pickaxe to git-blame.\n>\n> Have you reinvented git-pickaxe so soon?  Maybe we could try using\n> git-longblade next time a new comamnd is being developed?  :-)\n\nOh, no, I meant \"blame\".\n"}]}