replay: change rev walking options

Let's force the rev walking options we need after calling setup_revisions() instead of before. This might override some user supplied rev walking command line options though. So let's detect that and warn users by: a) setting the desired values, before setup_revisions(), b) checking after setup_revisions() whether these values differ from the desired values, c) if so throwing a warning and setting the desired values again. We want the command to work from older commits to newer ones by default. Also we don't want history simplification, as we want to deal with all the commits in the affected range. Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Co-authored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Nov 24, 2023 at 12:10 UTC 8259e4154f46de5b3443a3ff7b1cc4441ec6b7df
1 file changed +41 -7
builtin/replay.c
+41 -7
@@ -173,22 +173,56 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
173
174 repo_init_revisions(the_repository, &revs, prefix);
175
176 - revs.verbose_header = 1;
177 - revs.max_parents = 1;
178 - revs.cherry_mark = 1;
179 - revs.limited = 1;
176 + strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
177 +
178 + /*
179 + * Set desired values for rev walking options here. If they
180 + * are changed by some user specified option in setup_revisions()
181 + * below, we will detect that below and then warn.
182 + *
183 + * TODO: In the future we might want to either die(), or allow
184 + * some options changing these values if we think they could
185 + * be useful.
186 + */
187 revs.reverse = 1;
181 - revs.right_only = 1;
188 revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
189 revs.topo_order = 1;
184 -
185 - strvec_pushl(&rev_walk_args, "", argv[2], "--not", argv[1], NULL);
190 + revs.simplify_history = 0;
191
192 if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
193 ret = error(_("unhandled options"));
194 goto cleanup;
195 }
196
197 + /*
198 + * Detect and warn if we override some user specified rev
199 + * walking options.
200 + */
201 + if (revs.reverse != 1) {
202 + warning(_("some rev walking options will be overridden as "
203 + "'%s' bit in 'struct rev_info' will be forced"),
204 + "reverse");
205 + revs.reverse = 1;
206 + }
207 + if (revs.sort_order != REV_SORT_IN_GRAPH_ORDER) {
208 + warning(_("some rev walking options will be overridden as "
209 + "'%s' bit in 'struct rev_info' will be forced"),
210 + "sort_order");
211 + revs.sort_order = REV_SORT_IN_GRAPH_ORDER;
212 + }
213 + if (revs.topo_order != 1) {
214 + warning(_("some rev walking options will be overridden as "
215 + "'%s' bit in 'struct rev_info' will be forced"),
216 + "topo_order");
217 + revs.topo_order = 1;
218 + }
219 + if (revs.simplify_history != 0) {
220 + warning(_("some rev walking options will be overridden as "
221 + "'%s' bit in 'struct rev_info' will be forced"),
222 + "simplify_history");
223 + revs.simplify_history = 0;
224 + }
225 +
226 strvec_clear(&rev_walk_args);
227
228 if (prepare_revision_walk(&revs) < 0) {