10 #include "parse-options.h"
17 #define QUOTE_PYTHON 4
20 typedef enum { FIELD_STR
, FIELD_ULONG
, FIELD_TIME
} cmp_type
;
24 unsigned long ul
; /* used for sorting when not FIELD_STR */
28 struct ref_sort
*next
;
29 int atom
; /* index into used_atom array */
35 unsigned char objectname
[20];
38 struct atom_value
*value
;
47 { "objectsize", FIELD_ULONG
},
51 { "numparent", FIELD_ULONG
},
58 { "authordate", FIELD_TIME
},
62 { "committerdate", FIELD_TIME
},
66 { "taggerdate", FIELD_TIME
},
68 { "creatordate", FIELD_TIME
},
78 * An atom is a valid field atom listed above, possibly prefixed with
79 * a "*" to denote deref_tag().
81 * We parse given format string and sort specifiers, and make a list
82 * of properties that we need to extract out of objects. refinfo
83 * structure will hold an array of values extracted that can be
84 * indexed with the "atom number", which is an index into this
87 static const char **used_atom
;
88 static cmp_type
*used_atom_type
;
89 static int used_atom_cnt
, sort_atom_limit
, need_tagged
, need_symref
;
92 * Used to parse format string and sort specifiers
94 static int parse_atom(const char *atom
, const char *ep
)
100 if (*sp
== '*' && sp
< ep
)
103 die("malformed field name: %.*s", (int)(ep
-atom
), atom
);
105 /* Do we have the atom already used elsewhere? */
106 for (i
= 0; i
< used_atom_cnt
; i
++) {
107 int len
= strlen(used_atom
[i
]);
108 if (len
== ep
- atom
&& !memcmp(used_atom
[i
], atom
, len
))
112 /* Is the atom a valid one? */
113 for (i
= 0; i
< ARRAY_SIZE(valid_atom
); i
++) {
114 int len
= strlen(valid_atom
[i
].name
);
116 * If the atom name has a colon, strip it and everything after
117 * it off - it specifies the format for this entry, and
118 * shouldn't be used for checking against the valid_atom
121 const char *formatp
= strchr(sp
, ':');
122 if (!formatp
|| ep
< formatp
)
124 if (len
== formatp
- sp
&& !memcmp(valid_atom
[i
].name
, sp
, len
))
128 if (ARRAY_SIZE(valid_atom
) <= i
)
129 die("unknown field name: %.*s", (int)(ep
-atom
), atom
);
131 /* Add it in, including the deref prefix */
134 used_atom
= xrealloc(used_atom
,
135 (sizeof *used_atom
) * used_atom_cnt
);
136 used_atom_type
= xrealloc(used_atom_type
,
137 (sizeof(*used_atom_type
) * used_atom_cnt
));
138 used_atom
[at
] = xmemdupz(atom
, ep
- atom
);
139 used_atom_type
[at
] = valid_atom
[i
].cmp_type
;
142 if (!strcmp(used_atom
[at
], "symref"))
148 * In a format string, find the next occurrence of %(atom).
150 static const char *find_next(const char *cp
)
155 * %( is the start of an atom;
156 * %% is a quoted per-cent.
160 else if (cp
[1] == '%')
161 cp
++; /* skip over two % */
162 /* otherwise this is a singleton, literal % */
170 * Make sure the format string is well formed, and parse out
173 static int verify_format(const char *format
)
176 for (cp
= format
; *cp
&& (sp
= find_next(cp
)); ) {
177 const char *ep
= strchr(sp
, ')');
179 return error("malformed format string %s", sp
);
180 /* sp points at "%(" and ep points at the closing ")" */
181 parse_atom(sp
+ 2, ep
);
188 * Given an object name, read the object data and size, and return a
189 * "struct object". If the object data we are returning is also borrowed
190 * by the "struct object" representation, set *eaten as well---it is a
191 * signal from parse_object_buffer to us not to free the buffer.
193 static void *get_obj(const unsigned char *sha1
, struct object
**obj
, unsigned long *sz
, int *eaten
)
195 enum object_type type
;
196 void *buf
= read_sha1_file(sha1
, &type
, sz
);
199 *obj
= parse_object_buffer(sha1
, type
, *sz
, buf
, eaten
);
205 /* See grab_values */
206 static void grab_common_values(struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
210 for (i
= 0; i
< used_atom_cnt
; i
++) {
211 const char *name
= used_atom
[i
];
212 struct atom_value
*v
= &val
[i
];
213 if (!!deref
!= (*name
== '*'))
217 if (!strcmp(name
, "objecttype"))
218 v
->s
= typename(obj
->type
);
219 else if (!strcmp(name
, "objectsize")) {
220 char *s
= xmalloc(40);
221 sprintf(s
, "%lu", sz
);
225 else if (!strcmp(name
, "objectname")) {
226 char *s
= xmalloc(41);
227 strcpy(s
, sha1_to_hex(obj
->sha1
));
230 else if (!strcmp(name
, "objectname:short")) {
231 v
->s
= xstrdup(find_unique_abbrev(obj
->sha1
,
237 /* See grab_values */
238 static void grab_tag_values(struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
241 struct tag
*tag
= (struct tag
*) obj
;
243 for (i
= 0; i
< used_atom_cnt
; i
++) {
244 const char *name
= used_atom
[i
];
245 struct atom_value
*v
= &val
[i
];
246 if (!!deref
!= (*name
== '*'))
250 if (!strcmp(name
, "tag"))
252 else if (!strcmp(name
, "type") && tag
->tagged
)
253 v
->s
= typename(tag
->tagged
->type
);
254 else if (!strcmp(name
, "object") && tag
->tagged
) {
255 char *s
= xmalloc(41);
256 strcpy(s
, sha1_to_hex(tag
->tagged
->sha1
));
262 static int num_parents(struct commit
*commit
)
264 struct commit_list
*parents
;
267 for (i
= 0, parents
= commit
->parents
;
269 parents
= parents
->next
)
274 /* See grab_values */
275 static void grab_commit_values(struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
278 struct commit
*commit
= (struct commit
*) obj
;
280 for (i
= 0; i
< used_atom_cnt
; i
++) {
281 const char *name
= used_atom
[i
];
282 struct atom_value
*v
= &val
[i
];
283 if (!!deref
!= (*name
== '*'))
287 if (!strcmp(name
, "tree")) {
288 char *s
= xmalloc(41);
289 strcpy(s
, sha1_to_hex(commit
->tree
->object
.sha1
));
292 if (!strcmp(name
, "numparent")) {
293 char *s
= xmalloc(40);
294 v
->ul
= num_parents(commit
);
295 sprintf(s
, "%lu", v
->ul
);
298 else if (!strcmp(name
, "parent")) {
299 int num
= num_parents(commit
);
301 struct commit_list
*parents
;
302 char *s
= xmalloc(41 * num
+ 1);
304 for (i
= 0, parents
= commit
->parents
;
306 parents
= parents
->next
, i
= i
+ 41) {
307 struct commit
*parent
= parents
->item
;
308 strcpy(s
+i
, sha1_to_hex(parent
->object
.sha1
));
318 static const char *find_wholine(const char *who
, int wholen
, const char *buf
, unsigned long sz
)
322 if (!strncmp(buf
, who
, wholen
) &&
324 return buf
+ wholen
+ 1;
325 eol
= strchr(buf
, '\n');
330 return ""; /* end of header */
336 static const char *copy_line(const char *buf
)
338 const char *eol
= strchrnul(buf
, '\n');
339 return xmemdupz(buf
, eol
- buf
);
342 static const char *copy_name(const char *buf
)
345 for (cp
= buf
; *cp
&& *cp
!= '\n'; cp
++) {
346 if (!strncmp(cp
, " <", 2))
347 return xmemdupz(buf
, cp
- buf
);
352 static const char *copy_email(const char *buf
)
354 const char *email
= strchr(buf
, '<');
358 eoemail
= strchr(email
, '>');
361 return xmemdupz(email
, eoemail
+ 1 - email
);
364 static char *copy_subject(const char *buf
, unsigned long len
)
366 char *r
= xmemdupz(buf
, len
);
369 for (i
= 0; i
< len
; i
++)
376 static void grab_date(const char *buf
, struct atom_value
*v
, const char *atomname
)
378 const char *eoemail
= strstr(buf
, "> ");
380 unsigned long timestamp
;
382 enum date_mode date_mode
= DATE_NORMAL
;
386 * We got here because atomname ends in "date" or "date<something>";
387 * it's not possible that <something> is not ":<format>" because
388 * parse_atom() wouldn't have allowed it, so we can assume that no
389 * ":" means no format is specified, and use the default.
391 formatp
= strchr(atomname
, ':');
392 if (formatp
!= NULL
) {
394 date_mode
= parse_date_format(formatp
);
399 timestamp
= strtoul(eoemail
+ 2, &zone
, 10);
400 if (timestamp
== ULONG_MAX
)
402 tz
= strtol(zone
, NULL
, 10);
403 if ((tz
== LONG_MIN
|| tz
== LONG_MAX
) && errno
== ERANGE
)
405 v
->s
= xstrdup(show_date(timestamp
, tz
, date_mode
));
413 /* See grab_values */
414 static void grab_person(const char *who
, struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
417 int wholen
= strlen(who
);
418 const char *wholine
= NULL
;
420 for (i
= 0; i
< used_atom_cnt
; i
++) {
421 const char *name
= used_atom
[i
];
422 struct atom_value
*v
= &val
[i
];
423 if (!!deref
!= (*name
== '*'))
427 if (strncmp(who
, name
, wholen
))
429 if (name
[wholen
] != 0 &&
430 strcmp(name
+ wholen
, "name") &&
431 strcmp(name
+ wholen
, "email") &&
432 prefixcmp(name
+ wholen
, "date"))
435 wholine
= find_wholine(who
, wholen
, buf
, sz
);
437 return; /* no point looking for it */
438 if (name
[wholen
] == 0)
439 v
->s
= copy_line(wholine
);
440 else if (!strcmp(name
+ wholen
, "name"))
441 v
->s
= copy_name(wholine
);
442 else if (!strcmp(name
+ wholen
, "email"))
443 v
->s
= copy_email(wholine
);
444 else if (!prefixcmp(name
+ wholen
, "date"))
445 grab_date(wholine
, v
, name
);
449 * For a tag or a commit object, if "creator" or "creatordate" is
450 * requested, do something special.
452 if (strcmp(who
, "tagger") && strcmp(who
, "committer"))
453 return; /* "author" for commit object is not wanted */
455 wholine
= find_wholine(who
, wholen
, buf
, sz
);
458 for (i
= 0; i
< used_atom_cnt
; i
++) {
459 const char *name
= used_atom
[i
];
460 struct atom_value
*v
= &val
[i
];
461 if (!!deref
!= (*name
== '*'))
466 if (!prefixcmp(name
, "creatordate"))
467 grab_date(wholine
, v
, name
);
468 else if (!strcmp(name
, "creator"))
469 v
->s
= copy_line(wholine
);
473 static void find_subpos(const char *buf
, unsigned long sz
,
474 const char **sub
, unsigned long *sublen
,
475 const char **body
, unsigned long *bodylen
)
478 /* skip past header until we hit empty line */
479 while (*buf
&& *buf
!= '\n') {
480 eol
= strchrnul(buf
, '\n');
485 /* skip any empty lines */
489 /* subject is first non-empty line */
491 /* subject goes to first empty line */
492 while (*buf
&& *buf
!= '\n') {
493 eol
= strchrnul(buf
, '\n');
498 *sublen
= buf
- *sub
;
499 /* drop trailing newline, if present */
500 if (*sublen
&& (*sub
)[*sublen
- 1] == '\n')
503 /* skip any empty lines */
507 *bodylen
= strlen(buf
);
510 /* See grab_values */
511 static void grab_sub_body_contents(struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
514 const char *subpos
= NULL
, *bodypos
;
515 unsigned long sublen
, bodylen
;
517 for (i
= 0; i
< used_atom_cnt
; i
++) {
518 const char *name
= used_atom
[i
];
519 struct atom_value
*v
= &val
[i
];
520 if (!!deref
!= (*name
== '*'))
524 if (strcmp(name
, "subject") &&
525 strcmp(name
, "body") &&
526 strcmp(name
, "contents"))
533 if (!strcmp(name
, "subject"))
534 v
->s
= copy_subject(subpos
, sublen
);
535 else if (!strcmp(name
, "body"))
536 v
->s
= xmemdupz(bodypos
, bodylen
);
537 else if (!strcmp(name
, "contents"))
538 v
->s
= xstrdup(subpos
);
543 * We want to have empty print-string for field requests
544 * that do not apply (e.g. "authordate" for a tag object)
546 static void fill_missing_values(struct atom_value
*val
)
549 for (i
= 0; i
< used_atom_cnt
; i
++) {
550 struct atom_value
*v
= &val
[i
];
557 * val is a list of atom_value to hold returned values. Extract
558 * the values for atoms in used_atom array out of (obj, buf, sz).
559 * when deref is false, (obj, buf, sz) is the object that is
560 * pointed at by the ref itself; otherwise it is the object the
561 * ref (which is a tag) refers to.
563 static void grab_values(struct atom_value
*val
, int deref
, struct object
*obj
, void *buf
, unsigned long sz
)
565 grab_common_values(val
, deref
, obj
, buf
, sz
);
568 grab_tag_values(val
, deref
, obj
, buf
, sz
);
569 grab_sub_body_contents(val
, deref
, obj
, buf
, sz
);
570 grab_person("tagger", val
, deref
, obj
, buf
, sz
);
573 grab_commit_values(val
, deref
, obj
, buf
, sz
);
574 grab_sub_body_contents(val
, deref
, obj
, buf
, sz
);
575 grab_person("author", val
, deref
, obj
, buf
, sz
);
576 grab_person("committer", val
, deref
, obj
, buf
, sz
);
579 /* grab_tree_values(val, deref, obj, buf, sz); */
582 /* grab_blob_values(val, deref, obj, buf, sz); */
585 die("Eh? Object of type %d?", obj
->type
);
589 static inline char *copy_advance(char *dst
, const char *src
)
597 * Parse the object referred by ref, and grab needed value.
599 static void populate_value(struct refinfo
*ref
)
605 const unsigned char *tagged
;
607 ref
->value
= xcalloc(sizeof(struct atom_value
), used_atom_cnt
);
609 if (need_symref
&& (ref
->flag
& REF_ISSYMREF
) && !ref
->symref
) {
610 unsigned char unused1
[20];
612 symref
= resolve_ref(ref
->refname
, unused1
, 1, NULL
);
614 ref
->symref
= xstrdup(symref
);
619 /* Fill in specials first */
620 for (i
= 0; i
< used_atom_cnt
; i
++) {
621 const char *name
= used_atom
[i
];
622 struct atom_value
*v
= &ref
->value
[i
];
632 if (!prefixcmp(name
, "refname"))
633 refname
= ref
->refname
;
634 else if (!prefixcmp(name
, "symref"))
635 refname
= ref
->symref
? ref
->symref
: "";
636 else if (!prefixcmp(name
, "upstream")) {
637 struct branch
*branch
;
638 /* only local branches may have an upstream */
639 if (prefixcmp(ref
->refname
, "refs/heads/"))
641 branch
= branch_get(ref
->refname
+ 11);
643 if (!branch
|| !branch
->merge
|| !branch
->merge
[0] ||
644 !branch
->merge
[0]->dst
)
646 refname
= branch
->merge
[0]->dst
;
648 else if (!strcmp(name
, "flag")) {
649 char buf
[256], *cp
= buf
;
650 if (ref
->flag
& REF_ISSYMREF
)
651 cp
= copy_advance(cp
, ",symref");
652 if (ref
->flag
& REF_ISPACKED
)
653 cp
= copy_advance(cp
, ",packed");
658 v
->s
= xstrdup(buf
+ 1);
665 formatp
= strchr(name
, ':');
666 /* look for "short" refname format */
669 if (!strcmp(formatp
, "short"))
670 refname
= shorten_unambiguous_ref(refname
,
671 warn_ambiguous_refs
);
673 die("unknown %.*s format %s",
674 (int)(formatp
- name
), name
, formatp
);
680 int len
= strlen(refname
);
681 char *s
= xmalloc(len
+ 4);
682 sprintf(s
, "%s^{}", refname
);
687 for (i
= 0; i
< used_atom_cnt
; i
++) {
688 struct atom_value
*v
= &ref
->value
[i
];
695 buf
= get_obj(ref
->objectname
, &obj
, &size
, &eaten
);
697 die("missing object %s for %s",
698 sha1_to_hex(ref
->objectname
), ref
->refname
);
700 die("parse_object_buffer failed on %s for %s",
701 sha1_to_hex(ref
->objectname
), ref
->refname
);
703 grab_values(ref
->value
, 0, obj
, buf
, size
);
708 * If there is no atom that wants to know about tagged
709 * object, we are done.
711 if (!need_tagged
|| (obj
->type
!= OBJ_TAG
))
715 * If it is a tag object, see if we use a value that derefs
716 * the object, and if we do grab the object it refers to.
718 tagged
= ((struct tag
*)obj
)->tagged
->sha1
;
721 * NEEDSWORK: This derefs tag only once, which
722 * is good to deal with chains of trust, but
723 * is not consistent with what deref_tag() does
724 * which peels the onion to the core.
726 buf
= get_obj(tagged
, &obj
, &size
, &eaten
);
728 die("missing object %s for %s",
729 sha1_to_hex(tagged
), ref
->refname
);
731 die("parse_object_buffer failed on %s for %s",
732 sha1_to_hex(tagged
), ref
->refname
);
733 grab_values(ref
->value
, 1, obj
, buf
, size
);
739 * Given a ref, return the value for the atom. This lazily gets value
740 * out of the object by calling populate value.
742 static void get_value(struct refinfo
*ref
, int atom
, struct atom_value
**v
)
746 fill_missing_values(ref
->value
);
748 *v
= &ref
->value
[atom
];
751 struct grab_ref_cbdata
{
752 struct refinfo
**grab_array
;
753 const char **grab_pattern
;
758 * A call-back given to for_each_ref(). Filter refs and keep them for
759 * later object processing.
761 static int grab_single_ref(const char *refname
, const unsigned char *sha1
, int flag
, void *cb_data
)
763 struct grab_ref_cbdata
*cb
= cb_data
;
767 if (*cb
->grab_pattern
) {
768 const char **pattern
;
769 int namelen
= strlen(refname
);
770 for (pattern
= cb
->grab_pattern
; *pattern
; pattern
++) {
771 const char *p
= *pattern
;
772 int plen
= strlen(p
);
774 if ((plen
<= namelen
) &&
775 !strncmp(refname
, p
, plen
) &&
776 (refname
[plen
] == '\0' ||
777 refname
[plen
] == '/' ||
780 if (!fnmatch(p
, refname
, FNM_PATHNAME
))
788 * We do not open the object yet; sort may only need refname
789 * to do its job and the resulting list may yet to be pruned
792 ref
= xcalloc(1, sizeof(*ref
));
793 ref
->refname
= xstrdup(refname
);
794 hashcpy(ref
->objectname
, sha1
);
798 cb
->grab_array
= xrealloc(cb
->grab_array
,
799 sizeof(*cb
->grab_array
) * (cnt
+ 1));
800 cb
->grab_array
[cnt
++] = ref
;
805 static int cmp_ref_sort(struct ref_sort
*s
, struct refinfo
*a
, struct refinfo
*b
)
807 struct atom_value
*va
, *vb
;
809 cmp_type cmp_type
= used_atom_type
[s
->atom
];
811 get_value(a
, s
->atom
, &va
);
812 get_value(b
, s
->atom
, &vb
);
815 cmp
= strcmp(va
->s
, vb
->s
);
820 else if (va
->ul
== vb
->ul
)
826 return (s
->reverse
) ? -cmp
: cmp
;
829 static struct ref_sort
*ref_sort
;
830 static int compare_refs(const void *a_
, const void *b_
)
832 struct refinfo
*a
= *((struct refinfo
**)a_
);
833 struct refinfo
*b
= *((struct refinfo
**)b_
);
836 for (s
= ref_sort
; s
; s
= s
->next
) {
837 int cmp
= cmp_ref_sort(s
, a
, b
);
844 static void sort_refs(struct ref_sort
*sort
, struct refinfo
**refs
, int num_refs
)
847 qsort(refs
, num_refs
, sizeof(struct refinfo
*), compare_refs
);
850 static void print_value(struct refinfo
*ref
, int atom
, int quote_style
)
852 struct atom_value
*v
;
853 get_value(ref
, atom
, &v
);
854 switch (quote_style
) {
859 sq_quote_print(stdout
, v
->s
);
862 perl_quote_print(stdout
, v
->s
);
865 python_quote_print(stdout
, v
->s
);
868 tcl_quote_print(stdout
, v
->s
);
873 static int hex1(char ch
)
875 if ('0' <= ch
&& ch
<= '9')
877 else if ('a' <= ch
&& ch
<= 'f')
878 return ch
- 'a' + 10;
879 else if ('A' <= ch
&& ch
<= 'F')
880 return ch
- 'A' + 10;
883 static int hex2(const char *cp
)
886 return (hex1(cp
[0]) << 4) | hex1(cp
[1]);
891 static void emit(const char *cp
, const char *ep
)
893 while (*cp
&& (!ep
|| cp
< ep
)) {
898 int ch
= hex2(cp
+ 1);
911 static void show_ref(struct refinfo
*info
, const char *format
, int quote_style
)
913 const char *cp
, *sp
, *ep
;
915 for (cp
= format
; *cp
&& (sp
= find_next(cp
)); cp
= ep
+ 1) {
916 ep
= strchr(sp
, ')');
919 print_value(info
, parse_atom(sp
+ 2, ep
), quote_style
);
922 sp
= cp
+ strlen(cp
);
928 static struct ref_sort
*default_sort(void)
930 static const char cstr_name
[] = "refname";
932 struct ref_sort
*sort
= xcalloc(1, sizeof(*sort
));
935 sort
->atom
= parse_atom(cstr_name
, cstr_name
+ strlen(cstr_name
));
939 static int opt_parse_sort(const struct option
*opt
, const char *arg
, int unset
)
941 struct ref_sort
**sort_tail
= opt
->value
;
945 if (!arg
) /* should --no-sort void the list ? */
948 *sort_tail
= s
= xcalloc(1, sizeof(*s
));
955 s
->atom
= parse_atom(arg
, arg
+len
);
959 static char const * const for_each_ref_usage
[] = {
960 "git for-each-ref [options] [<pattern>]",
964 int cmd_for_each_ref(int argc
, const char **argv
, const char *prefix
)
967 const char *format
= "%(objectname) %(objecttype)\t%(refname)";
968 struct ref_sort
*sort
= NULL
, **sort_tail
= &sort
;
969 int maxcount
= 0, quote_style
= 0;
970 struct refinfo
**refs
;
971 struct grab_ref_cbdata cbdata
;
973 struct option opts
[] = {
974 OPT_BIT('s', "shell", "e_style
,
975 "quote placeholders suitably for shells", QUOTE_SHELL
),
976 OPT_BIT('p', "perl", "e_style
,
977 "quote placeholders suitably for perl", QUOTE_PERL
),
978 OPT_BIT(0 , "python", "e_style
,
979 "quote placeholders suitably for python", QUOTE_PYTHON
),
980 OPT_BIT(0 , "tcl", "e_style
,
981 "quote placeholders suitably for tcl", QUOTE_TCL
),
984 OPT_INTEGER( 0 , "count", &maxcount
, "show only <n> matched refs"),
985 OPT_STRING( 0 , "format", &format
, "format", "format to use for the output"),
986 OPT_CALLBACK(0 , "sort", sort_tail
, "key",
987 "field name to sort on", &opt_parse_sort
),
991 parse_options(argc
, argv
, prefix
, opts
, for_each_ref_usage
, 0);
993 error("invalid --count argument: `%d'", maxcount
);
994 usage_with_options(for_each_ref_usage
, opts
);
996 if (HAS_MULTI_BITS(quote_style
)) {
997 error("more than one quoting style?");
998 usage_with_options(for_each_ref_usage
, opts
);
1000 if (verify_format(format
))
1001 usage_with_options(for_each_ref_usage
, opts
);
1004 sort
= default_sort();
1005 sort_atom_limit
= used_atom_cnt
;
1007 /* for warn_ambiguous_refs */
1008 git_config(git_default_config
, NULL
);
1010 memset(&cbdata
, 0, sizeof(cbdata
));
1011 cbdata
.grab_pattern
= argv
;
1012 for_each_rawref(grab_single_ref
, &cbdata
);
1013 refs
= cbdata
.grab_array
;
1014 num_refs
= cbdata
.grab_cnt
;
1016 sort_refs(sort
, refs
, num_refs
);
1018 if (!maxcount
|| num_refs
< maxcount
)
1019 maxcount
= num_refs
;
1020 for (i
= 0; i
< maxcount
; i
++)
1021 show_ref(refs
[i
], format
, quote_style
);