Merge part of pack-thin branch
[git/jnareb-git.git] / rev-list.c
blob15894005c5c0a8c722bf3511fd3c5a24973c4447
1 #include "cache.h"
2 #include "refs.h"
3 #include "tag.h"
4 #include "commit.h"
5 #include "tree.h"
6 #include "blob.h"
7 #include "epoch.h"
8 #include "diff.h"
10 #define SEEN (1u << 0)
11 #define INTERESTING (1u << 1)
12 #define COUNTED (1u << 2)
13 #define SHOWN (1u << 3)
14 #define TREECHANGE (1u << 4)
15 #define TMP_MARK (1u << 5) /* for isolated cases; clean after use */
17 static const char rev_list_usage[] =
18 "git-rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
19 " limiting output:\n"
20 " --max-count=nr\n"
21 " --max-age=epoch\n"
22 " --min-age=epoch\n"
23 " --sparse\n"
24 " --no-merges\n"
25 " --remove-empty\n"
26 " --all\n"
27 " ordering output:\n"
28 " --merge-order [ --show-breaks ]\n"
29 " --topo-order\n"
30 " --date-order\n"
31 " formatting output:\n"
32 " --parents\n"
33 " --objects | --objects-edge\n"
34 " --unpacked\n"
35 " --header | --pretty\n"
36 " --abbrev=nr | --no-abbrev\n"
37 " special purpose:\n"
38 " --bisect"
41 static int dense = 1;
42 static int unpacked = 0;
43 static int bisect_list = 0;
44 static int tag_objects = 0;
45 static int tree_objects = 0;
46 static int blob_objects = 0;
47 static int edge_hint = 0;
48 static int verbose_header = 0;
49 static int abbrev = DEFAULT_ABBREV;
50 static int show_parents = 0;
51 static int hdr_termination = 0;
52 static const char *commit_prefix = "";
53 static unsigned long max_age = -1;
54 static unsigned long min_age = -1;
55 static int max_count = -1;
56 static enum cmit_fmt commit_format = CMIT_FMT_RAW;
57 static int merge_order = 0;
58 static int show_breaks = 0;
59 static int stop_traversal = 0;
60 static int topo_order = 0;
61 static int lifo = 1;
62 static int no_merges = 0;
63 static const char **paths = NULL;
64 static int remove_empty_trees = 0;
66 static void show_commit(struct commit *commit)
68 commit->object.flags |= SHOWN;
69 if (show_breaks) {
70 commit_prefix = "| ";
71 if (commit->object.flags & DISCONTINUITY) {
72 commit_prefix = "^ ";
73 } else if (commit->object.flags & BOUNDARY) {
74 commit_prefix = "= ";
77 printf("%s%s", commit_prefix, sha1_to_hex(commit->object.sha1));
78 if (show_parents) {
79 struct commit_list *parents = commit->parents;
80 while (parents) {
81 struct object *o = &(parents->item->object);
82 parents = parents->next;
83 if (o->flags & TMP_MARK)
84 continue;
85 printf(" %s", sha1_to_hex(o->sha1));
86 o->flags |= TMP_MARK;
88 /* TMP_MARK is a general purpose flag that can
89 * be used locally, but the user should clean
90 * things up after it is done with them.
92 for (parents = commit->parents;
93 parents;
94 parents = parents->next)
95 parents->item->object.flags &= ~TMP_MARK;
97 if (commit_format == CMIT_FMT_ONELINE)
98 putchar(' ');
99 else
100 putchar('\n');
102 if (verbose_header) {
103 static char pretty_header[16384];
104 pretty_print_commit(commit_format, commit, ~0, pretty_header, sizeof(pretty_header), abbrev);
105 printf("%s%c", pretty_header, hdr_termination);
107 fflush(stdout);
110 static int rewrite_one(struct commit **pp)
112 for (;;) {
113 struct commit *p = *pp;
114 if (p->object.flags & (TREECHANGE | UNINTERESTING))
115 return 0;
116 if (!p->parents)
117 return -1;
118 *pp = p->parents->item;
122 static void rewrite_parents(struct commit *commit)
124 struct commit_list **pp = &commit->parents;
125 while (*pp) {
126 struct commit_list *parent = *pp;
127 if (rewrite_one(&parent->item) < 0) {
128 *pp = parent->next;
129 continue;
131 pp = &parent->next;
135 static int filter_commit(struct commit * commit)
137 if (stop_traversal && (commit->object.flags & BOUNDARY))
138 return STOP;
139 if (commit->object.flags & (UNINTERESTING|SHOWN))
140 return CONTINUE;
141 if (min_age != -1 && (commit->date > min_age))
142 return CONTINUE;
143 if (max_age != -1 && (commit->date < max_age)) {
144 stop_traversal=1;
145 return CONTINUE;
147 if (no_merges && (commit->parents && commit->parents->next))
148 return CONTINUE;
149 if (paths && dense) {
150 if (!(commit->object.flags & TREECHANGE))
151 return CONTINUE;
152 rewrite_parents(commit);
154 return DO;
157 static int process_commit(struct commit * commit)
159 int action=filter_commit(commit);
161 if (action == STOP) {
162 return STOP;
165 if (action == CONTINUE) {
166 return CONTINUE;
169 if (max_count != -1 && !max_count--)
170 return STOP;
172 show_commit(commit);
174 return CONTINUE;
177 static struct object_list **add_object(struct object *obj, struct object_list **p, const char *name)
179 struct object_list *entry = xmalloc(sizeof(*entry));
180 entry->item = obj;
181 entry->next = *p;
182 entry->name = name;
183 *p = entry;
184 return &entry->next;
187 static struct object_list **process_blob(struct blob *blob, struct object_list **p, const char *name)
189 struct object *obj = &blob->object;
191 if (!blob_objects)
192 return p;
193 if (obj->flags & (UNINTERESTING | SEEN))
194 return p;
195 obj->flags |= SEEN;
196 return add_object(obj, p, name);
199 static struct object_list **process_tree(struct tree *tree, struct object_list **p, const char *name)
201 struct object *obj = &tree->object;
202 struct tree_entry_list *entry;
204 if (!tree_objects)
205 return p;
206 if (obj->flags & (UNINTERESTING | SEEN))
207 return p;
208 if (parse_tree(tree) < 0)
209 die("bad tree object %s", sha1_to_hex(obj->sha1));
210 obj->flags |= SEEN;
211 p = add_object(obj, p, name);
212 entry = tree->entries;
213 tree->entries = NULL;
214 while (entry) {
215 struct tree_entry_list *next = entry->next;
216 if (entry->directory)
217 p = process_tree(entry->item.tree, p, entry->name);
218 else
219 p = process_blob(entry->item.blob, p, entry->name);
220 free(entry);
221 entry = next;
223 return p;
226 static struct object_list *pending_objects = NULL;
228 static void show_commit_list(struct commit_list *list)
230 struct object_list *objects = NULL, **p = &objects, *pending;
231 while (list) {
232 struct commit *commit = pop_most_recent_commit(&list, SEEN);
234 p = process_tree(commit->tree, p, "");
235 if (process_commit(commit) == STOP)
236 break;
238 for (pending = pending_objects; pending; pending = pending->next) {
239 struct object *obj = pending->item;
240 const char *name = pending->name;
241 if (obj->flags & (UNINTERESTING | SEEN))
242 continue;
243 if (obj->type == tag_type) {
244 obj->flags |= SEEN;
245 p = add_object(obj, p, name);
246 continue;
248 if (obj->type == tree_type) {
249 p = process_tree((struct tree *)obj, p, name);
250 continue;
252 if (obj->type == blob_type) {
253 p = process_blob((struct blob *)obj, p, name);
254 continue;
256 die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
258 while (objects) {
259 /* An object with name "foo\n0000000..." can be used to
260 * confuse downstream git-pack-objects very badly.
262 const char *ep = strchr(objects->name, '\n');
263 if (ep) {
264 printf("%s %.*s\n", sha1_to_hex(objects->item->sha1),
265 (int) (ep - objects->name),
266 objects->name);
268 else
269 printf("%s %s\n", sha1_to_hex(objects->item->sha1), objects->name);
270 objects = objects->next;
274 static void mark_blob_uninteresting(struct blob *blob)
276 if (!blob_objects)
277 return;
278 if (blob->object.flags & UNINTERESTING)
279 return;
280 blob->object.flags |= UNINTERESTING;
283 static void mark_tree_uninteresting(struct tree *tree)
285 struct object *obj = &tree->object;
286 struct tree_entry_list *entry;
288 if (!tree_objects)
289 return;
290 if (obj->flags & UNINTERESTING)
291 return;
292 obj->flags |= UNINTERESTING;
293 if (!has_sha1_file(obj->sha1))
294 return;
295 if (parse_tree(tree) < 0)
296 die("bad tree %s", sha1_to_hex(obj->sha1));
297 entry = tree->entries;
298 tree->entries = NULL;
299 while (entry) {
300 struct tree_entry_list *next = entry->next;
301 if (entry->directory)
302 mark_tree_uninteresting(entry->item.tree);
303 else
304 mark_blob_uninteresting(entry->item.blob);
305 free(entry);
306 entry = next;
310 static void mark_parents_uninteresting(struct commit *commit)
312 struct commit_list *parents = commit->parents;
314 while (parents) {
315 struct commit *commit = parents->item;
316 commit->object.flags |= UNINTERESTING;
319 * Normally we haven't parsed the parent
320 * yet, so we won't have a parent of a parent
321 * here. However, it may turn out that we've
322 * reached this commit some other way (where it
323 * wasn't uninteresting), in which case we need
324 * to mark its parents recursively too..
326 if (commit->parents)
327 mark_parents_uninteresting(commit);
330 * A missing commit is ok iff its parent is marked
331 * uninteresting.
333 * We just mark such a thing parsed, so that when
334 * it is popped next time around, we won't be trying
335 * to parse it and get an error.
337 if (!has_sha1_file(commit->object.sha1))
338 commit->object.parsed = 1;
339 parents = parents->next;
343 static int everybody_uninteresting(struct commit_list *orig)
345 struct commit_list *list = orig;
346 while (list) {
347 struct commit *commit = list->item;
348 list = list->next;
349 if (commit->object.flags & UNINTERESTING)
350 continue;
351 return 0;
353 return 1;
357 * This is a truly stupid algorithm, but it's only
358 * used for bisection, and we just don't care enough.
360 * We care just barely enough to avoid recursing for
361 * non-merge entries.
363 static int count_distance(struct commit_list *entry)
365 int nr = 0;
367 while (entry) {
368 struct commit *commit = entry->item;
369 struct commit_list *p;
371 if (commit->object.flags & (UNINTERESTING | COUNTED))
372 break;
373 if (!paths || (commit->object.flags & TREECHANGE))
374 nr++;
375 commit->object.flags |= COUNTED;
376 p = commit->parents;
377 entry = p;
378 if (p) {
379 p = p->next;
380 while (p) {
381 nr += count_distance(p);
382 p = p->next;
387 return nr;
390 static void clear_distance(struct commit_list *list)
392 while (list) {
393 struct commit *commit = list->item;
394 commit->object.flags &= ~COUNTED;
395 list = list->next;
399 static struct commit_list *find_bisection(struct commit_list *list)
401 int nr, closest;
402 struct commit_list *p, *best;
404 nr = 0;
405 p = list;
406 while (p) {
407 if (!paths || (p->item->object.flags & TREECHANGE))
408 nr++;
409 p = p->next;
411 closest = 0;
412 best = list;
414 for (p = list; p; p = p->next) {
415 int distance;
417 if (paths && !(p->item->object.flags & TREECHANGE))
418 continue;
420 distance = count_distance(p);
421 clear_distance(list);
422 if (nr - distance < distance)
423 distance = nr - distance;
424 if (distance > closest) {
425 best = p;
426 closest = distance;
429 if (best)
430 best->next = NULL;
431 return best;
434 static void mark_edge_parents_uninteresting(struct commit *commit)
436 struct commit_list *parents;
438 for (parents = commit->parents; parents; parents = parents->next) {
439 struct commit *parent = parents->item;
440 if (!(parent->object.flags & UNINTERESTING))
441 continue;
442 mark_tree_uninteresting(parent->tree);
443 if (edge_hint)
444 printf("-%s\n", sha1_to_hex(parent->object.sha1));
448 static void mark_edges_uninteresting(struct commit_list *list)
450 for ( ; list; list = list->next) {
451 struct commit *commit = list->item;
453 if (commit->object.flags & UNINTERESTING) {
454 mark_tree_uninteresting(commit->tree);
455 continue;
457 mark_edge_parents_uninteresting(commit);
461 #define TREE_SAME 0
462 #define TREE_NEW 1
463 #define TREE_DIFFERENT 2
464 static int tree_difference = TREE_SAME;
466 static void file_add_remove(struct diff_options *options,
467 int addremove, unsigned mode,
468 const unsigned char *sha1,
469 const char *base, const char *path)
471 int diff = TREE_DIFFERENT;
474 * Is it an add of a new file? It means that
475 * the old tree didn't have it at all, so we
476 * will turn "TREE_SAME" -> "TREE_NEW", but
477 * leave any "TREE_DIFFERENT" alone (and if
478 * it already was "TREE_NEW", we'll keep it
479 * "TREE_NEW" of course).
481 if (addremove == '+') {
482 diff = tree_difference;
483 if (diff != TREE_SAME)
484 return;
485 diff = TREE_NEW;
487 tree_difference = diff;
490 static void file_change(struct diff_options *options,
491 unsigned old_mode, unsigned new_mode,
492 const unsigned char *old_sha1,
493 const unsigned char *new_sha1,
494 const char *base, const char *path)
496 tree_difference = TREE_DIFFERENT;
499 static struct diff_options diff_opt = {
500 .recursive = 1,
501 .add_remove = file_add_remove,
502 .change = file_change,
505 static int compare_tree(struct tree *t1, struct tree *t2)
507 if (!t1)
508 return TREE_NEW;
509 if (!t2)
510 return TREE_DIFFERENT;
511 tree_difference = TREE_SAME;
512 if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", &diff_opt) < 0)
513 return TREE_DIFFERENT;
514 return tree_difference;
517 static int same_tree_as_empty(struct tree *t1)
519 int retval;
520 void *tree;
521 struct tree_desc empty, real;
523 if (!t1)
524 return 0;
526 tree = read_object_with_reference(t1->object.sha1, "tree", &real.size, NULL);
527 if (!tree)
528 return 0;
529 real.buf = tree;
531 empty.buf = "";
532 empty.size = 0;
534 tree_difference = 0;
535 retval = diff_tree(&empty, &real, "", &diff_opt);
536 free(tree);
538 return retval >= 0 && !tree_difference;
541 static void try_to_simplify_commit(struct commit *commit)
543 struct commit_list **pp, *parent;
545 if (!commit->tree)
546 return;
548 if (!commit->parents) {
549 if (!same_tree_as_empty(commit->tree))
550 commit->object.flags |= TREECHANGE;
551 return;
554 pp = &commit->parents;
555 while ((parent = *pp) != NULL) {
556 struct commit *p = parent->item;
558 if (p->object.flags & UNINTERESTING) {
559 pp = &parent->next;
560 continue;
563 parse_commit(p);
564 switch (compare_tree(p->tree, commit->tree)) {
565 case TREE_SAME:
566 parent->next = NULL;
567 commit->parents = parent;
568 return;
570 case TREE_NEW:
571 if (remove_empty_trees && same_tree_as_empty(p->tree)) {
572 *pp = parent->next;
573 continue;
575 /* fallthrough */
576 case TREE_DIFFERENT:
577 pp = &parent->next;
578 continue;
580 die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1));
582 commit->object.flags |= TREECHANGE;
585 static void add_parents_to_list(struct commit *commit, struct commit_list **list)
587 struct commit_list *parent = commit->parents;
590 * If the commit is uninteresting, don't try to
591 * prune parents - we want the maximal uninteresting
592 * set.
594 * Normally we haven't parsed the parent
595 * yet, so we won't have a parent of a parent
596 * here. However, it may turn out that we've
597 * reached this commit some other way (where it
598 * wasn't uninteresting), in which case we need
599 * to mark its parents recursively too..
601 if (commit->object.flags & UNINTERESTING) {
602 while (parent) {
603 struct commit *p = parent->item;
604 parent = parent->next;
605 parse_commit(p);
606 p->object.flags |= UNINTERESTING;
607 if (p->parents)
608 mark_parents_uninteresting(p);
609 if (p->object.flags & SEEN)
610 continue;
611 p->object.flags |= SEEN;
612 insert_by_date(p, list);
614 return;
618 * Ok, the commit wasn't uninteresting. Try to
619 * simplify the commit history and find the parent
620 * that has no differences in the path set if one exists.
622 if (paths)
623 try_to_simplify_commit(commit);
625 parent = commit->parents;
626 while (parent) {
627 struct commit *p = parent->item;
629 parent = parent->next;
631 parse_commit(p);
632 if (p->object.flags & SEEN)
633 continue;
634 p->object.flags |= SEEN;
635 insert_by_date(p, list);
639 static struct commit_list *limit_list(struct commit_list *list)
641 struct commit_list *newlist = NULL;
642 struct commit_list **p = &newlist;
643 while (list) {
644 struct commit_list *entry = list;
645 struct commit *commit = list->item;
646 struct object *obj = &commit->object;
648 list = list->next;
649 free(entry);
651 if (max_age != -1 && (commit->date < max_age))
652 obj->flags |= UNINTERESTING;
653 if (unpacked && has_sha1_pack(obj->sha1))
654 obj->flags |= UNINTERESTING;
655 add_parents_to_list(commit, &list);
656 if (obj->flags & UNINTERESTING) {
657 mark_parents_uninteresting(commit);
658 if (everybody_uninteresting(list))
659 break;
660 continue;
662 if (min_age != -1 && (commit->date > min_age))
663 continue;
664 p = &commit_list_insert(commit, p)->next;
666 if (tree_objects)
667 mark_edges_uninteresting(newlist);
668 if (bisect_list)
669 newlist = find_bisection(newlist);
670 return newlist;
673 static void add_pending_object(struct object *obj, const char *name)
675 add_object(obj, &pending_objects, name);
678 static struct commit *get_commit_reference(const char *name, const unsigned char *sha1, unsigned int flags)
680 struct object *object;
682 object = parse_object(sha1);
683 if (!object)
684 die("bad object %s", name);
687 * Tag object? Look what it points to..
689 while (object->type == tag_type) {
690 struct tag *tag = (struct tag *) object;
691 object->flags |= flags;
692 if (tag_objects && !(object->flags & UNINTERESTING))
693 add_pending_object(object, tag->tag);
694 object = parse_object(tag->tagged->sha1);
695 if (!object)
696 die("bad object %s", sha1_to_hex(tag->tagged->sha1));
700 * Commit object? Just return it, we'll do all the complex
701 * reachability crud.
703 if (object->type == commit_type) {
704 struct commit *commit = (struct commit *)object;
705 object->flags |= flags;
706 if (parse_commit(commit) < 0)
707 die("unable to parse commit %s", name);
708 if (flags & UNINTERESTING)
709 mark_parents_uninteresting(commit);
710 return commit;
714 * Tree object? Either mark it uniniteresting, or add it
715 * to the list of objects to look at later..
717 if (object->type == tree_type) {
718 struct tree *tree = (struct tree *)object;
719 if (!tree_objects)
720 return NULL;
721 if (flags & UNINTERESTING) {
722 mark_tree_uninteresting(tree);
723 return NULL;
725 add_pending_object(object, "");
726 return NULL;
730 * Blob object? You know the drill by now..
732 if (object->type == blob_type) {
733 struct blob *blob = (struct blob *)object;
734 if (!blob_objects)
735 return NULL;
736 if (flags & UNINTERESTING) {
737 mark_blob_uninteresting(blob);
738 return NULL;
740 add_pending_object(object, "");
741 return NULL;
743 die("%s is unknown object", name);
746 static void handle_one_commit(struct commit *com, struct commit_list **lst)
748 if (!com || com->object.flags & SEEN)
749 return;
750 com->object.flags |= SEEN;
751 commit_list_insert(com, lst);
754 /* for_each_ref() callback does not allow user data -- Yuck. */
755 static struct commit_list **global_lst;
757 static int include_one_commit(const char *path, const unsigned char *sha1)
759 struct commit *com = get_commit_reference(path, sha1, 0);
760 handle_one_commit(com, global_lst);
761 return 0;
764 static void handle_all(struct commit_list **lst)
766 global_lst = lst;
767 for_each_ref(include_one_commit);
768 global_lst = NULL;
771 int main(int argc, const char **argv)
773 const char *prefix = setup_git_directory();
774 struct commit_list *list = NULL;
775 int i, limited = 0;
777 for (i = 1 ; i < argc; i++) {
778 int flags;
779 const char *arg = argv[i];
780 char *dotdot;
781 struct commit *commit;
782 unsigned char sha1[20];
784 /* accept -<digit>, like traditilnal "head" */
785 if ((*arg == '-') && isdigit(arg[1])) {
786 max_count = atoi(arg + 1);
787 continue;
789 if (!strcmp(arg, "-n")) {
790 if (++i >= argc)
791 die("-n requires an argument");
792 max_count = atoi(argv[i]);
793 continue;
795 if (!strncmp(arg,"-n",2)) {
796 max_count = atoi(arg + 2);
797 continue;
799 if (!strncmp(arg, "--max-count=", 12)) {
800 max_count = atoi(arg + 12);
801 continue;
803 if (!strncmp(arg, "--max-age=", 10)) {
804 max_age = atoi(arg + 10);
805 limited = 1;
806 continue;
808 if (!strncmp(arg, "--min-age=", 10)) {
809 min_age = atoi(arg + 10);
810 limited = 1;
811 continue;
813 if (!strcmp(arg, "--header")) {
814 verbose_header = 1;
815 continue;
817 if (!strcmp(arg, "--no-abbrev")) {
818 abbrev = 0;
819 continue;
821 if (!strncmp(arg, "--abbrev=", 9)) {
822 abbrev = strtoul(arg + 9, NULL, 10);
823 if (abbrev && abbrev < MINIMUM_ABBREV)
824 abbrev = MINIMUM_ABBREV;
825 else if (40 < abbrev)
826 abbrev = 40;
827 continue;
829 if (!strncmp(arg, "--pretty", 8)) {
830 commit_format = get_commit_format(arg+8);
831 verbose_header = 1;
832 hdr_termination = '\n';
833 if (commit_format == CMIT_FMT_ONELINE)
834 commit_prefix = "";
835 else
836 commit_prefix = "commit ";
837 continue;
839 if (!strncmp(arg, "--no-merges", 11)) {
840 no_merges = 1;
841 continue;
843 if (!strcmp(arg, "--parents")) {
844 show_parents = 1;
845 continue;
847 if (!strcmp(arg, "--bisect")) {
848 bisect_list = 1;
849 continue;
851 if (!strcmp(arg, "--all")) {
852 handle_all(&list);
853 continue;
855 if (!strcmp(arg, "--objects")) {
856 tag_objects = 1;
857 tree_objects = 1;
858 blob_objects = 1;
859 continue;
861 if (!strcmp(arg, "--objects-edge")) {
862 tag_objects = 1;
863 tree_objects = 1;
864 blob_objects = 1;
865 edge_hint = 1;
866 continue;
868 if (!strcmp(arg, "--unpacked")) {
869 unpacked = 1;
870 limited = 1;
871 continue;
873 if (!strcmp(arg, "--merge-order")) {
874 merge_order = 1;
875 continue;
877 if (!strcmp(arg, "--show-breaks")) {
878 show_breaks = 1;
879 continue;
881 if (!strcmp(arg, "--topo-order")) {
882 topo_order = 1;
883 lifo = 1;
884 limited = 1;
885 continue;
887 if (!strcmp(arg, "--date-order")) {
888 topo_order = 1;
889 lifo = 0;
890 limited = 1;
891 continue;
893 if (!strcmp(arg, "--dense")) {
894 dense = 1;
895 continue;
897 if (!strcmp(arg, "--sparse")) {
898 dense = 0;
899 continue;
901 if (!strcmp(arg, "--remove-empty")) {
902 remove_empty_trees = 1;
903 continue;
905 if (!strcmp(arg, "--")) {
906 i++;
907 break;
910 if (show_breaks && !merge_order)
911 usage(rev_list_usage);
913 flags = 0;
914 dotdot = strstr(arg, "..");
915 if (dotdot) {
916 unsigned char from_sha1[20];
917 char *next = dotdot + 2;
918 *dotdot = 0;
919 if (!*next)
920 next = "HEAD";
921 if (!get_sha1(arg, from_sha1) && !get_sha1(next, sha1)) {
922 struct commit *exclude;
923 struct commit *include;
925 exclude = get_commit_reference(arg, from_sha1, UNINTERESTING);
926 include = get_commit_reference(next, sha1, 0);
927 if (!exclude || !include)
928 die("Invalid revision range %s..%s", arg, next);
929 limited = 1;
930 handle_one_commit(exclude, &list);
931 handle_one_commit(include, &list);
932 continue;
934 *dotdot = '.';
936 if (*arg == '^') {
937 flags = UNINTERESTING;
938 arg++;
939 limited = 1;
941 if (get_sha1(arg, sha1) < 0) {
942 struct stat st;
943 if (lstat(arg, &st) < 0)
944 die("'%s': %s", arg, strerror(errno));
945 break;
947 commit = get_commit_reference(arg, sha1, flags);
948 handle_one_commit(commit, &list);
951 if (!list &&
952 (!(tag_objects||tree_objects||blob_objects) && !pending_objects))
953 usage(rev_list_usage);
955 paths = get_pathspec(prefix, argv + i);
956 if (paths) {
957 limited = 1;
958 diff_tree_setup_paths(paths);
961 save_commit_buffer = verbose_header;
962 track_object_refs = 0;
964 if (!merge_order) {
965 sort_by_date(&list);
966 if (list && !limited && max_count == 1 &&
967 !tag_objects && !tree_objects && !blob_objects) {
968 show_commit(list->item);
969 return 0;
971 if (limited)
972 list = limit_list(list);
973 if (topo_order)
974 sort_in_topological_order(&list, lifo);
975 show_commit_list(list);
976 } else {
977 #ifndef NO_OPENSSL
978 if (sort_list_in_merge_order(list, &process_commit)) {
979 die("merge order sort failed\n");
981 #else
982 die("merge order sort unsupported, OpenSSL not linked");
983 #endif
986 return 0;