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