]> git.ipfire.org Git - thirdparty/git.git/commit
replay: remove dead code and rearrange
authorKristoffer Haugsbakk <code@khaugsbakk.name>
Mon, 5 Jan 2026 19:53:17 +0000 (20:53 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Jan 2026 22:30:15 +0000 (07:30 +0900)
commit76eab50f756fedfa28388213d7fea209f86dfae6
tree2f6ee0962229e0e9092c6d5088d7f23849a2c7fa
parent66ce5f8e8872f0183bb137911c52b07f1f242d13
replay: remove dead code and rearrange

22d99f01 (replay: add --advance or 'cherry-pick' mode, 2023-11-24) both
added `--advance` and made one of `--onto` or `--advance` mandatory.
But `determine_replay_mode` claims that there is a third alternative;
neither of `--onto` or `--advance` were given:

    if (onto_name) {
    ...
    } else if (*advance_name) {
    ...
    } else {
    ...
    }

But this is false—the fallthrough else-block is dead code.

Commit 22d99f01 was iterated upon by several people.[1] The initial
author wrote code for a sort of *guess mode*, allowing for shorter
commands when that was possible. But the next person instead made one
of the aforementioned options mandatory. In turn this code was dead on
arrival in git.git.

[1]: https://lore.kernel.org/git/CABPp-BEcJqjD4ztsZo2FTZgWT5ZOADKYEyiZtda+d0mSd1quPQ@mail.gmail.com/

Let’s remove this code. We can also join the if-block with the
condition `!*advance_name` into the `*onto` block since we do not set
`*advance_name` in this function. It only looked like we might set it
since the dead code has this line:

    *advance_name = xstrdup_or_null(last_key);

Let’s also rename the function since we do not determine the
replay mode here. We just set up `*onto` and refs to update.

Note that there might be more dead code caused by this *guess mode*.
We only concern ourselves with this function for now.

Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/replay.c