git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Nazri Ramliy <ayiehere@gmail.com>,
	Phillip Wood <phillip.wood123@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v2 4/4] built-in rebase: set ORIG_HEAD just once, before the rebase
Date: Sun, 03 Mar 2019 09:11:55 -0800 (PST)	[thread overview]
Message-ID: <7891c05f51583e2391c74753c0377ed416314b8c.1551633112.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.153.v2.git.gitgitgadget@gmail.com>

From: Johannes Schindelin <johannes.schindelin@gmx.de>

Technically, the scripted version set ORIG_HEAD only in two spots (which
really could have been one, because it called `git checkout $onto^0` to
start the rebase and also if it could take a shortcut, and in both cases
it called `git update-ref $orig_head`).

Practically, it *implicitly* reset ORIG_HEAD whenever `git reset --hard`
was called.

However, what we really want is that it is set exactly once, at the
beginning of the rebase.

So let's do that.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/rebase.c  | 31 ++++++++++++++++++-------------
 t/t3400-rebase.sh |  2 +-
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index aa469ec964..0f4e1ead49 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -369,6 +369,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
 #define RESET_HEAD_DETACH (1<<0)
 #define RESET_HEAD_HARD (1<<1)
 #define RESET_HEAD_REFS_ONLY (1<<2)
+#define RESET_ORIG_HEAD (1<<3)
 
 static int reset_head(struct object_id *oid, const char *action,
 		      const char *switch_to_branch, unsigned flags,
@@ -377,6 +378,7 @@ static int reset_head(struct object_id *oid, const char *action,
 	unsigned detach_head = flags & RESET_HEAD_DETACH;
 	unsigned reset_hard = flags & RESET_HEAD_HARD;
 	unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
+	unsigned update_orig_head = flags & RESET_ORIG_HEAD;
 	struct object_id head_oid;
 	struct tree_desc desc[2] = { { NULL }, { NULL } };
 	struct lock_file lock = LOCK_INIT;
@@ -453,18 +455,21 @@ static int reset_head(struct object_id *oid, const char *action,
 	strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
 	prefix_len = msg.len;
 
-	if (!get_oid("ORIG_HEAD", &oid_old_orig))
-		old_orig = &oid_old_orig;
-	if (!get_oid("HEAD", &oid_orig)) {
-		orig = &oid_orig;
-		if (!reflog_orig_head) {
-			strbuf_addstr(&msg, "updating ORIG_HEAD");
-			reflog_orig_head = msg.buf;
-		}
-		update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
-			   UPDATE_REFS_MSG_ON_ERR);
-	} else if (old_orig)
-		delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
+	if (update_orig_head) {
+		if (!get_oid("ORIG_HEAD", &oid_old_orig))
+			old_orig = &oid_old_orig;
+		if (!get_oid("HEAD", &oid_orig)) {
+			orig = &oid_orig;
+			if (!reflog_orig_head) {
+				strbuf_addstr(&msg, "updating ORIG_HEAD");
+				reflog_orig_head = msg.buf;
+			}
+			update_ref(reflog_orig_head, "ORIG_HEAD", orig,
+				   old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
+		} else if (old_orig)
+			delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
+	}
+
 	if (!reflog_head) {
 		strbuf_setlen(&msg, prefix_len);
 		strbuf_addstr(&msg, "updating HEAD");
@@ -1725,7 +1730,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	strbuf_addf(&msg, "%s: checkout %s",
 		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
 	if (reset_head(&options.onto->object.oid, "checkout", NULL,
-		       RESET_HEAD_DETACH, NULL, msg.buf))
+		       RESET_HEAD_DETACH | RESET_ORIG_HEAD, NULL, msg.buf))
 		die(_("Could not detach HEAD"));
 	strbuf_release(&msg);
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 7e8d5bb200..460d0523be 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -59,7 +59,7 @@ test_expect_success 'rebase against master' '
 	git rebase master
 '
 
-test_expect_failure 'rebase sets ORIG_HEAD to pre-rebase state' '
+test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	git checkout -b orig-head topic &&
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
-- 
gitgitgadget

      parent reply	other threads:[~2019-03-03 17:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 15:27 [PATCH 0/4] Fix ORIG_HEAD behavior of the built-in rebase Johannes Schindelin via GitGitGadget
2019-02-28 15:27 ` [PATCH 1/4] built-in rebase: no need to check out `onto` twice Johannes Schindelin via GitGitGadget
2019-02-28 20:55   ` Phillip Wood
2019-03-01 13:19     ` Johannes Schindelin
2019-03-01 15:00       ` Phillip Wood
2019-03-03  1:35         ` Junio C Hamano
2019-03-03 17:09           ` Johannes Schindelin
2019-03-03 19:11           ` Phillip Wood
2019-02-28 15:27 ` [PATCH 2/4] built-in rebase: use the correct reflog when switching branches Johannes Schindelin via GitGitGadget
2019-02-28 15:27 ` [PATCH 4/4] built-in rebase: set ORIG_HEAD just once, before the rebase Johannes Schindelin via GitGitGadget
2019-02-28 15:27 ` [PATCH 3/4] built-in rebase: demonstrate that ORIG_HEAD is not set correctly Johannes Schindelin via GitGitGadget
2019-03-03 17:11 ` [PATCH v2 0/4] Fix ORIG_HEAD behavior of the built-in rebase Johannes Schindelin via GitGitGadget
2019-03-03 17:11   ` [PATCH v2 1/4] built-in rebase: no need to check out `onto` twice Johannes Schindelin via GitGitGadget
2019-03-03 17:11   ` [PATCH v2 3/4] built-in rebase: demonstrate that ORIG_HEAD is not set correctly Johannes Schindelin via GitGitGadget
2019-03-03 17:11   ` [PATCH v2 2/4] built-in rebase: use the correct reflog when switching branches Johannes Schindelin via GitGitGadget
2019-03-03 17:11   ` Johannes Schindelin via GitGitGadget [this message]

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=7891c05f51583e2391c74753c0377ed416314b8c.1551633112.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=ayiehere@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=phillip.wood123@gmail.com \
    /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).