Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 1 | #include "cache.h" |
Junio C Hamano | e091eb9 | 2005-10-05 14:49:54 -0700 | [diff] [blame] | 2 | #include "refs.h" |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 3 | #include "tag.h" |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 4 | #include "commit.h" |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 5 | #include "tree.h" |
| 6 | #include "blob.h" |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 7 | #include "epoch.h" |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 8 | #include "diff.h" |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 10 | #define SEEN (1u << 0) |
| 11 | #define INTERESTING (1u << 1) |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 12 | #define COUNTED (1u << 2) |
Linus Torvalds | bce6286 | 2005-07-06 09:56:16 -0700 | [diff] [blame] | 13 | #define SHOWN (1u << 3) |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 14 | #define TREECHANGE (1u << 4) |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 16 | static const char rev_list_usage[] = |
Junio C Hamano | 69e0c25 | 2005-10-30 01:03:45 -0800 | [diff] [blame] | 17 | "git-rev-list [OPTION] <commit-id>... [ -- paths... ]\n" |
| 18 | " limiting output:\n" |
| 19 | " --max-count=nr\n" |
| 20 | " --max-age=epoch\n" |
| 21 | " --min-age=epoch\n" |
| 22 | " --sparse\n" |
| 23 | " --no-merges\n" |
| 24 | " --all\n" |
| 25 | " ordering output:\n" |
| 26 | " --merge-order [ --show-breaks ]\n" |
| 27 | " --topo-order\n" |
| 28 | " formatting output:\n" |
| 29 | " --parents\n" |
| 30 | " --objects\n" |
| 31 | " --unpacked\n" |
| 32 | " --header | --pretty\n" |
| 33 | " special purpose:\n" |
| 34 | " --bisect" |
| 35 | ; |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 37 | static int dense = 1; |
Linus Torvalds | 12d2a18 | 2005-07-03 13:29:54 -0700 | [diff] [blame] | 38 | static int unpacked = 0; |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 39 | static int bisect_list = 0; |
Linus Torvalds | 3c90f03 | 2005-06-29 10:40:14 -0700 | [diff] [blame] | 40 | static int tag_objects = 0; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 41 | static int tree_objects = 0; |
| 42 | static int blob_objects = 0; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 43 | static int verbose_header = 0; |
| 44 | static int show_parents = 0; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 45 | static int hdr_termination = 0; |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 46 | static const char *commit_prefix = ""; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 47 | static unsigned long max_age = -1; |
| 48 | static unsigned long min_age = -1; |
| 49 | static int max_count = -1; |
Linus Torvalds | 000182e | 2005-06-05 09:02:03 -0700 | [diff] [blame] | 50 | static enum cmit_fmt commit_format = CMIT_FMT_RAW; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 51 | static int merge_order = 0; |
| 52 | static int show_breaks = 0; |
Jon Seymour | 5e749e2 | 2005-06-20 12:29:41 +1000 | [diff] [blame] | 53 | static int stop_traversal = 0; |
Linus Torvalds | d2d02a4 | 2005-07-06 10:25:04 -0700 | [diff] [blame] | 54 | static int topo_order = 0; |
Johannes Schindelin | 76cd8eb | 2005-08-08 11:37:21 +0200 | [diff] [blame] | 55 | static int no_merges = 0; |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 56 | static const char **paths = NULL; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 57 | |
| 58 | static void show_commit(struct commit *commit) |
| 59 | { |
Jon Seymour | 51b1e17 | 2005-06-20 12:29:38 +1000 | [diff] [blame] | 60 | commit->object.flags |= SHOWN; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 61 | if (show_breaks) { |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 62 | commit_prefix = "| "; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 63 | if (commit->object.flags & DISCONTINUITY) { |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 64 | commit_prefix = "^ "; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 65 | } else if (commit->object.flags & BOUNDARY) { |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 66 | commit_prefix = "= "; |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 69 | printf("%s%s", commit_prefix, sha1_to_hex(commit->object.sha1)); |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 70 | if (show_parents) { |
| 71 | struct commit_list *parents = commit->parents; |
| 72 | while (parents) { |
| 73 | printf(" %s", sha1_to_hex(parents->item->object.sha1)); |
| 74 | parents = parents->next; |
| 75 | } |
| 76 | } |
Junio C Hamano | d87449c | 2005-08-08 22:15:40 -0700 | [diff] [blame] | 77 | if (commit_format == CMIT_FMT_ONELINE) |
| 78 | putchar(' '); |
| 79 | else |
| 80 | putchar('\n'); |
| 81 | |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 82 | if (verbose_header) { |
Linus Torvalds | 000182e | 2005-06-05 09:02:03 -0700 | [diff] [blame] | 83 | static char pretty_header[16384]; |
| 84 | pretty_print_commit(commit_format, commit->buffer, ~0, pretty_header, sizeof(pretty_header)); |
| 85 | printf("%s%c", pretty_header, hdr_termination); |
Linus Torvalds | 7620d39 | 2005-07-04 16:36:48 -0700 | [diff] [blame] | 86 | } |
| 87 | fflush(stdout); |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 90 | static int rewrite_one(struct commit **pp) |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 91 | { |
| 92 | for (;;) { |
| 93 | struct commit *p = *pp; |
| 94 | if (p->object.flags & (TREECHANGE | UNINTERESTING)) |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 95 | return 0; |
| 96 | if (!p->parents) |
| 97 | return -1; |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 98 | *pp = p->parents->item; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | static void rewrite_parents(struct commit *commit) |
| 103 | { |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 104 | struct commit_list **pp = &commit->parents; |
| 105 | while (*pp) { |
| 106 | struct commit_list *parent = *pp; |
| 107 | if (rewrite_one(&parent->item) < 0) { |
| 108 | *pp = parent->next; |
| 109 | continue; |
| 110 | } |
| 111 | pp = &parent->next; |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 115 | static int filter_commit(struct commit * commit) |
| 116 | { |
Jon Seymour | d2775a8 | 2005-07-07 02:39:34 +1000 | [diff] [blame] | 117 | if (stop_traversal && (commit->object.flags & BOUNDARY)) |
Jon Seymour | 5e749e2 | 2005-06-20 12:29:41 +1000 | [diff] [blame] | 118 | return STOP; |
Jon Seymour | 51b1e17 | 2005-06-20 12:29:38 +1000 | [diff] [blame] | 119 | if (commit->object.flags & (UNINTERESTING|SHOWN)) |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 120 | return CONTINUE; |
| 121 | if (min_age != -1 && (commit->date > min_age)) |
| 122 | return CONTINUE; |
Jon Seymour | 5e749e2 | 2005-06-20 12:29:41 +1000 | [diff] [blame] | 123 | if (max_age != -1 && (commit->date < max_age)) { |
Jon Seymour | d2775a8 | 2005-07-07 02:39:34 +1000 | [diff] [blame] | 124 | stop_traversal=1; |
Linus Torvalds | 27cfe2e | 2005-09-20 17:55:46 -0700 | [diff] [blame] | 125 | return CONTINUE; |
Jon Seymour | 5e749e2 | 2005-06-20 12:29:41 +1000 | [diff] [blame] | 126 | } |
Johannes Schindelin | 76cd8eb | 2005-08-08 11:37:21 +0200 | [diff] [blame] | 127 | if (no_merges && (commit->parents && commit->parents->next)) |
| 128 | return CONTINUE; |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 129 | if (paths && dense) { |
| 130 | if (!(commit->object.flags & TREECHANGE)) |
| 131 | return CONTINUE; |
| 132 | rewrite_parents(commit); |
| 133 | } |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 134 | return DO; |
| 135 | } |
| 136 | |
| 137 | static int process_commit(struct commit * commit) |
| 138 | { |
| 139 | int action=filter_commit(commit); |
| 140 | |
| 141 | if (action == STOP) { |
| 142 | return STOP; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 143 | } |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 144 | |
| 145 | if (action == CONTINUE) { |
| 146 | return CONTINUE; |
| 147 | } |
| 148 | |
Luben Tuikov | 07f9247 | 2005-11-18 16:29:04 -0500 | [diff] [blame] | 149 | if (max_count != -1 && !max_count--) |
| 150 | return STOP; |
| 151 | |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 152 | show_commit(commit); |
| 153 | |
| 154 | return CONTINUE; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 157 | static struct object_list **add_object(struct object *obj, struct object_list **p, const char *name) |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 158 | { |
| 159 | struct object_list *entry = xmalloc(sizeof(*entry)); |
| 160 | entry->item = obj; |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 161 | entry->next = *p; |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 162 | entry->name = name; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 163 | *p = entry; |
| 164 | return &entry->next; |
| 165 | } |
| 166 | |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 167 | static struct object_list **process_blob(struct blob *blob, struct object_list **p, const char *name) |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 168 | { |
| 169 | struct object *obj = &blob->object; |
| 170 | |
| 171 | if (!blob_objects) |
| 172 | return p; |
| 173 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 174 | return p; |
| 175 | obj->flags |= SEEN; |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 176 | return add_object(obj, p, name); |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 179 | static struct object_list **process_tree(struct tree *tree, struct object_list **p, const char *name) |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 180 | { |
| 181 | struct object *obj = &tree->object; |
| 182 | struct tree_entry_list *entry; |
| 183 | |
| 184 | if (!tree_objects) |
| 185 | return p; |
| 186 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 187 | return p; |
| 188 | if (parse_tree(tree) < 0) |
| 189 | die("bad tree object %s", sha1_to_hex(obj->sha1)); |
| 190 | obj->flags |= SEEN; |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 191 | p = add_object(obj, p, name); |
Linus Torvalds | b0d8923 | 2005-09-16 14:32:48 -0700 | [diff] [blame] | 192 | entry = tree->entries; |
| 193 | tree->entries = NULL; |
| 194 | while (entry) { |
| 195 | struct tree_entry_list *next = entry->next; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 196 | if (entry->directory) |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 197 | p = process_tree(entry->item.tree, p, entry->name); |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 198 | else |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 199 | p = process_blob(entry->item.blob, p, entry->name); |
Linus Torvalds | b0d8923 | 2005-09-16 14:32:48 -0700 | [diff] [blame] | 200 | free(entry); |
| 201 | entry = next; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 202 | } |
| 203 | return p; |
| 204 | } |
| 205 | |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 206 | static struct object_list *pending_objects = NULL; |
| 207 | |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 208 | static void show_commit_list(struct commit_list *list) |
| 209 | { |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 210 | struct object_list *objects = NULL, **p = &objects, *pending; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 211 | while (list) { |
| 212 | struct commit *commit = pop_most_recent_commit(&list, SEEN); |
| 213 | |
Linus Torvalds | 9ce43d1 | 2005-06-26 15:26:05 -0700 | [diff] [blame] | 214 | p = process_tree(commit->tree, p, ""); |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 215 | if (process_commit(commit) == STOP) |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 216 | break; |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 217 | } |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 218 | for (pending = pending_objects; pending; pending = pending->next) { |
| 219 | struct object *obj = pending->item; |
| 220 | const char *name = pending->name; |
| 221 | if (obj->flags & (UNINTERESTING | SEEN)) |
| 222 | continue; |
| 223 | if (obj->type == tag_type) { |
| 224 | obj->flags |= SEEN; |
| 225 | p = add_object(obj, p, name); |
| 226 | continue; |
| 227 | } |
| 228 | if (obj->type == tree_type) { |
| 229 | p = process_tree((struct tree *)obj, p, name); |
| 230 | continue; |
| 231 | } |
| 232 | if (obj->type == blob_type) { |
| 233 | p = process_blob((struct blob *)obj, p, name); |
| 234 | continue; |
| 235 | } |
| 236 | die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name); |
| 237 | } |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 238 | while (objects) { |
Junio C Hamano | c807f77 | 2005-10-02 17:29:21 -0700 | [diff] [blame] | 239 | /* An object with name "foo\n0000000000000000000000000000000000000000" |
| 240 | * can be used confuse downstream git-pack-objects very badly. |
| 241 | */ |
| 242 | const char *ep = strchr(objects->name, '\n'); |
| 243 | if (ep) { |
| 244 | printf("%s %.*s\n", sha1_to_hex(objects->item->sha1), |
| 245 | (int) (ep - objects->name), |
| 246 | objects->name); |
| 247 | } |
| 248 | else |
| 249 | printf("%s %s\n", sha1_to_hex(objects->item->sha1), objects->name); |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 250 | objects = objects->next; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | static void mark_blob_uninteresting(struct blob *blob) |
| 255 | { |
| 256 | if (!blob_objects) |
| 257 | return; |
| 258 | if (blob->object.flags & UNINTERESTING) |
| 259 | return; |
| 260 | blob->object.flags |= UNINTERESTING; |
| 261 | } |
| 262 | |
| 263 | static void mark_tree_uninteresting(struct tree *tree) |
| 264 | { |
| 265 | struct object *obj = &tree->object; |
| 266 | struct tree_entry_list *entry; |
| 267 | |
| 268 | if (!tree_objects) |
| 269 | return; |
| 270 | if (obj->flags & UNINTERESTING) |
| 271 | return; |
| 272 | obj->flags |= UNINTERESTING; |
Linus Torvalds | 454fbbc | 2005-07-10 15:09:46 -0700 | [diff] [blame] | 273 | if (!has_sha1_file(obj->sha1)) |
| 274 | return; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 275 | if (parse_tree(tree) < 0) |
| 276 | die("bad tree %s", sha1_to_hex(obj->sha1)); |
| 277 | entry = tree->entries; |
Linus Torvalds | b0d8923 | 2005-09-16 14:32:48 -0700 | [diff] [blame] | 278 | tree->entries = NULL; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 279 | while (entry) { |
Linus Torvalds | b0d8923 | 2005-09-16 14:32:48 -0700 | [diff] [blame] | 280 | struct tree_entry_list *next = entry->next; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 281 | if (entry->directory) |
| 282 | mark_tree_uninteresting(entry->item.tree); |
| 283 | else |
| 284 | mark_blob_uninteresting(entry->item.blob); |
Linus Torvalds | b0d8923 | 2005-09-16 14:32:48 -0700 | [diff] [blame] | 285 | free(entry); |
| 286 | entry = next; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 287 | } |
Linus Torvalds | 81f2bb1 | 2005-06-02 09:19:53 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 290 | static void mark_parents_uninteresting(struct commit *commit) |
| 291 | { |
| 292 | struct commit_list *parents = commit->parents; |
| 293 | |
| 294 | while (parents) { |
| 295 | struct commit *commit = parents->item; |
| 296 | commit->object.flags |= UNINTERESTING; |
Linus Torvalds | 454fbbc | 2005-07-10 15:09:46 -0700 | [diff] [blame] | 297 | |
| 298 | /* |
Linus Torvalds | 6c3b84c | 2005-07-29 15:50:30 -0700 | [diff] [blame] | 299 | * Normally we haven't parsed the parent |
| 300 | * yet, so we won't have a parent of a parent |
| 301 | * here. However, it may turn out that we've |
| 302 | * reached this commit some other way (where it |
| 303 | * wasn't uninteresting), in which case we need |
| 304 | * to mark its parents recursively too.. |
| 305 | */ |
| 306 | if (commit->parents) |
| 307 | mark_parents_uninteresting(commit); |
| 308 | |
| 309 | /* |
Linus Torvalds | 454fbbc | 2005-07-10 15:09:46 -0700 | [diff] [blame] | 310 | * A missing commit is ok iff its parent is marked |
| 311 | * uninteresting. |
| 312 | * |
| 313 | * We just mark such a thing parsed, so that when |
| 314 | * it is popped next time around, we won't be trying |
| 315 | * to parse it and get an error. |
| 316 | */ |
| 317 | if (!has_sha1_file(commit->object.sha1)) |
| 318 | commit->object.parsed = 1; |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 319 | parents = parents->next; |
| 320 | } |
| 321 | } |
| 322 | |
Linus Torvalds | 4311d32 | 2005-07-23 10:01:49 -0700 | [diff] [blame] | 323 | static int everybody_uninteresting(struct commit_list *orig) |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 324 | { |
Linus Torvalds | 4311d32 | 2005-07-23 10:01:49 -0700 | [diff] [blame] | 325 | struct commit_list *list = orig; |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 326 | while (list) { |
| 327 | struct commit *commit = list->item; |
| 328 | list = list->next; |
| 329 | if (commit->object.flags & UNINTERESTING) |
| 330 | continue; |
| 331 | return 0; |
| 332 | } |
| 333 | return 1; |
| 334 | } |
| 335 | |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 336 | /* |
| 337 | * This is a truly stupid algorithm, but it's only |
| 338 | * used for bisection, and we just don't care enough. |
| 339 | * |
| 340 | * We care just barely enough to avoid recursing for |
| 341 | * non-merge entries. |
| 342 | */ |
| 343 | static int count_distance(struct commit_list *entry) |
| 344 | { |
| 345 | int nr = 0; |
| 346 | |
| 347 | while (entry) { |
| 348 | struct commit *commit = entry->item; |
| 349 | struct commit_list *p; |
| 350 | |
| 351 | if (commit->object.flags & (UNINTERESTING | COUNTED)) |
| 352 | break; |
| 353 | nr++; |
| 354 | commit->object.flags |= COUNTED; |
| 355 | p = commit->parents; |
| 356 | entry = p; |
| 357 | if (p) { |
| 358 | p = p->next; |
| 359 | while (p) { |
| 360 | nr += count_distance(p); |
| 361 | p = p->next; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | return nr; |
| 366 | } |
| 367 | |
Linus Torvalds | 3d95806 | 2005-06-18 20:02:49 -0700 | [diff] [blame] | 368 | static void clear_distance(struct commit_list *list) |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 369 | { |
| 370 | while (list) { |
| 371 | struct commit *commit = list->item; |
| 372 | commit->object.flags &= ~COUNTED; |
| 373 | list = list->next; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static struct commit_list *find_bisection(struct commit_list *list) |
| 378 | { |
| 379 | int nr, closest; |
| 380 | struct commit_list *p, *best; |
| 381 | |
| 382 | nr = 0; |
| 383 | p = list; |
| 384 | while (p) { |
| 385 | nr++; |
| 386 | p = p->next; |
| 387 | } |
| 388 | closest = 0; |
| 389 | best = list; |
| 390 | |
| 391 | p = list; |
| 392 | while (p) { |
| 393 | int distance = count_distance(p); |
| 394 | clear_distance(list); |
| 395 | if (nr - distance < distance) |
| 396 | distance = nr - distance; |
| 397 | if (distance > closest) { |
| 398 | best = p; |
| 399 | closest = distance; |
| 400 | } |
| 401 | p = p->next; |
| 402 | } |
| 403 | if (best) |
| 404 | best->next = NULL; |
| 405 | return best; |
| 406 | } |
| 407 | |
Linus Torvalds | 5bdbaaa | 2005-09-15 15:14:29 -0700 | [diff] [blame] | 408 | static void mark_edges_uninteresting(struct commit_list *list) |
| 409 | { |
| 410 | for ( ; list; list = list->next) { |
| 411 | struct commit_list *parents = list->item->parents; |
| 412 | |
| 413 | for ( ; parents; parents = parents->next) { |
| 414 | struct commit *commit = parents->item; |
| 415 | if (commit->object.flags & UNINTERESTING) |
| 416 | mark_tree_uninteresting(commit->tree); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 421 | static int is_different = 0; |
| 422 | |
| 423 | static void file_add_remove(struct diff_options *options, |
| 424 | int addremove, unsigned mode, |
| 425 | const unsigned char *sha1, |
| 426 | const char *base, const char *path) |
| 427 | { |
| 428 | is_different = 1; |
| 429 | } |
| 430 | |
| 431 | static void file_change(struct diff_options *options, |
| 432 | unsigned old_mode, unsigned new_mode, |
| 433 | const unsigned char *old_sha1, |
| 434 | const unsigned char *new_sha1, |
| 435 | const char *base, const char *path) |
| 436 | { |
| 437 | is_different = 1; |
| 438 | } |
| 439 | |
| 440 | static struct diff_options diff_opt = { |
| 441 | .recursive = 1, |
| 442 | .add_remove = file_add_remove, |
| 443 | .change = file_change, |
| 444 | }; |
| 445 | |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 446 | static int same_tree(struct tree *t1, struct tree *t2) |
| 447 | { |
| 448 | is_different = 0; |
| 449 | if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", &diff_opt) < 0) |
| 450 | return 0; |
| 451 | return !is_different; |
| 452 | } |
| 453 | |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 454 | static int same_tree_as_empty(struct tree *t1) |
| 455 | { |
| 456 | int retval; |
| 457 | void *tree; |
| 458 | struct tree_desc empty, real; |
| 459 | |
| 460 | if (!t1) |
| 461 | return 0; |
| 462 | |
| 463 | tree = read_object_with_reference(t1->object.sha1, "tree", &real.size, NULL); |
| 464 | if (!tree) |
| 465 | return 0; |
| 466 | real.buf = tree; |
| 467 | |
| 468 | empty.buf = ""; |
| 469 | empty.size = 0; |
| 470 | |
| 471 | is_different = 0; |
| 472 | retval = diff_tree(&empty, &real, "", &diff_opt); |
| 473 | free(tree); |
| 474 | |
| 475 | return retval >= 0 && !is_different; |
| 476 | } |
| 477 | |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 478 | static struct commit *try_to_simplify_merge(struct commit *commit, struct commit_list *parent) |
| 479 | { |
| 480 | if (!commit->tree) |
| 481 | return NULL; |
| 482 | |
| 483 | while (parent) { |
| 484 | struct commit *p = parent->item; |
| 485 | parent = parent->next; |
| 486 | parse_commit(p); |
| 487 | if (!p->tree) |
| 488 | continue; |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 489 | if (same_tree(commit->tree, p->tree)) |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 490 | return p; |
| 491 | } |
| 492 | return NULL; |
| 493 | } |
| 494 | |
| 495 | static void add_parents_to_list(struct commit *commit, struct commit_list **list) |
| 496 | { |
| 497 | struct commit_list *parent = commit->parents; |
| 498 | |
| 499 | /* |
| 500 | * If the commit is uninteresting, don't try to |
| 501 | * prune parents - we want the maximal uninteresting |
| 502 | * set. |
| 503 | * |
| 504 | * Normally we haven't parsed the parent |
| 505 | * yet, so we won't have a parent of a parent |
| 506 | * here. However, it may turn out that we've |
| 507 | * reached this commit some other way (where it |
| 508 | * wasn't uninteresting), in which case we need |
| 509 | * to mark its parents recursively too.. |
| 510 | */ |
| 511 | if (commit->object.flags & UNINTERESTING) { |
| 512 | while (parent) { |
| 513 | struct commit *p = parent->item; |
| 514 | parent = parent->next; |
| 515 | parse_commit(p); |
| 516 | p->object.flags |= UNINTERESTING; |
| 517 | if (p->parents) |
| 518 | mark_parents_uninteresting(p); |
| 519 | if (p->object.flags & SEEN) |
| 520 | continue; |
| 521 | p->object.flags |= SEEN; |
| 522 | insert_by_date(p, list); |
| 523 | } |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * Ok, the commit wasn't uninteresting. If it |
| 529 | * is a merge, try to find the parent that has |
| 530 | * no differences in the path set if one exists. |
| 531 | */ |
| 532 | if (paths && parent && parent->next) { |
| 533 | struct commit *preferred; |
| 534 | |
| 535 | preferred = try_to_simplify_merge(commit, parent); |
| 536 | if (preferred) { |
| 537 | parent->item = preferred; |
| 538 | parent->next = NULL; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | while (parent) { |
| 543 | struct commit *p = parent->item; |
| 544 | |
| 545 | parent = parent->next; |
| 546 | |
| 547 | parse_commit(p); |
| 548 | if (p->object.flags & SEEN) |
| 549 | continue; |
| 550 | p->object.flags |= SEEN; |
| 551 | insert_by_date(p, list); |
| 552 | } |
| 553 | } |
| 554 | |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 555 | static void compress_list(struct commit_list *list) |
| 556 | { |
| 557 | while (list) { |
| 558 | struct commit *commit = list->item; |
| 559 | struct commit_list *parent = commit->parents; |
| 560 | list = list->next; |
| 561 | |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 562 | if (!parent) { |
| 563 | if (!same_tree_as_empty(commit->tree)) |
| 564 | commit->object.flags |= TREECHANGE; |
| 565 | continue; |
| 566 | } |
| 567 | |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 568 | /* |
| 569 | * Exactly one parent? Check if it leaves the tree |
| 570 | * unchanged |
| 571 | */ |
Linus Torvalds | 129adf4 | 2005-10-25 11:50:46 -0700 | [diff] [blame] | 572 | if (!parent->next) { |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 573 | struct tree *t1 = commit->tree; |
| 574 | struct tree *t2 = parent->item->tree; |
| 575 | if (!t1 || !t2 || same_tree(t1, t2)) |
| 576 | continue; |
| 577 | } |
| 578 | commit->object.flags |= TREECHANGE; |
| 579 | } |
| 580 | } |
| 581 | |
Linus Torvalds | 6da4016 | 2005-07-03 10:10:45 -0700 | [diff] [blame] | 582 | static struct commit_list *limit_list(struct commit_list *list) |
Linus Torvalds | 3b42a63 | 2005-06-02 09:25:44 -0700 | [diff] [blame] | 583 | { |
| 584 | struct commit_list *newlist = NULL; |
| 585 | struct commit_list **p = &newlist; |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 586 | while (list) { |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 587 | struct commit_list *entry = list; |
| 588 | struct commit *commit = list->item; |
Linus Torvalds | 3b42a63 | 2005-06-02 09:25:44 -0700 | [diff] [blame] | 589 | struct object *obj = &commit->object; |
| 590 | |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 591 | list = list->next; |
| 592 | free(entry); |
| 593 | |
Linus Torvalds | 27cfe2e | 2005-09-20 17:55:46 -0700 | [diff] [blame] | 594 | if (max_age != -1 && (commit->date < max_age)) |
| 595 | obj->flags |= UNINTERESTING; |
Linus Torvalds | 12d2a18 | 2005-07-03 13:29:54 -0700 | [diff] [blame] | 596 | if (unpacked && has_sha1_pack(obj->sha1)) |
| 597 | obj->flags |= UNINTERESTING; |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 598 | add_parents_to_list(commit, &list); |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 599 | if (obj->flags & UNINTERESTING) { |
Linus Torvalds | 3b42a63 | 2005-06-02 09:25:44 -0700 | [diff] [blame] | 600 | mark_parents_uninteresting(commit); |
| 601 | if (everybody_uninteresting(list)) |
| 602 | break; |
| 603 | continue; |
| 604 | } |
Linus Torvalds | 27cfe2e | 2005-09-20 17:55:46 -0700 | [diff] [blame] | 605 | if (min_age != -1 && (commit->date > min_age)) |
| 606 | continue; |
Linus Torvalds | 3b42a63 | 2005-06-02 09:25:44 -0700 | [diff] [blame] | 607 | p = &commit_list_insert(commit, p)->next; |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 608 | } |
Linus Torvalds | 5bdbaaa | 2005-09-15 15:14:29 -0700 | [diff] [blame] | 609 | if (tree_objects) |
| 610 | mark_edges_uninteresting(newlist); |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 611 | if (paths && dense) |
| 612 | compress_list(newlist); |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 613 | if (bisect_list) |
| 614 | newlist = find_bisection(newlist); |
Linus Torvalds | 3b42a63 | 2005-06-02 09:25:44 -0700 | [diff] [blame] | 615 | return newlist; |
| 616 | } |
| 617 | |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 618 | static void add_pending_object(struct object *obj, const char *name) |
| 619 | { |
| 620 | add_object(obj, &pending_objects, name); |
| 621 | } |
| 622 | |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 623 | static struct commit *get_commit_reference(const char *name, const unsigned char *sha1, unsigned int flags) |
Linus Torvalds | 3c90f03 | 2005-06-29 10:40:14 -0700 | [diff] [blame] | 624 | { |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 625 | struct object *object; |
Linus Torvalds | 3c90f03 | 2005-06-29 10:40:14 -0700 | [diff] [blame] | 626 | |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 627 | object = parse_object(sha1); |
| 628 | if (!object) |
| 629 | die("bad object %s", name); |
| 630 | |
| 631 | /* |
| 632 | * Tag object? Look what it points to.. |
| 633 | */ |
Junio C Hamano | 013aab8 | 2005-07-10 23:55:56 -0700 | [diff] [blame] | 634 | while (object->type == tag_type) { |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 635 | struct tag *tag = (struct tag *) object; |
| 636 | object->flags |= flags; |
| 637 | if (tag_objects && !(object->flags & UNINTERESTING)) |
| 638 | add_pending_object(object, tag->tag); |
Junio C Hamano | 013aab8 | 2005-07-10 23:55:56 -0700 | [diff] [blame] | 639 | object = parse_object(tag->tagged->sha1); |
Sergey Vlasov | 7f1335c | 2005-08-19 22:28:35 +0400 | [diff] [blame] | 640 | if (!object) |
| 641 | die("bad object %s", sha1_to_hex(tag->tagged->sha1)); |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Commit object? Just return it, we'll do all the complex |
| 646 | * reachability crud. |
| 647 | */ |
| 648 | if (object->type == commit_type) { |
| 649 | struct commit *commit = (struct commit *)object; |
| 650 | object->flags |= flags; |
| 651 | if (parse_commit(commit) < 0) |
| 652 | die("unable to parse commit %s", name); |
Linus Torvalds | 454fbbc | 2005-07-10 15:09:46 -0700 | [diff] [blame] | 653 | if (flags & UNINTERESTING) |
| 654 | mark_parents_uninteresting(commit); |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 655 | return commit; |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Tree object? Either mark it uniniteresting, or add it |
| 660 | * to the list of objects to look at later.. |
| 661 | */ |
| 662 | if (object->type == tree_type) { |
| 663 | struct tree *tree = (struct tree *)object; |
| 664 | if (!tree_objects) |
Linus Torvalds | 960bba0 | 2005-07-03 13:07:52 -0700 | [diff] [blame] | 665 | return NULL; |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 666 | if (flags & UNINTERESTING) { |
| 667 | mark_tree_uninteresting(tree); |
| 668 | return NULL; |
| 669 | } |
| 670 | add_pending_object(object, ""); |
| 671 | return NULL; |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * Blob object? You know the drill by now.. |
| 676 | */ |
| 677 | if (object->type == blob_type) { |
| 678 | struct blob *blob = (struct blob *)object; |
| 679 | if (!blob_objects) |
Linus Torvalds | 960bba0 | 2005-07-03 13:07:52 -0700 | [diff] [blame] | 680 | return NULL; |
Linus Torvalds | 36f8d17 | 2005-06-29 11:30:24 -0700 | [diff] [blame] | 681 | if (flags & UNINTERESTING) { |
| 682 | mark_blob_uninteresting(blob); |
| 683 | return NULL; |
| 684 | } |
| 685 | add_pending_object(object, ""); |
| 686 | return NULL; |
| 687 | } |
| 688 | die("%s is unknown object", name); |
Linus Torvalds | 3c90f03 | 2005-06-29 10:40:14 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 691 | static void handle_one_commit(struct commit *com, struct commit_list **lst) |
| 692 | { |
| 693 | if (!com || com->object.flags & SEEN) |
| 694 | return; |
| 695 | com->object.flags |= SEEN; |
| 696 | commit_list_insert(com, lst); |
| 697 | } |
| 698 | |
Junio C Hamano | e091eb9 | 2005-10-05 14:49:54 -0700 | [diff] [blame] | 699 | /* for_each_ref() callback does not allow user data -- Yuck. */ |
| 700 | static struct commit_list **global_lst; |
| 701 | |
| 702 | static int include_one_commit(const char *path, const unsigned char *sha1) |
| 703 | { |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 704 | struct commit *com = get_commit_reference(path, sha1, 0); |
Junio C Hamano | e091eb9 | 2005-10-05 14:49:54 -0700 | [diff] [blame] | 705 | handle_one_commit(com, global_lst); |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | static void handle_all(struct commit_list **lst) |
| 710 | { |
| 711 | global_lst = lst; |
| 712 | for_each_ref(include_one_commit); |
| 713 | global_lst = NULL; |
| 714 | } |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 715 | |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 716 | int main(int argc, const char **argv) |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 717 | { |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 718 | const char *prefix = setup_git_directory(); |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 719 | struct commit_list *list = NULL; |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 720 | int i, limited = 0; |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 721 | |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 722 | for (i = 1 ; i < argc; i++) { |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 723 | int flags; |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 724 | const char *arg = argv[i]; |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 725 | char *dotdot; |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 726 | struct commit *commit; |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 727 | unsigned char sha1[20]; |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 728 | |
| 729 | if (!strncmp(arg, "--max-count=", 12)) { |
| 730 | max_count = atoi(arg + 12); |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 731 | continue; |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 732 | } |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 733 | if (!strncmp(arg, "--max-age=", 10)) { |
| 734 | max_age = atoi(arg + 10); |
Linus Torvalds | 27cfe2e | 2005-09-20 17:55:46 -0700 | [diff] [blame] | 735 | limited = 1; |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 736 | continue; |
| 737 | } |
| 738 | if (!strncmp(arg, "--min-age=", 10)) { |
| 739 | min_age = atoi(arg + 10); |
Linus Torvalds | 27cfe2e | 2005-09-20 17:55:46 -0700 | [diff] [blame] | 740 | limited = 1; |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 741 | continue; |
| 742 | } |
| 743 | if (!strcmp(arg, "--header")) { |
| 744 | verbose_header = 1; |
| 745 | continue; |
| 746 | } |
Linus Torvalds | 000182e | 2005-06-05 09:02:03 -0700 | [diff] [blame] | 747 | if (!strncmp(arg, "--pretty", 8)) { |
| 748 | commit_format = get_commit_format(arg+8); |
Linus Torvalds | 9d97aa6 | 2005-06-01 08:42:22 -0700 | [diff] [blame] | 749 | verbose_header = 1; |
Linus Torvalds | 9d97aa6 | 2005-06-01 08:42:22 -0700 | [diff] [blame] | 750 | hdr_termination = '\n'; |
Junio C Hamano | d87449c | 2005-08-08 22:15:40 -0700 | [diff] [blame] | 751 | if (commit_format == CMIT_FMT_ONELINE) |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 752 | commit_prefix = ""; |
Junio C Hamano | d87449c | 2005-08-08 22:15:40 -0700 | [diff] [blame] | 753 | else |
Pavel Roskin | d998a08 | 2005-08-24 17:58:42 -0400 | [diff] [blame] | 754 | commit_prefix = "commit "; |
Linus Torvalds | 9d97aa6 | 2005-06-01 08:42:22 -0700 | [diff] [blame] | 755 | continue; |
| 756 | } |
Johannes Schindelin | 76cd8eb | 2005-08-08 11:37:21 +0200 | [diff] [blame] | 757 | if (!strncmp(arg, "--no-merges", 11)) { |
| 758 | no_merges = 1; |
| 759 | continue; |
| 760 | } |
Linus Torvalds | 9765800 | 2005-05-30 19:30:07 -0700 | [diff] [blame] | 761 | if (!strcmp(arg, "--parents")) { |
| 762 | show_parents = 1; |
| 763 | continue; |
| 764 | } |
Linus Torvalds | 8b3a1e0 | 2005-06-17 22:54:50 -0700 | [diff] [blame] | 765 | if (!strcmp(arg, "--bisect")) { |
| 766 | bisect_list = 1; |
| 767 | continue; |
| 768 | } |
Junio C Hamano | e091eb9 | 2005-10-05 14:49:54 -0700 | [diff] [blame] | 769 | if (!strcmp(arg, "--all")) { |
| 770 | handle_all(&list); |
| 771 | continue; |
| 772 | } |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 773 | if (!strcmp(arg, "--objects")) { |
Linus Torvalds | 3c90f03 | 2005-06-29 10:40:14 -0700 | [diff] [blame] | 774 | tag_objects = 1; |
Linus Torvalds | 9de4875 | 2005-06-24 22:56:58 -0700 | [diff] [blame] | 775 | tree_objects = 1; |
| 776 | blob_objects = 1; |
| 777 | continue; |
| 778 | } |
Linus Torvalds | 12d2a18 | 2005-07-03 13:29:54 -0700 | [diff] [blame] | 779 | if (!strcmp(arg, "--unpacked")) { |
| 780 | unpacked = 1; |
| 781 | limited = 1; |
| 782 | continue; |
| 783 | } |
Linus Torvalds | 12ba7ea | 2005-07-05 12:12:50 -0700 | [diff] [blame] | 784 | if (!strcmp(arg, "--merge-order")) { |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 785 | merge_order = 1; |
| 786 | continue; |
| 787 | } |
Linus Torvalds | 12ba7ea | 2005-07-05 12:12:50 -0700 | [diff] [blame] | 788 | if (!strcmp(arg, "--show-breaks")) { |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 789 | show_breaks = 1; |
| 790 | continue; |
| 791 | } |
Linus Torvalds | d2d02a4 | 2005-07-06 10:25:04 -0700 | [diff] [blame] | 792 | if (!strcmp(arg, "--topo-order")) { |
| 793 | topo_order = 1; |
Linus Torvalds | e6c3505 | 2005-07-06 10:51:43 -0700 | [diff] [blame] | 794 | limited = 1; |
Linus Torvalds | d2d02a4 | 2005-07-06 10:25:04 -0700 | [diff] [blame] | 795 | continue; |
| 796 | } |
Linus Torvalds | 1b9e059 | 2005-10-21 16:40:54 -0700 | [diff] [blame] | 797 | if (!strcmp(arg, "--dense")) { |
| 798 | dense = 1; |
| 799 | continue; |
| 800 | } |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 801 | if (!strcmp(arg, "--sparse")) { |
| 802 | dense = 0; |
| 803 | continue; |
| 804 | } |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 805 | if (!strcmp(arg, "--")) { |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 806 | i++; |
Linus Torvalds | cf48454 | 2005-10-20 21:25:09 -0700 | [diff] [blame] | 807 | break; |
| 808 | } |
Linus Torvalds | a6f68d4 | 2005-05-25 18:29:09 -0700 | [diff] [blame] | 809 | |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 810 | if (show_breaks && !merge_order) |
| 811 | usage(rev_list_usage); |
| 812 | |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 813 | flags = 0; |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 814 | dotdot = strstr(arg, ".."); |
| 815 | if (dotdot) { |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 816 | unsigned char from_sha1[20]; |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 817 | char *next = dotdot + 2; |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 818 | *dotdot = 0; |
Linus Torvalds | 2a7055a | 2005-09-16 17:53:19 -0700 | [diff] [blame] | 819 | if (!*next) |
| 820 | next = "HEAD"; |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 821 | if (!get_sha1(arg, from_sha1) && !get_sha1(next, sha1)) { |
| 822 | struct commit *exclude; |
| 823 | struct commit *include; |
| 824 | |
| 825 | exclude = get_commit_reference(arg, from_sha1, UNINTERESTING); |
| 826 | include = get_commit_reference(next, sha1, 0); |
| 827 | if (!exclude || !include) |
| 828 | die("Invalid revision range %s..%s", arg, next); |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 829 | limited = 1; |
| 830 | handle_one_commit(exclude, &list); |
| 831 | handle_one_commit(include, &list); |
| 832 | continue; |
| 833 | } |
Linus Torvalds | 2a7055a | 2005-09-16 17:53:19 -0700 | [diff] [blame] | 834 | *dotdot = '.'; |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 835 | } |
Linus Torvalds | 337cb3f | 2005-06-04 14:38:28 -0700 | [diff] [blame] | 836 | if (*arg == '^') { |
| 837 | flags = UNINTERESTING; |
| 838 | arg++; |
| 839 | limited = 1; |
| 840 | } |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 841 | if (get_sha1(arg, sha1) < 0) |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 842 | break; |
Linus Torvalds | 19a7e71 | 2005-10-26 08:18:13 -0700 | [diff] [blame] | 843 | commit = get_commit_reference(arg, sha1, flags); |
Junio C Hamano | 1215879 | 2005-08-04 02:31:15 -0700 | [diff] [blame] | 844 | handle_one_commit(commit, &list); |
Kay Sievers | fcfda02 | 2005-05-06 10:00:11 +0200 | [diff] [blame] | 845 | } |
| 846 | |
Linus Torvalds | 7b34c2f | 2005-10-25 15:24:55 -0700 | [diff] [blame] | 847 | if (!list) |
| 848 | usage(rev_list_usage); |
| 849 | |
| 850 | paths = get_pathspec(prefix, argv + i); |
| 851 | if (paths) { |
| 852 | limited = 1; |
| 853 | diff_tree_setup_paths(paths); |
| 854 | } |
| 855 | |
Linus Torvalds | 60ab26d | 2005-09-15 14:43:17 -0700 | [diff] [blame] | 856 | save_commit_buffer = verbose_header; |
Linus Torvalds | 8805cca | 2005-09-16 14:55:33 -0700 | [diff] [blame] | 857 | track_object_refs = 0; |
Linus Torvalds | 60ab26d | 2005-09-15 14:43:17 -0700 | [diff] [blame] | 858 | |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 859 | if (!merge_order) { |
Jon Seymour | a7336ae | 2005-07-07 10:59:13 +1000 | [diff] [blame] | 860 | sort_by_date(&list); |
Linus Torvalds | fe5f51c | 2005-10-18 18:29:17 -0700 | [diff] [blame] | 861 | if (list && !limited && max_count == 1 && |
| 862 | !tag_objects && !tree_objects && !blob_objects) { |
| 863 | show_commit(list->item); |
| 864 | return 0; |
| 865 | } |
Petr Baudis | 17ebe97 | 2005-06-08 22:59:43 +0200 | [diff] [blame] | 866 | if (limited) |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 867 | list = limit_list(list); |
Linus Torvalds | d2d02a4 | 2005-07-06 10:25:04 -0700 | [diff] [blame] | 868 | if (topo_order) |
| 869 | sort_in_topological_order(&list); |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 870 | show_commit_list(list); |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 871 | } else { |
Petr Baudis | dd53c7a | 2005-07-29 17:50:51 +0200 | [diff] [blame] | 872 | #ifndef NO_OPENSSL |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 873 | if (sort_list_in_merge_order(list, &process_commit)) { |
Petr Baudis | dd53c7a | 2005-07-29 17:50:51 +0200 | [diff] [blame] | 874 | die("merge order sort failed\n"); |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 875 | } |
Petr Baudis | dd53c7a | 2005-07-29 17:50:51 +0200 | [diff] [blame] | 876 | #else |
| 877 | die("merge order sort unsupported, OpenSSL not linked"); |
| 878 | #endif |
jon@blackcubes.dyndns.org | a3437b8 | 2005-06-06 15:39:40 +0000 | [diff] [blame] | 879 | } |
Linus Torvalds | 8906300 | 2005-05-30 18:46:32 -0700 | [diff] [blame] | 880 | |
Linus Torvalds | 6474510 | 2005-04-23 19:04:40 -0700 | [diff] [blame] | 881 | return 0; |
| 882 | } |