From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Caspar Duregger <herr.kaste@gmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH 1/4] rebase -i: stop overwriting ORIG_HEAD buffer
Date: Tue, 27 Oct 2020 14:02:14 +0000 [thread overview]
Message-ID: <24f2c4a62317231f4eabed23bb24d345abc9d67e.1603807338.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.773.git.1603807337.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
After rebasing ORIG_HEAD is supposed to point to the old HEAD of the
rebased branch. Unfortunately the buffer storing the oid was
overwritten with a new oid before ORIG_HEAD was created. The buffer is
also used when writing .git/rebase-merge/orig-head which is used by
`rebase --abort` to restore the previous head. Luckily that file is
written before the buffer is overwritten. As we want the full oid
find_unique_abbrev() is replaced with oid_to_hex_r() rather than
find_unique_abbrev_r().
I think that all of the users of head_hash should actually be using
opts->orig_head instead as passing a string rather than a struct
object_id around is a hang over from the scripted implementation. This
patch just fixes the immediate bug and adds a regression test based on
Caspar's reproduction example. The users will be converted to use
struct object_id and head_hash removed in the next few commits.
Reported-by: Caspar Duregger <herr.kaste@gmail.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
builtin/rebase.c | 10 +++++-----
t/t3404-rebase-interactive.sh | 11 +++++++++++
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index eeca53382f..6def28a533 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -270,15 +270,15 @@ static int edit_todo_file(unsigned flags)
}
static int get_revision_ranges(struct commit *upstream, struct commit *onto,
- struct object_id *orig_head, const char **head_hash,
+ struct object_id *orig_head, char *head_hash,
char **revisions, char **shortrevisions)
{
struct commit *base_rev = upstream ? upstream : onto;
const char *shorthead;
- *head_hash = find_unique_abbrev(orig_head, GIT_MAX_HEXSZ);
+ oid_to_hex_r(head_hash, orig_head);
*revisions = xstrfmt("%s...%s", oid_to_hex(&base_rev->object.oid),
- *head_hash);
+ head_hash);
shorthead = find_unique_abbrev(orig_head, DEFAULT_ABBREV);
@@ -327,7 +327,7 @@ static void split_exec_commands(const char *cmd, struct string_list *commands)
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
{
int ret;
- const char *head_hash = NULL;
+ char head_hash[GIT_MAX_HEXSZ];
char *revisions = NULL, *shortrevisions = NULL;
struct strvec make_script_args = STRVEC_INIT;
struct todo_list todo_list = TODO_LIST_INIT;
@@ -335,7 +335,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
struct string_list commands = STRING_LIST_INIT_DUP;
if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head,
- &head_hash, &revisions, &shortrevisions))
+ head_hash, &revisions, &shortrevisions))
return -1;
if (init_basic_state(&replay,
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 07a1617351..1e56696e4f 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1797,6 +1797,17 @@ test_expect_success 'todo has correct onto hash' '
test_i18ngrep "^# Rebase ..* onto $onto" actual
'
+test_expect_success 'ORIG_HEAD is updated correctly' '
+ test_when_finished "git checkout master && git branch -D test-orig-head" &&
+ git checkout -b test-orig-head A &&
+ git commit --allow-empty -m A1 &&
+ git commit --allow-empty -m A2 &&
+ git commit --allow-empty -m A3 &&
+ git commit --allow-empty -m A4 &&
+ git rebase master &&
+ test_cmp_rev ORIG_HEAD test-orig-head@{1}
+'
+
# This must be the last test in this file
test_expect_success '$EDITOR and friends are unchanged' '
test_editor_unchanged
--
gitgitgadget
next prev parent reply other threads:[~2020-10-27 18:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 14:02 [PATCH 0/4] rebase -i: fix ORIG_HEAD handling Phillip Wood via GitGitGadget
2020-10-27 14:02 ` Phillip Wood via GitGitGadget [this message]
2020-10-27 21:10 ` [PATCH 1/4] rebase -i: stop overwriting ORIG_HEAD buffer Junio C Hamano
2020-10-31 10:55 ` Phillip Wood
2020-11-02 19:40 ` herr.kaste
2020-11-03 0:21 ` Junio C Hamano
2020-11-03 11:02 ` herr.kaste
2020-10-27 14:02 ` [PATCH 2/4] rebase -i: use struct object_id rather than looking up commit Phillip Wood via GitGitGadget
2020-10-27 14:02 ` [PATCH 3/4] rebase -i: use struct object_id when writing state Phillip Wood via GitGitGadget
2020-10-27 14:02 ` [PATCH 4/4] rebase -i: simplify get_revision_ranges() Phillip Wood via GitGitGadget
2020-11-04 15:29 ` [PATCH v2 0/4] rebase -i: fix ORIG_HEAD handling Phillip Wood via GitGitGadget
2020-11-04 15:29 ` [PATCH v2 1/4] rebase -i: stop overwriting ORIG_HEAD buffer Phillip Wood via GitGitGadget
2020-11-04 15:29 ` [PATCH v2 2/4] rebase -i: use struct object_id rather than looking up commit Phillip Wood via GitGitGadget
2020-11-04 15:29 ` [PATCH v2 3/4] rebase -i: use struct object_id when writing state Phillip Wood via GitGitGadget
2020-11-04 15:29 ` [PATCH v2 4/4] rebase -i: simplify get_revision_ranges() Phillip Wood via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=24f2c4a62317231f4eabed23bb24d345abc9d67e.1603807338.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=herr.kaste@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).