| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 1 | /* |
| 2 | * rev-parse.c |
| 3 | * |
| 4 | * Copyright (C) Linus Torvalds, 2005 |
| 5 | */ |
| 6 | #include "cache.h" |
| Linus Torvalds | a8be83f | 2005-06-21 03:28:09 | [diff] [blame] | 7 | #include "commit.h" |
| Linus Torvalds | 960bba0 | 2005-07-03 20:07:52 | [diff] [blame] | 8 | #include "refs.h" |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 9 | #include "quote.h" |
| Linus Torvalds | a8be83f | 2005-06-21 03:28:09 | [diff] [blame] | 10 | |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 11 | #define DO_REVS 1 |
| 12 | #define DO_NOREV 2 |
| 13 | #define DO_FLAGS 4 |
| 14 | #define DO_NONFLAGS 8 |
| 15 | static int filter = ~0; |
| 16 | |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 17 | static char *def = NULL; |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 18 | |
| Linus Torvalds | 042a4ed | 2005-06-26 18:34:30 | [diff] [blame] | 19 | #define NORMAL 0 |
| 20 | #define REVERSED 1 |
| 21 | static int show_type = NORMAL; |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 22 | static int symbolic = 0; |
| Junio C Hamano | d501250 | 2006-01-25 09:35:38 | [diff] [blame] | 23 | static int abbrev = 0; |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 24 | static int output_sq = 0; |
| 25 | |
| 26 | static int revs_count = 0; |
| Linus Torvalds | 042a4ed | 2005-06-26 18:34:30 | [diff] [blame] | 27 | |
| Linus Torvalds | 921d865 | 2005-06-13 18:14:20 | [diff] [blame] | 28 | /* |
| 29 | * Some arguments are relevant "revision" arguments, |
| 30 | * others are about output format or other details. |
| 31 | * This sorts it all out. |
| 32 | */ |
| 33 | static int is_rev_argument(const char *arg) |
| 34 | { |
| 35 | static const char *rev_args[] = { |
| Junio C Hamano | e091eb9 | 2005-10-05 21:49:54 | [diff] [blame] | 36 | "--all", |
| Junio C Hamano | 5ccfb75 | 2005-08-09 02:31:37 | [diff] [blame] | 37 | "--bisect", |
| Junio C Hamano | 5a83f3b | 2005-10-30 09:08:35 | [diff] [blame] | 38 | "--dense", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 39 | "--header", |
| 40 | "--max-age=", |
| 41 | "--max-count=", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 42 | "--min-age=", |
| Junio C Hamano | 5ccfb75 | 2005-08-09 02:31:37 | [diff] [blame] | 43 | "--no-merges", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 44 | "--objects", |
| Junio C Hamano | c649657 | 2006-02-19 11:32:31 | [diff] [blame] | 45 | "--objects-edge", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 46 | "--parents", |
| 47 | "--pretty", |
| Junio C Hamano | 5a83f3b | 2005-10-30 09:08:35 | [diff] [blame] | 48 | "--sparse", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 49 | "--topo-order", |
| Junio C Hamano | 4c8725f | 2006-02-16 06:05:33 | [diff] [blame] | 50 | "--date-order", |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 51 | "--unpacked", |
| Linus Torvalds | 921d865 | 2005-06-13 18:14:20 | [diff] [blame] | 52 | NULL |
| 53 | }; |
| 54 | const char **p = rev_args; |
| 55 | |
| Eric Wong | 8233340 | 2006-01-30 00:28:02 | [diff] [blame] | 56 | /* accept -<digit>, like traditional "head" */ |
| 57 | if ((*arg == '-') && isdigit(arg[1])) |
| 58 | return 1; |
| 59 | |
| Linus Torvalds | 921d865 | 2005-06-13 18:14:20 | [diff] [blame] | 60 | for (;;) { |
| 61 | const char *str = *p++; |
| 62 | int len; |
| 63 | if (!str) |
| 64 | return 0; |
| 65 | len = strlen(str); |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 66 | if (!strcmp(arg, str) || |
| 67 | (str[len-1] == '=' && !strncmp(arg, str, len))) |
| Linus Torvalds | 921d865 | 2005-06-13 18:14:20 | [diff] [blame] | 68 | return 1; |
| 69 | } |
| 70 | } |
| 71 | |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 72 | /* Output argument as a string, either SQ or normal */ |
| Junio C Hamano | 5bb2c65 | 2005-07-23 02:08:32 | [diff] [blame] | 73 | static void show(const char *arg) |
| 74 | { |
| 75 | if (output_sq) { |
| 76 | int sq = '\'', ch; |
| 77 | |
| 78 | putchar(sq); |
| 79 | while ((ch = *arg++)) { |
| 80 | if (ch == sq) |
| 81 | fputs("'\\'", stdout); |
| 82 | putchar(ch); |
| 83 | } |
| 84 | putchar(sq); |
| 85 | putchar(' '); |
| 86 | } |
| 87 | else |
| 88 | puts(arg); |
| 89 | } |
| 90 | |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 91 | /* Output a revision, only if filter allows it */ |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 92 | static void show_rev(int type, const unsigned char *sha1, const char *name) |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 93 | { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 94 | if (!(filter & DO_REVS)) |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 95 | return; |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 96 | def = NULL; |
| 97 | revs_count++; |
| Junio C Hamano | 5bb2c65 | 2005-07-23 02:08:32 | [diff] [blame] | 98 | |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 99 | if (type != show_type) |
| 100 | putchar('^'); |
| 101 | if (symbolic && name) |
| 102 | show(name); |
| Junio C Hamano | d501250 | 2006-01-25 09:35:38 | [diff] [blame] | 103 | else if (abbrev) |
| 104 | show(find_unique_abbrev(sha1, abbrev)); |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 105 | else |
| 106 | show(sha1_to_hex(sha1)); |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 107 | } |
| 108 | |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 109 | /* Output a flag, only if filter allows it. */ |
| Linus Torvalds | 9523a4c | 2006-02-05 19:58:34 | [diff] [blame] | 110 | static int show_flag(char *arg) |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 111 | { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 112 | if (!(filter & DO_FLAGS)) |
| Linus Torvalds | 9523a4c | 2006-02-05 19:58:34 | [diff] [blame] | 113 | return 0; |
| 114 | if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) { |
| Linus Torvalds | 0360e99 | 2005-08-23 17:47:54 | [diff] [blame] | 115 | show(arg); |
| Linus Torvalds | 9523a4c | 2006-02-05 19:58:34 | [diff] [blame] | 116 | return 1; |
| 117 | } |
| 118 | return 0; |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 119 | } |
| 120 | |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 121 | static void show_default(void) |
| 122 | { |
| 123 | char *s = def; |
| 124 | |
| 125 | if (s) { |
| 126 | unsigned char sha1[20]; |
| 127 | |
| 128 | def = NULL; |
| Junio C Hamano | 9938af6 | 2005-08-04 05:15:49 | [diff] [blame] | 129 | if (!get_sha1(s, sha1)) { |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 130 | show_rev(NORMAL, sha1, s); |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 131 | return; |
| 132 | } |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
| Linus Torvalds | 960bba0 | 2005-07-03 20:07:52 | [diff] [blame] | 136 | static int show_reference(const char *refname, const unsigned char *sha1) |
| 137 | { |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 138 | show_rev(NORMAL, sha1, refname); |
| Linus Torvalds | 960bba0 | 2005-07-03 20:07:52 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 142 | static void show_datestring(const char *flag, const char *datestr) |
| 143 | { |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 144 | static char buffer[100]; |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 145 | |
| 146 | /* date handling requires both flags and revs */ |
| 147 | if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS)) |
| 148 | return; |
| Linus Torvalds | 3c07b1d | 2005-11-15 03:29:06 | [diff] [blame] | 149 | snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr)); |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 150 | show(buffer); |
| 151 | } |
| 152 | |
| Linus Torvalds | 9ad0a93 | 2006-02-06 05:41:47 | [diff] [blame] | 153 | static int show_file(const char *arg) |
| Linus Torvalds | 7a3dd47 | 2005-10-18 07:16:45 | [diff] [blame] | 154 | { |
| Linus Torvalds | 7b34c2f | 2005-10-25 22:24:55 | [diff] [blame] | 155 | show_default(); |
| Linus Torvalds | 9ad0a93 | 2006-02-06 05:41:47 | [diff] [blame] | 156 | if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) { |
| Linus Torvalds | 7a3dd47 | 2005-10-18 07:16:45 | [diff] [blame] | 157 | show(arg); |
| Linus Torvalds | 9ad0a93 | 2006-02-06 05:41:47 | [diff] [blame] | 158 | return 1; |
| 159 | } |
| 160 | return 0; |
| Linus Torvalds | 7a3dd47 | 2005-10-18 07:16:45 | [diff] [blame] | 161 | } |
| 162 | |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 163 | int main(int argc, char **argv) |
| 164 | { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 165 | int i, as_is = 0, verify = 0; |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 166 | unsigned char sha1[20]; |
| Linus Torvalds | d288a70 | 2005-08-17 01:06:34 | [diff] [blame] | 167 | const char *prefix = setup_git_directory(); |
| 168 | |
| Junio C Hamano | 84a9b58 | 2006-03-24 07:41:18 | [diff] [blame] | 169 | git_config(git_default_config); |
| 170 | |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 171 | for (i = 1; i < argc; i++) { |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 172 | char *arg = argv[i]; |
| 173 | char *dotdot; |
| Linus Torvalds | fb18a2e | 2006-03-27 00:28:20 | [diff] [blame] | 174 | |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 175 | if (as_is) { |
| Linus Torvalds | fb18a2e | 2006-03-27 00:28:20 | [diff] [blame] | 176 | if (show_file(arg) && as_is < 2) |
| Linus Torvalds | e23d0b4 | 2006-04-26 17:15:54 | [diff] [blame] | 177 | verify_filename(prefix, arg); |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 178 | continue; |
| 179 | } |
| Eric Wong | 3af0698 | 2006-01-30 00:26:40 | [diff] [blame] | 180 | if (!strcmp(arg,"-n")) { |
| 181 | if (++i >= argc) |
| 182 | die("-n requires an argument"); |
| 183 | if ((filter & DO_FLAGS) && (filter & DO_REVS)) { |
| 184 | show(arg); |
| 185 | show(argv[i]); |
| 186 | } |
| 187 | continue; |
| 188 | } |
| 189 | if (!strncmp(arg,"-n",2)) { |
| 190 | if ((filter & DO_FLAGS) && (filter & DO_REVS)) |
| 191 | show(arg); |
| 192 | continue; |
| 193 | } |
| 194 | |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 195 | if (*arg == '-') { |
| 196 | if (!strcmp(arg, "--")) { |
| Linus Torvalds | fb18a2e | 2006-03-27 00:28:20 | [diff] [blame] | 197 | as_is = 2; |
| Linus Torvalds | a08b650 | 2005-10-21 00:16:30 | [diff] [blame] | 198 | /* Pass on the "--" if we show anything but files.. */ |
| 199 | if (filter & (DO_FLAGS | DO_REVS)) |
| 200 | show_file(arg); |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 201 | continue; |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 202 | } |
| 203 | if (!strcmp(arg, "--default")) { |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 204 | def = argv[i+1]; |
| 205 | i++; |
| 206 | continue; |
| 207 | } |
| Linus Torvalds | 8ebb018 | 2005-06-13 17:21:11 | [diff] [blame] | 208 | if (!strcmp(arg, "--revs-only")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 209 | filter &= ~DO_NOREV; |
| Linus Torvalds | 8ebb018 | 2005-06-13 17:21:11 | [diff] [blame] | 210 | continue; |
| 211 | } |
| 212 | if (!strcmp(arg, "--no-revs")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 213 | filter &= ~DO_REVS; |
| Linus Torvalds | 8ebb018 | 2005-06-13 17:21:11 | [diff] [blame] | 214 | continue; |
| 215 | } |
| Linus Torvalds | f79b65a | 2005-07-06 17:08:08 | [diff] [blame] | 216 | if (!strcmp(arg, "--flags")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 217 | filter &= ~DO_NONFLAGS; |
| Linus Torvalds | f79b65a | 2005-07-06 17:08:08 | [diff] [blame] | 218 | continue; |
| 219 | } |
| 220 | if (!strcmp(arg, "--no-flags")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 221 | filter &= ~DO_FLAGS; |
| Linus Torvalds | f79b65a | 2005-07-06 17:08:08 | [diff] [blame] | 222 | continue; |
| 223 | } |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 224 | if (!strcmp(arg, "--verify")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 225 | filter &= ~(DO_FLAGS|DO_NOREV); |
| 226 | verify = 1; |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 227 | continue; |
| Linus Torvalds | 921d865 | 2005-06-13 18:14:20 | [diff] [blame] | 228 | } |
| Junio C Hamano | 62a604b | 2006-01-27 01:02:07 | [diff] [blame] | 229 | if (!strcmp(arg, "--short") || |
| Jonas Fonseca | 44de0da | 2006-02-18 01:10:53 | [diff] [blame] | 230 | !strncmp(arg, "--short=", 8)) { |
| Junio C Hamano | d501250 | 2006-01-25 09:35:38 | [diff] [blame] | 231 | filter &= ~(DO_FLAGS|DO_NOREV); |
| 232 | verify = 1; |
| 233 | abbrev = DEFAULT_ABBREV; |
| Jonas Fonseca | 44de0da | 2006-02-18 01:10:53 | [diff] [blame] | 234 | if (arg[7] == '=') |
| 235 | abbrev = strtoul(arg + 8, NULL, 10); |
| Junio C Hamano | 1dc4fb8 | 2006-01-26 08:48:19 | [diff] [blame] | 236 | if (abbrev < MINIMUM_ABBREV) |
| 237 | abbrev = MINIMUM_ABBREV; |
| 238 | else if (40 <= abbrev) |
| 239 | abbrev = 40; |
| Junio C Hamano | d501250 | 2006-01-25 09:35:38 | [diff] [blame] | 240 | continue; |
| 241 | } |
| Junio C Hamano | 5bb2c65 | 2005-07-23 02:08:32 | [diff] [blame] | 242 | if (!strcmp(arg, "--sq")) { |
| 243 | output_sq = 1; |
| 244 | continue; |
| 245 | } |
| Linus Torvalds | 042a4ed | 2005-06-26 18:34:30 | [diff] [blame] | 246 | if (!strcmp(arg, "--not")) { |
| 247 | show_type ^= REVERSED; |
| 248 | continue; |
| 249 | } |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 250 | if (!strcmp(arg, "--symbolic")) { |
| 251 | symbolic = 1; |
| 252 | continue; |
| 253 | } |
| Linus Torvalds | 960bba0 | 2005-07-03 20:07:52 | [diff] [blame] | 254 | if (!strcmp(arg, "--all")) { |
| 255 | for_each_ref(show_reference); |
| 256 | continue; |
| 257 | } |
| Linus Torvalds | d288a70 | 2005-08-17 01:06:34 | [diff] [blame] | 258 | if (!strcmp(arg, "--show-prefix")) { |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 259 | if (prefix) |
| 260 | puts(prefix); |
| Linus Torvalds | d288a70 | 2005-08-17 01:06:34 | [diff] [blame] | 261 | continue; |
| 262 | } |
| Junio C Hamano | 5f94c73 | 2005-12-23 06:35:38 | [diff] [blame] | 263 | if (!strcmp(arg, "--show-cdup")) { |
| 264 | const char *pfx = prefix; |
| 265 | while (pfx) { |
| 266 | pfx = strchr(pfx, '/'); |
| 267 | if (pfx) { |
| 268 | pfx++; |
| 269 | printf("../"); |
| 270 | } |
| 271 | } |
| 272 | putchar('\n'); |
| 273 | continue; |
| 274 | } |
| Linus Torvalds | a8783ee | 2005-09-18 18:18:30 | [diff] [blame] | 275 | if (!strcmp(arg, "--git-dir")) { |
| 276 | const char *gitdir = getenv(GIT_DIR_ENVIRONMENT); |
| 277 | static char cwd[PATH_MAX]; |
| 278 | if (gitdir) { |
| 279 | puts(gitdir); |
| 280 | continue; |
| 281 | } |
| 282 | if (!prefix) { |
| 283 | puts(".git"); |
| 284 | continue; |
| 285 | } |
| 286 | if (!getcwd(cwd, PATH_MAX)) |
| 287 | die("unable to get current working directory"); |
| 288 | printf("%s/.git\n", cwd); |
| 289 | continue; |
| 290 | } |
| Linus Torvalds | c1babb1 | 2005-09-20 21:13:24 | [diff] [blame] | 291 | if (!strncmp(arg, "--since=", 8)) { |
| 292 | show_datestring("--max-age=", arg+8); |
| 293 | continue; |
| 294 | } |
| 295 | if (!strncmp(arg, "--after=", 8)) { |
| 296 | show_datestring("--max-age=", arg+8); |
| 297 | continue; |
| 298 | } |
| 299 | if (!strncmp(arg, "--before=", 9)) { |
| 300 | show_datestring("--min-age=", arg+9); |
| 301 | continue; |
| 302 | } |
| 303 | if (!strncmp(arg, "--until=", 8)) { |
| 304 | show_datestring("--min-age=", arg+8); |
| 305 | continue; |
| 306 | } |
| Linus Torvalds | 9523a4c | 2006-02-05 19:58:34 | [diff] [blame] | 307 | if (show_flag(arg) && verify) |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 308 | die("Needed a single revision"); |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 309 | continue; |
| 310 | } |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 311 | |
| 312 | /* Not a flag argument */ |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 313 | dotdot = strstr(arg, ".."); |
| 314 | if (dotdot) { |
| 315 | unsigned char end[20]; |
| Junio C Hamano | ce4a706 | 2006-03-30 03:41:37 | [diff] [blame] | 316 | char *next = dotdot + 2; |
| 317 | char *this = arg; |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 318 | *dotdot = 0; |
| Junio C Hamano | ce4a706 | 2006-03-30 03:41:37 | [diff] [blame] | 319 | if (!*next) |
| 320 | next = "HEAD"; |
| 321 | if (dotdot == arg) |
| 322 | this = "HEAD"; |
| 323 | if (!get_sha1(this, sha1) && !get_sha1(next, end)) { |
| 324 | show_rev(NORMAL, end, next); |
| 325 | show_rev(REVERSED, sha1, this); |
| 326 | continue; |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 327 | } |
| 328 | *dotdot = '.'; |
| 329 | } |
| Junio C Hamano | 9938af6 | 2005-08-04 05:15:49 | [diff] [blame] | 330 | if (!get_sha1(arg, sha1)) { |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 331 | show_rev(NORMAL, sha1, arg); |
| Linus Torvalds | 800644c | 2005-06-20 15:29:13 | [diff] [blame] | 332 | continue; |
| 333 | } |
| Junio C Hamano | 9938af6 | 2005-08-04 05:15:49 | [diff] [blame] | 334 | if (*arg == '^' && !get_sha1(arg+1, sha1)) { |
| Junio C Hamano | 30b96fc | 2005-08-16 19:36:46 | [diff] [blame] | 335 | show_rev(REVERSED, sha1, arg+1); |
| Linus Torvalds | 800644c | 2005-06-20 15:29:13 | [diff] [blame] | 336 | continue; |
| 337 | } |
| Linus Torvalds | 9ad0a93 | 2006-02-06 05:41:47 | [diff] [blame] | 338 | as_is = 1; |
| 339 | if (!show_file(arg)) |
| 340 | continue; |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 341 | if (verify) |
| 342 | die("Needed a single revision"); |
| Linus Torvalds | e23d0b4 | 2006-04-26 17:15:54 | [diff] [blame] | 343 | verify_filename(prefix, arg); |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 344 | } |
| Linus Torvalds | 023d66e | 2005-06-24 17:12:55 | [diff] [blame] | 345 | show_default(); |
| Junio C Hamano | 4866ccf | 2005-08-24 21:30:04 | [diff] [blame] | 346 | if (verify && revs_count != 1) |
| 347 | die("Needed a single revision"); |
| Linus Torvalds | 178cb24 | 2005-06-13 17:06:50 | [diff] [blame] | 348 | return 0; |
| 349 | } |