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[] = {
38 const char **p = rev_args;
41 const char *str = *p++;
46 if (!strncmp(arg, str, len))
51 static void show(const char *arg)
57 while ((ch = *arg++)) {
59 fputs("'\\'", stdout);
69 static void show_rev(int type, const unsigned char *sha1)
75 /* Hexadecimal string plus possibly a carret;
76 * this does not have to be quoted even under output_sq.
78 printf("%s%s%c", type == show_type ? "" : "^", sha1_to_hex(sha1),
79 output_sq ? ' ' : '\n');
82 static void show_rev_arg(char *rev)
89 static void show_norev(char *norev)
98 static void show_arg(char *arg)
102 if (do_rev_argument && is_rev_argument(arg))
108 static void show_default(void)
113 unsigned char sha1[20];
116 if (!get_sha1(s, sha1)) {
117 show_rev(NORMAL, sha1);
124 static int show_reference(const char *refname, const unsigned char *sha1)
126 show_rev(NORMAL, sha1);
130 int main(int argc, char **argv)
133 unsigned char sha1[20];
135 for (i = 1; i < argc; i++) {
144 if (!strcmp(arg, "--")) {
150 if (!strcmp(arg, "--default")) {
155 if (!strcmp(arg, "--revs-only")) {
159 if (!strcmp(arg, "--no-revs")) {
163 if (!strcmp(arg, "--flags")) {
167 if (!strcmp(arg, "--no-flags")) {
171 if (!strcmp(arg, "--verify")) {
177 if (!strcmp(arg, "--sq")) {
181 if (!strcmp(arg, "--not")) {
182 show_type ^= REVERSED;
185 if (!strcmp(arg, "--all")) {
186 for_each_ref(show_reference);
192 dotdot = strstr(arg, "..");
194 unsigned char end[20];
197 if (!get_sha1(arg, sha1)) {
200 if (!get_sha1(n, end)) {
204 show_rev(NORMAL, end);
205 show_rev(REVERSED, sha1);
211 if (!get_sha1(arg, sha1)) {
215 show_rev(NORMAL, sha1);
218 if (*arg == '^' && !get_sha1(arg+1, sha1)) {
222 show_rev(REVERSED, sha1);
229 if (single_rev && output_revs != 1) {
230 fprintf(stderr, "Needed a single revision\n");