aboutsummaryrefslogtreecommitdiff
path: root/sequencer.c
Commit message (Collapse)AuthorAge
* sequencer (rebase -i): write out the final messageJohannes Schindelin2017-01-17
| | | | | | | | The shell script version of the interactive rebase has a very specific final message. Teach the sequencer to print the same. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): write the progress into filesJohannes Schindelin2017-01-17
| | | | | | | | | | | For the benefit of e.g. the shell prompt, the interactive rebase not only displays the progress for the user to see, but also writes it into the msgnum/end files in the state directory. Teach the sequencer this new trick. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): show the progressJohannes Schindelin2017-01-17
| | | | | | | | | The interactive rebase keeps the user informed about its progress. If the sequencer wants to do the grunt work of the interactive rebase, it also needs to show that progress. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): suggest --edit-todo upon unknown commandJohannes Schindelin2017-01-17
| | | | | | | This is the same behavior as known from `git rebase -i`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): show only failed cherry-picks' outputJohannes Schindelin2017-01-17
| | | | | | | | This is the behavior of the shell script version of the interactive rebase, by using the `output` function defined in `git-rebase.sh`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): show only failed `git commit`'s outputJohannes Schindelin2017-01-17
| | | | | | | | This is the behavior of the shell script version of the interactive rebase, by using the `output` function defined in `git-rebase.sh`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: use run_command() directlyJohannes Schindelin2017-01-17
| | | | | | | | | | | | | | | Instead of using the convenience function run_command_v_opt_cd_env(), we now use the run_command() function. The former function is simply a wrapper of the latter, trying to make it more convenient to use. However, we already have to construct the argv and the env parameters, and we will need even finer control e.g. over the output of the command, so let's just stop using the convenience function. Based on patches and suggestions by Johannes Sixt and Jeff King. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: update reading author-scriptJohannes Schindelin2017-01-17
| | | | | | | | | | | | | | Rather than abusing a strbuf to come up with an environment block, let's just use the argv_array structure which serves the same purpose much better. While at it, rename the function to reflect the fact that it does not really care exactly what environment variables are defined in said file. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): differentiate between comments and 'noop'Johannes Schindelin2017-01-09
| | | | | | | | In the upcoming patch, we will support rebase -i's progress reporting. The progress skips comments but counts 'noop's. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the 'drop' commandJohannes Schindelin2017-01-09
| | | | | | | | The parsing part of a 'drop' command is almost identical to parsing a 'pick', while the operation is the same as that of a 'noop'. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): allow rescheduling commandsJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | The interactive rebase has the very special magic that a cherry-pick that exits with a status different from 0 and 1 signifies a failure to even record that a cherry-pick was started. This can happen e.g. when a fast-forward fails because it would overwrite untracked files. In that case, we must reschedule the command that we thought we already had at least started successfully. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): respect strategy/strategy_opts settingsJohannes Schindelin2017-01-09
| | | | | | | | | The sequencer already has an idea about using different merge strategies. We just piggy-back on top of that, using rebase -i's own settings, when running the sequencer in interactive rebase mode. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): respect the rebase.autostash settingJohannes Schindelin2017-01-09
| | | | | | | | | | | | | Git's `rebase` command inspects the `rebase.autostash` config setting to determine whether it should stash any uncommitted changes before rebasing and re-apply them afterwards. As we introduce more bits and pieces to let the sequencer act as interactive rebase's backend, here is the part that adds support for the autostash feature. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): run the post-rewrite hook, if neededJohannes Schindelin2017-01-09
| | | | | Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): record interrupted commits in rewritten, tooJohannes Schindelin2017-01-09
| | | | | | | | When continuing after a `pick` command failed, we want that commit to show up in the rewritten-list (and its notes to be rewritten), too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): copy commit notes at endJohannes Schindelin2017-01-09
| | | | | | | | | When rebasing commits that have commit notes attached, the interactive rebase rewrites those notes faithfully at the end. The sequencer must do this, too, if it wishes to do interactive rebase's job. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): set the reflog message consistentlyJohannes Schindelin2017-01-09
| | | | | | | | | We already used the same reflog message as the scripted version of rebase -i when finishing. With this commit, we do that also for all the commands before that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): refactor setting the reflog messageJohannes Schindelin2017-01-09
| | | | | | | | | | | This makes the code DRYer, with the obvious benefit that we can enhance the code further in a single place. We can also reuse the functionality elsewhere by calling this new function. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): allow fast-forwarding for edit/rewordJohannes Schindelin2017-01-09
| | | | | | | | | | | The sequencer already knew how to fast-forward instead of cherry-picking, if possible. We want to continue to do this, of course, but in case of the 'reword' command, we will need to call `git commit` after fast-forwarding. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the 'reword' commandJohannes Schindelin2017-01-09
| | | | | | | | This is now trivial, as all the building blocks are in place: all we need to do is to flip the "edit" switch when committing. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): leave a patch upon errorJohannes Schindelin2017-01-09
| | | | | | | | | When doing an interactive rebase, we want to leave a 'patch' file for further inspection by the user (even if we never tried to actually apply that patch, since we're cherry-picking instead). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): update refs after a successful rebaseJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | | | An interactive rebase operates on a detached HEAD (to keep the reflog of the original branch relatively clean), and updates the branch only at the end. Now that the sequencer learns to perform interactive rebases, it also needs to learn the trick to update the branch before removing the directory containing the state of the interactive rebase. We introduce a new head_ref variable in a wider scope than necessary at the moment, to allow for a later patch that prints out "Successfully rebased and updated <ref>". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): the todo can be empty when continuingJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | When the last command of an interactive rebase fails, the user needs to resolve the problem and then continue the interactive rebase. Naturally, the todo script is empty by then. So let's not complain about that! To that end, let's move that test out of the function that parses the todo script, and into the more high-level function read_populate_todo(). This is also necessary by now because the lower-level parse_insn_buffer() has no idea whether we are performing an interactive rebase or not. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): skip some revert/cherry-pick specific code pathJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | When a cherry-pick continues without a "todo script", the intention is simply to pick a single commit. However, when an interactive rebase is continued without a "todo script", it means that the last command has been completed and that we now need to clean up. This commit guards the revert/cherry-pick specific steps so that they are not executed in rebase -i mode. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): remove CHERRY_PICK_HEAD when no longer neededJohannes Schindelin2017-01-09
| | | | | | | The scripted version of the interactive rebase already does that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): allow continuing with staged changesJohannes Schindelin2017-01-09
| | | | | | | | | | | | When an interactive rebase is interrupted, the user may stage changes before continuing, and we need to commit those changes in that case. Please note that the nested "if" added to the sequencer_continue() is not combined into a single "if" because it will be extended with an "else" clause in a later patch in this patch series. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): write an author-script fileJohannes Schindelin2017-01-09
| | | | | | | | | | When the interactive rebase aborts, it writes out an author-script file to record the author information for the current commit. As we are about to teach the sequencer how to perform the actions behind an interactive rebase, it needs to write those author-script files, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the short commandsJohannes Schindelin2017-01-09
| | | | | | | | | For users' convenience, most rebase commands can be abbreviated, e.g. 'p' instead of 'pick' and 'x' instead of 'exec'. Let's teach the sequencer to handle those abbreviated commands just fine. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): add support for the 'fixup' and 'squash' commandsJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a huge patch, and at the same time a huge step forward to execute the performance-critical parts of the interactive rebase in a builtin command. Since 'fixup' and 'squash' are not only similar, but also need to know about each other (we want to reduce a series of fixups/squashes into a single, final commit message edit, from the user's point of view), we really have to implement them both at the same time. Most of the actual work is done by the existing code path that already handles the "pick" and the "edit" commands; We added support for other features (e.g. to amend the commit message) in the patches leading up to this one, yet there are still quite a few bits in this patch that simply would not make sense as individual patches (such as: determining whether there was anything to "fix up" in the "todo" script, etc). In theory, it would be possible to reuse the fast-forward code path also for the fixup and the squash code paths, but in practice this would make the code less readable. The end result cannot be fast-forwarded anyway, therefore let's just extend the cherry-picking code path for now. Since the sequencer parses the entire `git-rebase-todo` script in one go, fixup or squash commands without a preceding pick can be reported early (in git-rebase--interactive, we could only report such errors just before executing the fixup/squash). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): write the 'done' fileJohannes Schindelin2017-01-09
| | | | | | | | | | In the interactive rebase, commands that were successfully processed are not simply discarded, but appended to the 'done' file instead. This is used e.g. to display the current state to the user in the output of `git status` or the progress. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): learn about the 'verbose' modeJohannes Schindelin2017-01-09
| | | | | | | | | | | | When calling `git rebase -i -v`, the user wants to see some statistics after the commits were rebased. Let's show some. The strbuf we use to perform that task will be used for other things in subsequent commits, hence it is declared and initialized in a wider scope than strictly needed here. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the 'exec' commandJohannes Schindelin2017-01-09
| | | | | | | | | | | | The 'exec' command is a little special among rebase -i's commands, as it does *not* have a SHA-1 as first parameter. Instead, everything after the `exec` command is treated as command-line to execute. Let's reuse the arg/arg_len fields of the todo_item structure (which hold the oneline for pick/edit commands) to point to the command-line. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the 'edit' commandJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | This patch is a straight-forward reimplementation of the `edit` operation of the interactive rebase command. Well, not *quite* straight-forward: when stopping, the `edit` command wants to write the `patch` file (which is not only the patch, but includes the commit message and author information). To that end, this patch requires the earlier work that taught the log-tree machinery to respect the `file` setting of rev_info->diffopt to write to a file stream different than stdout. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer (rebase -i): implement the 'noop' commandJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | | | | The 'noop' command is probably the most boring of all rebase -i commands to support in the sequencer. Which makes it an excellent candidate for this first stab to add support for rebase -i's commands to the sequencer. For the moment, let's also treat empty lines and commented-out lines as 'noop'; We will refine that handling later in this patch series. To make it easier to identify "classes" of todo_commands (such as: determine whether a command is pick-like, i.e. handles a single commit), let's enforce a certain order of said commands. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: support a new action: 'interactive rebase'Johannes Schindelin2017-01-09
| | | | | | | | | | | This patch introduces a new action for the sequencer. It really does not do a whole lot of its own right now, but lays the ground work for patches to come. The intention, of course, is to finally make the sequencer the work horse of the interactive rebase (the original idea behind the "sequencer" concept). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: use a helper to find the commit messageJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | It is actually not safe to look for a commit message by looking for the first empty line and skipping it. The find_commit_subject() function looks more carefully, so let's use it. Since we are interested in the entire commit message, we re-compute the string length after verifying that the commit subject is not empty (in which case the entire commit message would be empty, something that should not happen but that we want to handle gracefully). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: move "else" keyword onto the same line as preceding braceJohannes Schindelin2017-01-09
| | | | | | | | | | | | | | | | | | It is the current coding style of the Git project to write if (...) { ... } else { ... } instead of putting the closing brace and the "else" keyword on separate lines. Pointed out by Junio Hamano. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sequencer: avoid unnecessary curly bracesJohannes Schindelin2017-01-09
| | | | | | | | | This was noticed while addressing Junio Hamano's concern that some "else" operators were on separate lines than the preceding closing brace. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'sb/sequencer-abort-safety'Junio C Hamano2016-12-21
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike "git am --abort", "git cherry-pick --abort" moved HEAD back to where cherry-pick started while picking multiple changes, when the cherry-pick stopped to ask for help from the user, and the user did "git reset --hard" to a different commit in order to re-attempt the operation. * sb/sequencer-abort-safety: Revert "sequencer: remove useless get_dir() function" sequencer: remove useless get_dir() function sequencer: make sequencer abort safer t3510: test that cherry-pick --abort does not unsafely change HEAD am: change safe_to_abort()'s not rewinding error into a warning am: fix filename in safe_to_abort() error message
| * Revert "sequencer: remove useless get_dir() function"Junio C Hamano2016-12-14
| | | | | | | | | | | | | | | | | | This reverts commit 39784cd3620cc47415c9010ec58a9616f040125c. The function had only one caller when the "remove useless" was written, but another topic will soon make heavy use of it and more importantly the function will return different paths depending on the value in opts.
| * sequencer: remove useless get_dir() functionStephan Beyer2016-12-09
| | | | | | | | | | | | | | | | | | This function is used only once, for the removal of the directory. It is not used for the creation of the directory nor anywhere else. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * sequencer: make sequencer abort saferStephan Beyer2016-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In contrast to "git am --abort", a sequencer abort did not check whether the current HEAD is the one that is expected. This can lead to loss of work (when not spotted and resolved using reflog before the garbage collector chimes in). This behavior is now changed by mimicking "git am --abort". The abortion is done but HEAD is not changed when the current HEAD is not the expected HEAD. A new file "sequencer/abort-safety" is added to save the expected HEAD. The new behavior is only active when --abort is invoked on multiple picks. The problem does not occur for the single-pick case because it is handled differently. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'jc/lock-report-on-error'Junio C Hamano2016-12-19
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Git 2.11 had a minor regression in "merge --ff-only" that competed with another process that simultanously attempted to update the index. We used to explain what went wrong with an error message, but the new code silently failed. The error message has been resurrected. * jc/lock-report-on-error: lockfile: LOCK_REPORT_ON_ERROR hold_locked_index(): align error handling with hold_lockfile_for_update() wt-status: implement opportunisitc index update correctly
| * | hold_locked_index(): align error handling with hold_lockfile_for_update()Junio C Hamano2016-12-07
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Callers of the hold_locked_index() function pass 0 when they want to prepare to write a new version of the index file without wishing to die or emit an error message when the request fails (e.g. somebody else already held the lock), and pass 1 when they want the call to die upon failure. This option is called LOCK_DIE_ON_ERROR by the underlying lockfile API, and the hold_locked_index() function translates the paramter to LOCK_DIE_ON_ERROR when calling the hold_lock_file_for_update(). Replace these hardcoded '1' with LOCK_DIE_ON_ERROR and stop translating. Callers other than the ones that are replaced with this change pass '0' to the function; no behaviour change is intended with this patch. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Among the callers of hold_locked_index() that passes 0: - diff.c::refresh_index_quietly() at the end of "git diff" is an opportunistic update; it leaks the lockfile structure but it is just before the program exits and nobody should care. - builtin/describe.c::cmd_describe(), builtin/commit.c::cmd_status(), sequencer.c::read_and_refresh_cache() are all opportunistic updates and they are OK. - builtin/update-index.c::cmd_update_index() takes a lock upfront but we may end up not needing to update the index (i.e. the entries may be fully up-to-date), in which case we do not need to issue an error upon failure to acquire the lock. We do diagnose and die if we indeed need to update, so it is OK. - wt-status.c::require_clean_work_tree() IS BUGGY. It asks silence, does not check the returned value. Compare with callsites like cmd_describe() and cmd_status() to notice that it is wrong to call update_index_if_able() unconditionally.
* | Merge branch 'jt/use-trailer-api-in-commands'Junio C Hamano2016-12-19
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | Commands that operate on a log message and add lines to the trailer blocks, such as "format-patch -s", "cherry-pick (-x|-s)", and "commit -s", have been taught to use the logic of and share the code with "git interpret-trailer". * jt/use-trailer-api-in-commands: sequencer: use trailer's trailer layout trailer: have function to describe trailer layout trailer: avoid unnecessary splitting on lines commit: make ignore_non_trailer take buf/len trailer: be stricter in parsing separators
| * sequencer: use trailer's trailer layoutJonathan Tan2016-11-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sequencer use trailer.c's trailer layout definition, as opposed to parsing the footer by itself. This makes "commit -s", "cherry-pick -x", and "format-patch --signoff" consistent with trailer, allowing non-trailer lines and multiple-line trailers in trailer blocks under certain conditions, and therefore suppressing the extra newline in those cases. Consistency with trailer extends to respecting trailer configs. Tests have been included to show that. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'js/prepare-sequencer'Junio C Hamano2016-11-22
|\ \ | | | | | | | | | | | | | | | | | | Fix for an error message string. * js/prepare-sequencer: i18n: fix unmatched single quote in error message
| * | i18n: fix unmatched single quote in error messageJiang Xin2016-11-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed unmatched single quote introduced by commit: * f56fffef9a sequencer: teach write_message() to append an optional LF Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'js/prepare-sequencer'Junio C Hamano2016-11-11
|\ \ \ | |/ / | | / | |/ |/| | | | | Silence a clang warning introduced by a recently graduated topic. * js/prepare-sequencer: sequencer: silence -Wtautological-constant-out-of-range-compare
| * sequencer: silence -Wtautological-constant-out-of-range-compareJeff King2016-11-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When clang compiles sequencer.c, it complains: sequencer.c:632:14: warning: comparison of constant 2 with expression of type 'const enum todo_command' is always true [-Wtautological-constant-out-of-range-compare] if (command < ARRAY_SIZE(todo_command_strings)) This is because "command" is an enum that may only have two values (0 and 1) and the array in question has two elements. As it turns out, clang is actually wrong here, at least according to its own bug tracker: https://llvm.org/bugs/show_bug.cgi?id=16154 But it's still worth working around this, as the warning is present with -Wall, meaning we fail compilation with "make DEVELOPER=1". Casting the enum to size_t sufficiently unconfuses clang. As a bonus, it also catches any possible out-of-bounds access if the enum takes on a negative value (which shouldn't happen either, but again, this is a defensive check). Signed-off-by: Jeff King <peff@peff.net>