Package: tig / 2.0.2-2

bts757692-topo-order Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
commit adb362bd657cc474629557310dfab12051bb61ac
Author: Jonas Fonseca <jonas.fonseca@gmail.com>
Date:   Wed Aug 13 23:43:15 2014 -0400

    Force --topo-order when graph is enabled and no commit order is set
    
    This is what `git log --graph` does to ensure that parent commits comes
    before child commits. The test case is based on the example provided
    by Benjamin Bergman in issue #238.
    
    Fixes #238 and Debian bug #757692
    References #300

diff a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc
--- a/doc/tigrc.5.adoc
+++ b/doc/tigrc.5.adoc
@@ -234,6 +234,8 @@
 	Commit ordering using the default (chronological reverse) order,
 	topological order, date order or reverse order. The default order is
 	used when the option is set to false, and topo order when set to true.
+	Note that topological order is automatically used in the main view when
+	the commit graph is enabled and the commit order is set to the default.
 
 'ignore-case' (bool)::
 
--- a/include/tig/options.h
+++ b/include/tig/options.h
@@ -167,6 +167,7 @@
 
 const char *ignore_space_arg();
 const char *commit_order_arg();
+const char *commit_order_arg_with_graph(bool with_graph);
 const char *diff_context_arg();
 const char *show_notes_arg();
 
--- a/src/main.c
+++ b/src/main.c
@@ -181,33 +181,43 @@
 	return with_reflog;
 }
 
+main_with_graph(struct view *view, enum open_flags flags)
+{
+	struct view_column *column = get_view_column(view, VIEW_COLUMN_COMMIT_TITLE);
+
+	if (open_in_pager_mode(flags))
+		return FALSE;
+
+	return column && column->opt.commit_title.graph &&
+	       opt_commit_order != COMMIT_ORDER_REVERSE;
+}
+
 static bool
 main_open(struct view *view, enum open_flags flags)
 {
+	bool with_graph = main_with_graph(view, flags);
 	const char *pretty_custom_argv[] = {
-		GIT_MAIN_LOG_CUSTOM(encoding_arg, commit_order_arg(), "%(cmdlineargs)", "%(revargs)", "%(fileargs)")
+		GIT_MAIN_LOG_CUSTOM(encoding_arg, commit_order_arg_with_graph(with_graph),
+			"%(cmdlineargs)", "%(revargs)", "%(fileargs)")
 	};
 	const char *pretty_raw_argv[] = {
-		GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg(), "%(cmdlineargs)", "%(revargs)", "%(fileargs)")
+		GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg_with_graph(with_graph),
+			"%(cmdlineargs)", "%(revargs)", "%(fileargs)")
 	};
 	struct main_state *state = view->private;
 	const char **main_argv = pretty_custom_argv;
-	struct view_column *column;
 	enum watch_trigger changes_triggers = WATCH_NONE;
 
 	if (opt_show_changes && repo.is_inside_work_tree)
 		changes_triggers |= WATCH_INDEX;
 
-	column = get_view_column(view, VIEW_COLUMN_COMMIT_TITLE);
-	state->with_graph = column && column->opt.commit_title.graph &&
-			    opt_commit_order != COMMIT_ORDER_REVERSE;
+	state->with_graph = with_graph;
 
 	if (opt_rev_argv && main_check_argv(view, opt_rev_argv))
 		main_argv = pretty_raw_argv;
 
 	if (open_in_pager_mode(flags)) {
 		changes_triggers = WATCH_NONE;
-		state->with_graph = FALSE;
 	}
 
 	/* This calls reset_view() so must be before adding changes commits. */
--- a/src/options.c
+++ b/src/options.c
@@ -128,6 +128,20 @@
 	return commit_order_arg_map[opt_commit_order].name;
 }
 
+const char *
+commit_order_arg_with_graph(bool with_graph)
+{
+	enum commit_order commit_order = opt_commit_order;
+
+	if (with_graph &&
+	    commit_order != COMMIT_ORDER_TOPO &&
+	    commit_order != COMMIT_ORDER_DATE &&
+	    commit_order != COMMIT_ORDER_AUTHOR_DATE)
+		commit_order = COMMIT_ORDER_TOPO;
+
+	return commit_order_arg_map[commit_order].name;
+}
+
 /* Use --show-notes to support Git >= 1.7.6 */
 #define NOTES_ARG	"--show-notes"
 #define NOTES_EQ_ARG	NOTES_ARG "="