Because "--graph" is about connected history while --no-walk
is about discrete points, it does not make sense to allow
giving these two options at the same time. [1]

This change allows git-show to have such options' combination
as a special case, because git-show itself has underlying
--no-walk option, while "git show --graph" is a legal and
useful operation which is tested in t4052. [2,3]

2 testcases have been added to test this patch.

[1]: http://article.gmane.org/gmane.comp.version-control.git/216083
[2]: http://article.gmane.org/gmane.comp.version-control.git/264950
[3]: http://article.gmane.org/gmane.comp.version-control.git/265107

Helped-By: Eric Sunshine <sunsh...@sunshineco.com>
Helped-By: René Scharfe <l....@web.de>
Helped-By: Junio C Hamano <gits...@pobox.com>
Signed-off-by: Dongcan Jiang <dongcan.ji...@gmail.com>
---
 Documentation/rev-list-options.txt | 2 ++
 builtin/log.c                      | 1 +
 revision.c                         | 4 ++++
 revision.h                         | 3 +++
 t/t4202-log.sh                     | 4 ++++
 t/t6014-rev-list-all.sh            | 4 ++++
 6 files changed, 18 insertions(+)

diff --git a/Documentation/rev-list-options.txt 
b/Documentation/rev-list-options.txt
index 4ed8587..136abdf 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -679,6 +679,7 @@ endif::git-rev-list[]
        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`.
@@ -781,6 +782,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 --git a/builtin/log.c b/builtin/log.c
index dd8f3fc..5b5d028 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -524,6 +524,7 @@ int cmd_show(int argc, const char **argv, const char 
*prefix)
 
        memset(&match_all, 0, sizeof(match_all));
        init_revisions(&rev, prefix);
+       rev.cmd_is_show = 1;
        rev.diff = 1;
        rev.always_show_header = 1;
        rev.no_walk = REVISION_WALK_NO_WALK_SORTED;
diff --git a/revision.c b/revision.c
index 66520c6..5d6fbef 100644
--- a/revision.c
+++ b/revision.c
@@ -1399,6 +1399,8 @@ void init_revisions(struct rev_info *revs, const char 
*prefix)
 
        revs->commit_format = CMIT_FMT_DEFAULT;
 
+       revs->cmd_is_show = 0;
+
        init_grep_defaults();
        grep_init(&revs->grep_filter, prefix);
        revs->grep_filter.status_only = 1;
@@ -2339,6 +2341,8 @@ int setup_revisions(int argc, const char **argv, struct 
rev_info *revs, struct s
 
        if (revs->reflog_info && revs->graph)
                die("cannot combine --walk-reflogs with --graph");
+       if (!revs->cmd_is_show && 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");
 
diff --git a/revision.h b/revision.h
index 0ea8b4e..378c3bf 100644
--- a/revision.h
+++ b/revision.h
@@ -146,6 +146,9 @@ struct rev_info {
                        track_first_time:1,
                        linear:1;
 
+       /* cmd type */
+       unsigned int  cmd_is_show:1;
+
        enum date_mode date_mode;
 
        unsigned int    abbrev;
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 5f2b290..f111705 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -887,4 +887,8 @@ test_expect_success GPG 'log --graph --show-signature for 
merged tag' '
        grep "^| | gpg: Good signature" actual
 '
 
+test_expect_success 'log --graph --no-walk is forbidden' '
+       test_must_fail git log --graph --no-walk
+'
+
 test_done
diff --git a/t/t6014-rev-list-all.sh b/t/t6014-rev-list-all.sh
index 991ab4a..c9bedd2 100755
--- a/t/t6014-rev-list-all.sh
+++ b/t/t6014-rev-list-all.sh
@@ -35,4 +35,8 @@ test_expect_success 'repack does not lose detached HEAD' '
 
 '
 
+test_expect_success 'rev-list --graph --no-walk is forbidden' '
+       test_must_fail git rev-list --graph --no-walk HEAD
+'
+
 test_done
-- 
2.3.1.252.ge67f612

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to