Merge branch 'jk/rev-list-empty-input' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:02:48 +0000 (17:02 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:02:48 +0000 (17:02 +0900)
"git log --tag=no-such-tag" showed log starting from HEAD, which
has been fixed---it now shows nothing.

* jk/rev-list-empty-input:
revision: do not fallback to default when rev_input_given is set
rev-list: don't show usage when we see empty ref patterns
revision: add rev_input_given flag
t6018: flesh out empty input/output rev-list tests

1  2 
builtin/rev-list.c
revision.c
diff --combined builtin/rev-list.c
index e8f50489038644ef7a6dc0d217563c65fa9d6083,1e9cc594881f8f08fb12c284271b00bcaae18ddc..95b4128250c850eb130fbdfea2407bad819a85b8
@@@ -11,7 -11,6 +11,7 @@@
  #include "graph.h"
  #include "bisect.h"
  #include "progress.h"
 +#include "reflog-walk.h"
  
  static const char rev_list_usage[] =
  "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@@ -123,7 -122,6 +123,7 @@@ static void show_commit(struct commit *
                ctx.date_mode_explicit = revs->date_mode_explicit;
                ctx.fmt = revs->commit_format;
                ctx.output_encoding = get_log_output_encoding();
 +              ctx.color = revs->diffopt.use_color;
                pretty_print_commit(&ctx, commit, &buf);
                if (buf.len) {
                        if (revs->commit_format != CMIT_FMT_ONELINE)
@@@ -350,9 -348,10 +350,10 @@@ int cmd_rev_list(int argc, const char *
                /* Only --header was specified */
                revs.commit_format = CMIT_FMT_RAW;
  
 -      if ((!revs.commits &&
 +      if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
             (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
-             !revs.pending.nr)) ||
+             !revs.pending.nr) &&
+            !revs.rev_input_given) ||
            revs.diff)
                usage(rev_list_usage);
  
diff --combined revision.c
index 2631b013a52980f1c338ba1cd539da50784475f4,ba2b166cd67fab9f68c303f2fe300511bf416b4d..f032ab2e5c5c73c691338cdaf99d5b3b3d16b674
@@@ -148,14 -148,16 +148,14 @@@ static void add_pending_object_with_pat
        if (revs->reflog_info && obj->type == OBJ_COMMIT) {
                struct strbuf buf = STRBUF_INIT;
                int len = interpret_branch_name(name, 0, &buf, 0);
 -              int st;
  
                if (0 < len && name[len] && buf.len)
                        strbuf_addstr(&buf, name + len);
 -              st = add_reflog_for_walk(revs->reflog_info,
 -                                       (struct commit *)obj,
 -                                       buf.buf[0] ? buf.buf: name);
 +              add_reflog_for_walk(revs->reflog_info,
 +                                  (struct commit *)obj,
 +                                  buf.buf[0] ? buf.buf: name);
                strbuf_release(&buf);
 -              if (st)
 -                      return;
 +              return; /* do not add the commit itself */
        }
        add_object_array_with_path(obj, name, &revs->pending, mode, path);
  }
@@@ -1166,6 -1168,7 +1166,7 @@@ static void init_all_refs_cb(struct all
  {
        cb->all_revs = revs;
        cb->all_flags = flags;
+       revs->rev_input_given = 1;
  }
  
  void clear_ref_exclusion(struct string_list **ref_excludes_p)
@@@ -2313,7 -2316,7 +2314,7 @@@ int setup_revisions(int argc, const cha
                opt->tweak(revs, opt);
        if (revs->show_merge)
                prepare_show_merge(revs);
-       if (revs->def && !revs->pending.nr && !got_rev_arg) {
+       if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) {
                struct object_id oid;
                struct object *object;
                struct object_context oc;
  
        if (revs->reverse && revs->reflog_info)
                die("cannot combine --reverse with --walk-reflogs");
 +      if (revs->reflog_info && revs->limited)
 +              die("cannot combine --walk-reflogs with history-limiting options");
        if (revs->rewrite_parents && revs->children.name)
                die("cannot combine --parents and --children");
  
@@@ -2963,18 -2964,6 +2964,18 @@@ static inline int want_ancestry(const s
        return (revs->rewrite_parents || revs->children.name);
  }
  
 +/*
 + * Return a timestamp to be used for --since/--until comparisons for this
 + * commit, based on the revision options.
 + */
 +static timestamp_t comparison_date(const struct rev_info *revs,
 +                                 struct commit *commit)
 +{
 +      return revs->reflog_info ?
 +              get_reflog_timestamp(revs->reflog_info) :
 +              commit->date;
 +}
 +
  enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit)
  {
        if (commit->object.flags & SHOWN)
                return commit_show;
        if (commit->object.flags & UNINTERESTING)
                return commit_ignore;
 -      if (revs->min_age != -1 && (commit->date > revs->min_age))
 -              return commit_ignore;
 +      if (revs->min_age != -1 &&
 +          comparison_date(revs, commit) > revs->min_age)
 +                      return commit_ignore;
        if (revs->min_parents || (revs->max_parents >= 0)) {
                int n = commit_list_count(commit->parents);
                if ((n < revs->min_parents) ||
@@@ -3120,19 -3108,17 +3121,19 @@@ static void track_linear(struct rev_inf
  
  static struct commit *get_revision_1(struct rev_info *revs)
  {
 -      if (!revs->commits)
 -              return NULL;
 +      while (1) {
 +              struct commit *commit;
  
 -      do {
 -              struct commit *commit = pop_commit(&revs->commits);
 +              if (revs->reflog_info)
 +                      commit = next_reflog_entry(revs->reflog_info);
 +              else
 +                      commit = pop_commit(&revs->commits);
  
 -              if (revs->reflog_info) {
 -                      save_parents(revs, commit);
 -                      fake_reflog_parent(revs->reflog_info, commit);
 +              if (!commit)
 +                      return NULL;
 +
 +              if (revs->reflog_info)
                        commit->object.flags &= ~(ADDED | SEEN | SHOWN);
 -              }
  
                /*
                 * If we haven't done the list limiting, we need to look at
                 */
                if (!revs->limited) {
                        if (revs->max_age != -1 &&
 -                          (commit->date < revs->max_age))
 +                          comparison_date(revs, commit) < revs->max_age)
                                continue;
 -                      if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
 +
 +                      if (revs->reflog_info)
 +                              try_to_simplify_commit(revs, commit);
 +                      else if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
                                if (!revs->ignore_missing_links)
                                        die("Failed to traverse parents of commit %s",
                                                oid_to_hex(&commit->object.oid));
                                track_linear(revs, commit);
                        return commit;
                }
 -      } while (revs->commits);
 -      return NULL;
 +      }
  }
  
  /*