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