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