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