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;
19 static int symbolic = 0;
23 static int show_type = NORMAL;
26 * Some arguments are relevant "revision" arguments,
27 * others are about output format or other details.
28 * This sorts it all out.
30 static int is_rev_argument(const char *arg)
32 static const char *rev_args[] = {
42 const char **p = rev_args;
45 const char *str = *p++;
50 if (!strncmp(arg, str, len))
55 static void show(const char *arg)
61 while ((ch = *arg++)) {
63 fputs("'\\'", stdout);
73 static void show_rev(int type, const unsigned char *sha1, const char *name)
79 if (type != show_type)
84 show(sha1_to_hex(sha1));
87 static void show_rev_arg(char *rev)
94 static void show_norev(char *norev)
103 static void show_arg(char *arg)
107 if (do_rev_argument && is_rev_argument(arg))
113 static void show_default(void)
118 unsigned char sha1[20];
121 if (!get_sha1(s, sha1)) {
122 show_rev(NORMAL, sha1, s);
129 static int show_reference(const char *refname, const unsigned char *sha1)
131 show_rev(NORMAL, sha1, refname);
135 int main(int argc, char **argv)
138 unsigned char sha1[20];
139 const char *prefix = setup_git_directory();
141 for (i = 1; i < argc; i++) {
150 if (!strcmp(arg, "--")) {
156 if (!strcmp(arg, "--default")) {
161 if (!strcmp(arg, "--revs-only")) {
165 if (!strcmp(arg, "--no-revs")) {
169 if (!strcmp(arg, "--flags")) {
173 if (!strcmp(arg, "--no-flags")) {
177 if (!strcmp(arg, "--verify")) {
183 if (!strcmp(arg, "--sq")) {
187 if (!strcmp(arg, "--not")) {
188 show_type ^= REVERSED;
191 if (!strcmp(arg, "--symbolic")) {
195 if (!strcmp(arg, "--all")) {
196 for_each_ref(show_reference);
199 if (!strcmp(arg, "--show-prefix")) {
206 dotdot = strstr(arg, "..");
208 unsigned char end[20];
211 if (!get_sha1(arg, sha1)) {
214 if (!get_sha1(n, end)) {
218 show_rev(NORMAL, end, n);
219 show_rev(REVERSED, sha1, arg);
225 if (!get_sha1(arg, sha1)) {
229 show_rev(NORMAL, sha1, arg);
232 if (*arg == '^' && !get_sha1(arg+1, sha1)) {
236 show_rev(REVERSED, sha1, arg+1);
243 if (single_rev && output_revs != 1) {
244 fprintf(stderr, "Needed a single revision\n");