4 * Copyright (C) Linus Torvalds, 2005
10 static char *def
= NULL
;
11 static int no_revs
= 0;
12 static int single_rev
= 0;
13 static int revs_only
= 0;
14 static int do_rev_argument
= 1;
15 static int output_revs
= 0;
16 static int flags_only
= 0;
17 static int no_flags
= 0;
18 static int output_sq
= 0;
22 static int show_type
= NORMAL
;
25 * Some arguments are relevant "revision" arguments,
26 * others are about output format or other details.
27 * This sorts it all out.
29 static int is_rev_argument(const char *arg
)
31 static const char *rev_args
[] = {
41 const char **p
= rev_args
;
44 const char *str
= *p
++;
49 if (!strncmp(arg
, str
, len
))
54 static void show(const char *arg
)
60 while ((ch
= *arg
++)) {
62 fputs("'\\'", stdout
);
72 static void show_rev(int type
, const unsigned char *sha1
)
78 /* Hexadecimal string plus possibly a carret;
79 * this does not have to be quoted even under output_sq.
81 printf("%s%s%c", type
== show_type
? "" : "^", sha1_to_hex(sha1
),
82 output_sq
? ' ' : '\n');
85 static void show_rev_arg(char *rev
)
92 static void show_norev(char *norev
)
101 static void show_arg(char *arg
)
105 if (do_rev_argument
&& is_rev_argument(arg
))
111 static void show_default(void)
116 unsigned char sha1
[20];
119 if (!get_sha1(s
, sha1
)) {
120 show_rev(NORMAL
, sha1
);
127 static int show_reference(const char *refname
, const unsigned char *sha1
)
129 show_rev(NORMAL
, sha1
);
133 int main(int argc
, char **argv
)
136 unsigned char sha1
[20];
138 for (i
= 1; i
< argc
; i
++) {
147 if (!strcmp(arg
, "--")) {
153 if (!strcmp(arg
, "--default")) {
158 if (!strcmp(arg
, "--revs-only")) {
162 if (!strcmp(arg
, "--no-revs")) {
166 if (!strcmp(arg
, "--flags")) {
170 if (!strcmp(arg
, "--no-flags")) {
174 if (!strcmp(arg
, "--verify")) {
180 if (!strcmp(arg
, "--sq")) {
184 if (!strcmp(arg
, "--not")) {
185 show_type
^= REVERSED
;
188 if (!strcmp(arg
, "--all")) {
189 for_each_ref(show_reference
);
195 dotdot
= strstr(arg
, "..");
197 unsigned char end
[20];
200 if (!get_sha1(arg
, sha1
)) {
203 if (!get_sha1(n
, end
)) {
207 show_rev(NORMAL
, end
);
208 show_rev(REVERSED
, sha1
);
214 if (!get_sha1(arg
, sha1
)) {
218 show_rev(NORMAL
, sha1
);
221 if (*arg
== '^' && !get_sha1(arg
+1, sha1
)) {
225 show_rev(REVERSED
, sha1
);
232 if (single_rev
&& output_revs
!= 1) {
233 fprintf(stderr
, "Needed a single revision\n");