@matheusbsbs / matheus-bagliano / commits / 26cdd1e7c7
Fork 0

avoid accessing _all_ loose refs in git-show-ref --verify

If you want to verify a ref, it is overkill to first read all loose refs into a linked list, and then check if the desired ref is there. Signed-off-by: Junio C Hamano <junkio@cox.net> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

Junio C Hamano committed Dec 17, 2006 at 18:08 UTC 26cdd1e7c7a21b6d71ebc201fc2472a6a68f5ce4
1 file changed +17
builtin-show-ref.c
+17
@@ -213,6 +213,23 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
213 return exclude_existing(arg + 19);
214 usage(show_ref_usage);
215 }
216 +
217 + if (verify) {
218 + unsigned char sha1[20];
219 +
220 + while (*pattern) {
221 + if (resolve_ref(*pattern, sha1, 1, NULL))
222 + printf("%s %s\n", sha1_to_hex(sha1),
223 + *pattern);
224 + else if (!quiet)
225 + die("'%s' - not a valid ref", *pattern);
226 + else
227 + return 1;
228 + pattern++;
229 + }
230 + return 0;
231 + }
232 +
233 if (show_head)
234 head_ref(show_ref, NULL);
235 for_each_ref(show_ref, NULL);