From: Junio C Hamano Date: Fri, 1 Nov 2013 14:38:41 +0000 (-0700) Subject: Merge branch 'jk/for-each-ref-skip-parsing' X-Git-Tag: v1.8.5-rc1~18 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c167b76a6249ed0eb4bedd11c5852b2818c276f7?ds=inline;hp=-c Merge branch 'jk/for-each-ref-skip-parsing' * jk/for-each-ref-skip-parsing: for-each-ref: avoid loading objects to print %(objectname) --- c167b76a6249ed0eb4bedd11c5852b2818c276f7 diff --combined builtin/for-each-ref.c index 1d4083c2dd,b84b6c11eb..d096051b15 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@@ -205,6 -205,22 +205,22 @@@ static void *get_obj(const unsigned cha return buf; } + static int grab_objectname(const char *name, const unsigned char *sha1, + struct atom_value *v) + { + if (!strcmp(name, "objectname")) { + char *s = xmalloc(41); + strcpy(s, sha1_to_hex(sha1)); + v->s = s; + return 1; + } + if (!strcmp(name, "objectname:short")) { + v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); + return 1; + } + return 0; + } + /* See grab_values */ static void grab_common_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz) { @@@ -225,15 -241,8 +241,8 @@@ v->ul = sz; v->s = s; } - else if (!strcmp(name, "objectname")) { - char *s = xmalloc(41); - strcpy(s, sha1_to_hex(obj->sha1)); - v->s = s; - } - else if (!strcmp(name, "objectname:short")) { - v->s = xstrdup(find_unique_abbrev(obj->sha1, - DEFAULT_ABBREV)); - } + else if (deref) + grab_objectname(name, obj->sha1, v); } } @@@ -676,6 -685,8 +685,8 @@@ static void populate_value(struct refin } continue; } + else if (!deref && grab_objectname(name, ref->objectname, v)) + continue; else continue; @@@ -867,29 -878,24 +878,29 @@@ static void sort_refs(struct ref_sort * static void print_value(struct refinfo *ref, int atom, int quote_style) { struct atom_value *v; + struct strbuf sb = STRBUF_INIT; get_value(ref, atom, &v); switch (quote_style) { case QUOTE_NONE: fputs(v->s, stdout); break; case QUOTE_SHELL: - sq_quote_print(stdout, v->s); + sq_quote_buf(&sb, v->s); break; case QUOTE_PERL: - perl_quote_print(stdout, v->s); + perl_quote_buf(&sb, v->s); break; case QUOTE_PYTHON: - python_quote_print(stdout, v->s); + python_quote_buf(&sb, v->s); break; case QUOTE_TCL: - tcl_quote_print(stdout, v->s); + tcl_quote_buf(&sb, v->s); break; } + if (quote_style != QUOTE_NONE) { + fputs(sb.buf, stdout); + strbuf_release(&sb); + } } static int hex1(char ch)