Merge branch 'dj/log-graph-with-no-walk'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2015 19:54:22 +0000 (12:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2015 19:54:22 +0000 (12:54 -0700)
"git log --graph --no-walk A B..." is a otcnflicting request that
asks nonsense; no-walk tells us show discrete points in the
history, while graph asks to draw connections between these
discrete points. Forbid the combination.

* dj/log-graph-with-no-walk:
revision: forbid combining --graph and --no-walk

1  2 
Documentation/rev-list-options.txt
revision.c
t/t4202-log.sh
index e2de7891cb37cb38605dab2e0b904d38701c37f5,890775b0f6358981b0a1b30409e48daf889e1623..f620ee4e1cff3f7d6d4c26f35db8b9011894c89a
@@@ -66,10 -66,6 +66,10 @@@ if it is part of the log message
        Limit the commits output to ones that match all given `--grep`,
        instead of ones that match at least one.
  
 +--invert-grep::
 +      Limit the commits output to ones with log message that do not
 +      match the pattern specified with `--grep=<pattern>`.
 +
  -i::
  --regexp-ignore-case::
        Match the regular expression limiting patterns without regard to letter
@@@ -123,8 -119,7 +123,8 @@@ parents) and `--max-parents=-1` (negati
        because merges into a topic branch tend to be only about
        adjusting to updated upstream from time to time, and
        this option allows you to ignore the individual commits
 -      brought in to your history by such a merge.
 +      brought in to your history by such a merge. Cannot be
 +      combined with --bisect.
  
  --not::
        Reverses the meaning of the '{caret}' prefix (or lack thereof)
@@@ -177,6 -172,11 +177,6 @@@ explicitly
        Pretend as if all objects mentioned by reflogs are listed on the
        command line as `<commit>`.
  
 ---indexed-objects::
 -      Pretend as if all trees and blobs used by the index are listed
 -      on the command line.  Note that you probably want to use
 -      `--objects`, too.
 -
  --ignore-missing::
        Upon seeing an invalid object name in the input, pretend as if
        the bad input was not given.
@@@ -186,7 -186,7 +186,7 @@@ ifndef::git-rev-list[
        Pretend as if the bad bisection ref `refs/bisect/bad`
        was listed and as if it was followed by `--not` and the good
        bisection refs `refs/bisect/good-*` on the command
 -      line.
 +      line. Cannot be combined with --first-parent.
  endif::git-rev-list[]
  
  --stdin::
@@@ -567,7 -567,7 +567,7 @@@ outputs 'midpoint', the output of the t
  would be of roughly the same length.  Finding the change which
  introduces a regression is thus reduced to a binary search: repeatedly
  generate and test new 'midpoint's until the commit chain is of length
 -one.
 +one. Cannot be combined with --first-parent.
  
  --bisect-vars::
        This calculates the same as `--bisect`, except that refs in
@@@ -644,7 -644,6 +644,7 @@@ Object Traversa
  
  These options are mostly targeted for packing of Git repositories.
  
 +ifdef::git-rev-list[]
  --objects::
        Print the object IDs of any object referenced by the listed
        commits.  `--objects foo ^bar` thus means ``send me
        commits at the cost of increased time.  This is used instead of
        `--objects-edge` to build ``thin'' packs for shallow repositories.
  
 +--indexed-objects::
 +      Pretend as if all trees and blobs used by the index are listed
 +      on the command line.  Note that you probably want to use
 +      `--objects`, too.
 +
  --unpacked::
        Only useful with `--objects`; print the object IDs that are not
        in packs.
 +endif::git-rev-list[]
  
  --no-walk[=(sorted|unsorted)]::
        Only show the given commits, but do not traverse their ancestors.
        given on the command line. Otherwise (if `sorted` or no argument
        was given), the commits are shown in reverse chronological order
        by commit time.
+       Cannot be combined with `--graph`.
  
  --do-walk::
        Overrides a previous `--no-walk`.
@@@ -782,6 -776,7 +783,7 @@@ you would get an output like this
        on the left hand side of the output.  This may cause extra lines
        to be printed in between commits, in order for the graph history
        to be drawn properly.
+       Cannot be combined with `--no-walk`.
  +
  This enables parent rewriting, see 'History Simplification' below.
  +
diff --combined revision.c
index ed3f6e967b32a4b489cd32c7f9f01b732250ae3b,f594a8d8201bbfec4ef7ddddf12a9348dbf2fbe1..6399a0412cc9005875e282a139200a4f918743f5
@@@ -2017,8 -2017,6 +2017,8 @@@ static int handle_revision_opt(struct r
                grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
        } else if (!strcmp(arg, "--all-match")) {
                revs->grep_filter.all_match = 1;
 +      } else if (!strcmp(arg, "--invert-grep")) {
 +              revs->invert_grep = 1;
        } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
                if (strcmp(optarg, "none"))
                        git_log_output_encoding = xstrdup(optarg);
@@@ -2339,12 -2337,11 +2339,14 @@@ int setup_revisions(int argc, const cha
  
        if (revs->reflog_info && revs->graph)
                die("cannot combine --walk-reflogs with --graph");
+       if (revs->no_walk && revs->graph)
+               die("cannot combine --no-walk with --graph");
        if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)
                die("cannot use --grep-reflog without --walk-reflogs");
  
 +      if (revs->first_parent_only && revs->bisect)
 +              die(_("--first-parent is incompatible with --bisect"));
 +
        return left;
  }
  
@@@ -2920,7 -2917,7 +2922,7 @@@ static int commit_match(struct commit *
                                     (char *)message, strlen(message));
        strbuf_release(&buf);
        unuse_commit_buffer(commit, message);
 -      return retval;
 +      return opt->invert_grep ? !retval : retval;
  }
  
  static inline int want_ancestry(const struct rev_info *revs)
@@@ -2973,61 -2970,6 +2975,61 @@@ enum commit_action get_commit_action(st
        return commit_show;
  }
  
 +define_commit_slab(saved_parents, struct commit_list *);
 +
 +#define EMPTY_PARENT_LIST ((struct commit_list *)-1)
 +
 +/*
 + * You may only call save_parents() once per commit (this is checked
 + * for non-root commits).
 + */
 +static void save_parents(struct rev_info *revs, struct commit *commit)
 +{
 +      struct commit_list **pp;
 +
 +      if (!revs->saved_parents_slab) {
 +              revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents));
 +              init_saved_parents(revs->saved_parents_slab);
 +      }
 +
 +      pp = saved_parents_at(revs->saved_parents_slab, commit);
 +
 +      /*
 +       * When walking with reflogs, we may visit the same commit
 +       * several times: once for each appearance in the reflog.
 +       *
 +       * In this case, save_parents() will be called multiple times.
 +       * We want to keep only the first set of parents.  We need to
 +       * store a sentinel value for an empty (i.e., NULL) parent
 +       * list to distinguish it from a not-yet-saved list, however.
 +       */
 +      if (*pp)
 +              return;
 +      if (commit->parents)
 +              *pp = copy_commit_list(commit->parents);
 +      else
 +              *pp = EMPTY_PARENT_LIST;
 +}
 +
 +static void free_saved_parents(struct rev_info *revs)
 +{
 +      if (revs->saved_parents_slab)
 +              clear_saved_parents(revs->saved_parents_slab);
 +}
 +
 +struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit)
 +{
 +      struct commit_list *parents;
 +
 +      if (!revs->saved_parents_slab)
 +              return commit->parents;
 +
 +      parents = *saved_parents_at(revs->saved_parents_slab, commit);
 +      if (parents == EMPTY_PARENT_LIST)
 +              return NULL;
 +      return parents;
 +}
 +
  enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
  {
        enum commit_action action = get_commit_action(revs, commit);
@@@ -3327,3 -3269,54 +3329,3 @@@ void put_revision_mark(const struct rev
        fputs(mark, stdout);
        putchar(' ');
  }
 -
 -define_commit_slab(saved_parents, struct commit_list *);
 -
 -#define EMPTY_PARENT_LIST ((struct commit_list *)-1)
 -
 -void save_parents(struct rev_info *revs, struct commit *commit)
 -{
 -      struct commit_list **pp;
 -
 -      if (!revs->saved_parents_slab) {
 -              revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents));
 -              init_saved_parents(revs->saved_parents_slab);
 -      }
 -
 -      pp = saved_parents_at(revs->saved_parents_slab, commit);
 -
 -      /*
 -       * When walking with reflogs, we may visit the same commit
 -       * several times: once for each appearance in the reflog.
 -       *
 -       * In this case, save_parents() will be called multiple times.
 -       * We want to keep only the first set of parents.  We need to
 -       * store a sentinel value for an empty (i.e., NULL) parent
 -       * list to distinguish it from a not-yet-saved list, however.
 -       */
 -      if (*pp)
 -              return;
 -      if (commit->parents)
 -              *pp = copy_commit_list(commit->parents);
 -      else
 -              *pp = EMPTY_PARENT_LIST;
 -}
 -
 -struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit)
 -{
 -      struct commit_list *parents;
 -
 -      if (!revs->saved_parents_slab)
 -              return commit->parents;
 -
 -      parents = *saved_parents_at(revs->saved_parents_slab, commit);
 -      if (parents == EMPTY_PARENT_LIST)
 -              return NULL;
 -      return parents;
 -}
 -
 -void free_saved_parents(struct rev_info *revs)
 -{
 -      if (revs->saved_parents_slab)
 -              clear_saved_parents(revs->saved_parents_slab);
 -}
diff --combined t/t4202-log.sh
index 5f2b290d2b803a4af971a1c03021e97a16951847,a9806520fb1733c0586bfed50a26d41ee5625cb3..f111705e704ad064409d6354aec78696bf325f5d
@@@ -212,21 -212,6 +212,21 @@@ test_expect_success 'log --grep' 
        test_cmp expect actual
  '
  
 +cat > expect << EOF
 +second
 +initial
 +EOF
 +test_expect_success 'log --invert-grep --grep' '
 +      git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'log --invert-grep --grep -i' '
 +      echo initial >expect &&
 +      git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
 +      test_cmp expect actual
 +'
 +
  test_expect_success 'log --grep option parsing' '
        echo second >expect &&
        git log -1 --pretty="tformat:%s" --grep sec >actual &&
@@@ -887,4 -872,8 +887,8 @@@ test_expect_success GPG 'log --graph --
        grep "^| | gpg: Good signature" actual
  '
  
+ test_expect_success 'log --graph --no-walk is forbidden' '
+       test_must_fail git log --graph --no-walk
+ '
  test_done