Merge branch 'ak/maint-for-each-ref-no-lookup'
authorJunio C Hamano <gitster@pobox.com>
Thu, 18 Jun 2009 17:33:09 +0000 (10:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Jun 2009 17:33:09 +0000 (10:33 -0700)
* ak/maint-for-each-ref-no-lookup:
for-each-ref: Do not lookup objects when they will not be used

1  2 
builtin-for-each-ref.c
diff --combined builtin-for-each-ref.c
index 784733b25d21f292c6ac895ba34d0a7b88b3073f,1911cda1c29ef4cb6f0785226efcb1d3cb07ef3e..d7cc8cafbfb4ea39e347828013b28d21cfe2be74
@@@ -561,14 -561,6 +561,6 @@@ static void populate_value(struct refin
  
        ref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);
  
-       buf = get_obj(ref->objectname, &obj, &size, &eaten);
-       if (!buf)
-               die("missing object %s for %s",
-                   sha1_to_hex(ref->objectname), ref->refname);
-       if (!obj)
-               die("parse_object_buffer failed on %s for %s",
-                   sha1_to_hex(ref->objectname), ref->refname);
        /* Fill in specials first */
        for (i = 0; i < used_atom_cnt; i++) {
                const char *name = used_atom[i];
                }
        }
  
+       for (i = 0; i < used_atom_cnt; i++) {
+               struct atom_value *v = &ref->value[i];
+               if (v->s == NULL)
+                       goto need_obj;
+       }
+       return;
+  need_obj:
+       buf = get_obj(ref->objectname, &obj, &size, &eaten);
+       if (!buf)
+               die("missing object %s for %s",
+                   sha1_to_hex(ref->objectname), ref->refname);
+       if (!obj)
+               die("parse_object_buffer failed on %s for %s",
+                   sha1_to_hex(ref->objectname), ref->refname);
        grab_values(ref->value, 0, obj, buf, size);
        if (!eaten)
                free(buf);
@@@ -905,7 -913,7 +913,7 @@@ int cmd_for_each_ref(int argc, const ch
                OPT_END(),
        };
  
 -      parse_options(argc, argv, opts, for_each_ref_usage, 0);
 +      parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
        if (maxcount < 0) {
                error("invalid --count argument: `%d'", maxcount);
                usage_with_options(for_each_ref_usage, opts);
  
        memset(&cbdata, 0, sizeof(cbdata));
        cbdata.grab_pattern = argv;
-       for_each_ref(grab_single_ref, &cbdata);
+       for_each_rawref(grab_single_ref, &cbdata);
        refs = cbdata.grab_array;
        num_refs = cbdata.grab_cnt;