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