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