Merge branch 'jk/cached-commit-buffer'
authorJunio C Hamano <gitster@pobox.com>
Tue, 6 Mar 2018 22:54:05 +0000 (14:54 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Mar 2018 22:54:05 +0000 (14:54 -0800)
Code clean-up.

* jk/cached-commit-buffer:
  revision: drop --show-all option
  commit: drop uses of get_cached_commit_buffer()

1  2 
builtin/rev-list.c
log-tree.c
revision.c
revision.h

diff --combined builtin/rev-list.c
@@@ -15,7 -15,6 +15,7 @@@
  #include "progress.h"
  #include "reflog-walk.h"
  #include "oidset.h"
 +#include "packfile.h"
  
  static const char rev_list_usage[] =
  "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@@ -68,7 -67,6 +68,7 @@@ enum missing_action 
        MA_ERROR = 0,    /* fail if any missing objects are encountered */
        MA_ALLOW_ANY,    /* silently allow ALL missing objects */
        MA_PRINT,        /* print ALL missing objects in special section */
 +      MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
  };
  static enum missing_action arg_missing_action;
  
@@@ -134,7 -132,7 +134,7 @@@ static void show_commit(struct commit *
        else
                putchar('\n');
  
-       if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) {
+       if (revs->verbose_header) {
                struct strbuf buf = STRBUF_INIT;
                struct pretty_print_context ctx = {0};
                ctx.abbrev = revs->abbrev;
@@@ -199,12 -197,6 +199,12 @@@ static void finish_commit(struct commi
  
  static inline void finish_object__ma(struct object *obj)
  {
 +      /*
 +       * Whether or not we try to dynamically fetch missing objects
 +       * from the server, we currently DO NOT have the object.  We
 +       * can either print, allow (ignore), or conditionally allow
 +       * (ignore) them.
 +       */
        switch (arg_missing_action) {
        case MA_ERROR:
                die("missing blob object '%s'", oid_to_hex(&obj->oid));
                oidset_insert(&missing_objects, &obj->oid);
                return;
  
 +      case MA_ALLOW_PROMISOR:
 +              if (is_promisor_object(&obj->oid))
 +                      return;
 +              die("unexpected missing blob object '%s'",
 +                  oid_to_hex(&obj->oid));
 +              return;
 +
        default:
                BUG("unhandled missing_action");
                return;
        }
  }
  
 -static void finish_object(struct object *obj, const char *name, void *cb_data)
 +static int finish_object(struct object *obj, const char *name, void *cb_data)
  {
        struct rev_list_info *info = cb_data;
 -      if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
 +      if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) {
                finish_object__ma(obj);
 +              return 1;
 +      }
        if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
                parse_object(&obj->oid);
 +      return 0;
  }
  
  static void show_object(struct object *obj, const char *name, void *cb_data)
  {
        struct rev_list_info *info = cb_data;
 -      finish_object(obj, name, cb_data);
 +      if (finish_object(obj, name, cb_data))
 +              return;
        display_progress(progress, ++progress_counter);
        if (info->flags & REV_LIST_QUIET)
                return;
@@@ -334,19 -315,11 +334,19 @@@ static inline int parse_missing_action_
  
        if (!strcmp(value, "allow-any")) {
                arg_missing_action = MA_ALLOW_ANY;
 +              fetch_if_missing = 0;
                return 1;
        }
  
        if (!strcmp(value, "print")) {
                arg_missing_action = MA_PRINT;
 +              fetch_if_missing = 0;
 +              return 1;
 +      }
 +
 +      if (!strcmp(value, "allow-promisor")) {
 +              arg_missing_action = MA_ALLOW_PROMISOR;
 +              fetch_if_missing = 0;
                return 1;
        }
  
@@@ -371,35 -344,6 +371,35 @@@ int cmd_rev_list(int argc, const char *
        init_revisions(&revs, prefix);
        revs.abbrev = DEFAULT_ABBREV;
        revs.commit_format = CMIT_FMT_UNSPECIFIED;
 +
 +      /*
 +       * Scan the argument list before invoking setup_revisions(), so that we
 +       * know if fetch_if_missing needs to be set to 0.
 +       *
 +       * "--exclude-promisor-objects" acts as a pre-filter on missing objects
 +       * by not crossing the boundary from realized objects to promisor
 +       * objects.
 +       *
 +       * Let "--missing" to conditionally set fetch_if_missing.
 +       */
 +      for (i = 1; i < argc; i++) {
 +              const char *arg = argv[i];
 +              if (!strcmp(arg, "--exclude-promisor-objects")) {
 +                      fetch_if_missing = 0;
 +                      revs.exclude_promisor_objects = 1;
 +                      break;
 +              }
 +      }
 +      for (i = 1; i < argc; i++) {
 +              const char *arg = argv[i];
 +              if (skip_prefix(arg, "--missing=", &arg)) {
 +                      if (revs.exclude_promisor_objects)
 +                              die(_("cannot combine --exclude-promisor-objects and --missing"));
 +                      if (parse_missing_action_value(arg))
 +                              break;
 +              }
 +      }
 +
        argc = setup_revisions(argc, argv, &revs, NULL);
  
        memset(&info, 0, sizeof(info));
                        continue;
                }
                if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
 -                      list_objects_filter_release(&filter_options);
 +                      list_objects_filter_set_no_filter(&filter_options);
                        continue;
                }
                if (!strcmp(arg, "--filter-print-omitted")) {
                        continue;
                }
  
 -              if (skip_prefix(arg, "--missing=", &arg) &&
 -                  parse_missing_action_value(arg))
 -                      continue;
 +              if (!strcmp(arg, "--exclude-promisor-objects"))
 +                      continue; /* already handled above */
 +              if (skip_prefix(arg, "--missing=", &arg))
 +                      continue; /* already handled above */
  
                usage(rev_list_usage);
  
diff --combined log-tree.c
@@@ -499,7 -499,7 +499,7 @@@ static void show_one_mergetag(struct co
        int status, nth;
        size_t payload_size, gpg_message_offset;
  
 -      hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
 +      hash_object_file(extra->value, extra->len, typename(OBJ_TAG), &oid);
        tag = lookup_tag(&oid);
        if (!tag)
                return; /* error message already given */
@@@ -659,9 -659,6 +659,6 @@@ void show_log(struct rev_info *opt
                show_mergetag(opt, commit);
        }
  
-       if (!get_cached_commit_buffer(commit, NULL))
-               return;
        if (opt->show_notes) {
                int raw;
                struct strbuf notebuf = STRBUF_INIT;
diff --combined revision.c
@@@ -198,8 -198,6 +198,8 @@@ static struct object *get_reference(str
        if (!object) {
                if (revs->ignore_missing)
                        return object;
 +              if (revs->exclude_promisor_objects && is_promisor_object(oid))
 +                      return NULL;
                die("bad object %s", name);
        }
        object->flags |= flags;
@@@ -801,17 -799,9 +801,17 @@@ static int add_parents_to_list(struct r
  
        for (parent = commit->parents; parent; parent = parent->next) {
                struct commit *p = parent->item;
 -
 -              if (parse_commit_gently(p, revs->ignore_missing_links) < 0)
 +              int gently = revs->ignore_missing_links ||
 +                           revs->exclude_promisor_objects;
 +              if (parse_commit_gently(p, gently) < 0) {
 +                      if (revs->exclude_promisor_objects &&
 +                          is_promisor_object(&p->object.oid)) {
 +                              if (revs->first_parent_only)
 +                                      break;
 +                              continue;
 +                      }
                        return -1;
 +              }
                if (revs->show_source && !p->util)
                        p->util = commit->util;
                p->object.flags |= left_flag;
@@@ -1065,14 -1055,9 +1065,9 @@@ static int limit_list(struct rev_info *
                        return -1;
                if (obj->flags & UNINTERESTING) {
                        mark_parents_uninteresting(commit);
-                       if (revs->show_all)
-                               p = &commit_list_insert(commit, p)->next;
                        slop = still_interesting(list, date, slop, &interesting_cache);
                        if (slop)
                                continue;
-                       /* If showing all, add the whole pending list to the end */
-                       if (revs->show_all)
-                               *p = list;
                        break;
                }
                if (revs->min_age != -1 && (commit->date > revs->min_age))
@@@ -1362,8 -1347,7 +1357,8 @@@ void add_index_objects_to_pending(struc
                        continue; /* current index already taken care of */
  
                if (read_index_from(&istate,
 -                                  worktree_git_path(wt, "index")) > 0)
 +                                  worktree_git_path(wt, "index"),
 +                                  get_worktree_git_dir(wt)) > 0)
                        do_add_index_objects_to_pending(revs, &istate);
                discard_index(&istate);
        }
@@@ -1864,8 -1848,6 +1859,6 @@@ static int handle_revision_opt(struct r
                revs->dense = 1;
        } else if (!strcmp(arg, "--sparse")) {
                revs->dense = 0;
-       } else if (!strcmp(arg, "--show-all")) {
-               revs->show_all = 1;
        } else if (!strcmp(arg, "--in-commit-order")) {
                revs->tree_blobs_in_commit_order = 1;
        } else if (!strcmp(arg, "--remove-empty")) {
                revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_ERE;
        } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
                revs->grep_filter.ignore_case = 1;
 -              revs->diffopt.flags.pickaxe_ignore_case = 1;
 +              revs->diffopt.pickaxe_opts |= DIFF_PICKAXE_IGNORE_CASE;
        } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
                revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;
        } else if (!strcmp(arg, "--perl-regexp") || !strcmp(arg, "-P")) {
                revs->limited = 1;
        } else if (!strcmp(arg, "--ignore-missing")) {
                revs->ignore_missing = 1;
 +      } else if (!strcmp(arg, "--exclude-promisor-objects")) {
 +              if (fetch_if_missing)
 +                      die("BUG: exclude_promisor_objects can only be used when fetch_if_missing is 0");
 +              revs->exclude_promisor_objects = 1;
        } else {
                int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
                if (!opts)
@@@ -2424,14 -2402,11 +2417,14 @@@ int setup_revisions(int argc, const cha
                revs->diff = 1;
  
        /* Pickaxe, diff-filter and rename following need diffs */
 -      if (revs->diffopt.pickaxe ||
 +      if ((revs->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) ||
            revs->diffopt.filter ||
            revs->diffopt.flags.follow_renames)
                revs->diff = 1;
  
 +      if (revs->diffopt.objfind)
 +              revs->simplify_history = 0;
 +
        if (revs->topo_order)
                revs->limited = 1;
  
@@@ -2860,16 -2835,6 +2853,16 @@@ void reset_revision_walk(void
        clear_object_flags(SEEN | ADDED | SHOWN);
  }
  
 +static int mark_uninteresting(const struct object_id *oid,
 +                            struct packed_git *pack,
 +                            uint32_t pos,
 +                            void *unused)
 +{
 +      struct object *o = parse_object(oid);
 +      o->flags |= UNINTERESTING | SEEN;
 +      return 0;
 +}
 +
  int prepare_revision_walk(struct rev_info *revs)
  {
        int i;
            (revs->limited && limiting_can_increase_treesame(revs)))
                revs->treesame.name = "treesame";
  
 +      if (revs->exclude_promisor_objects) {
 +              for_each_packed_object(mark_uninteresting, NULL,
 +                                     FOR_EACH_OBJECT_PROMISOR_ONLY);
 +      }
 +
        if (revs->no_walk != REVISION_WALK_NO_WALK_UNSORTED)
                commit_list_sort_by_date(&revs->commits);
        if (revs->no_walk)
@@@ -3094,8 -3054,6 +3087,6 @@@ enum commit_action get_commit_action(st
                return commit_ignore;
        if (revs->unpacked && has_sha1_pack(commit->object.oid.hash))
                return commit_ignore;
-       if (revs->show_all)
-               return commit_show;
        if (commit->object.flags & UNINTERESTING)
                return commit_ignore;
        if (revs->min_age != -1 &&
@@@ -3194,7 -3152,6 +3185,6 @@@ enum commit_action simplify_commit(stru
        enum commit_action action = get_commit_action(revs, commit);
  
        if (action == commit_show &&
-           !revs->show_all &&
            revs->prune && revs->dense && want_ancestry(revs)) {
                /*
                 * --full-diff on simplified parents is no good: it
diff --combined revision.h
@@@ -90,7 -90,6 +90,6 @@@ struct rev_info 
        unsigned int    dense:1,
                        prune:1,
                        no_walk:2,
-                       show_all:1,
                        remove_empty_trees:1,
                        simplify_history:1,
                        topo_order:1,
                        ancestry_path:1,
                        first_parent_only:1,
                        line_level_traverse:1,
 -                      tree_blobs_in_commit_order:1;
 +                      tree_blobs_in_commit_order:1,
 +
 +                      /* for internal use only */
 +                      exclude_promisor_objects:1;
  
        /* Diff flags */
        unsigned int    diff:1,