From: Pratik Karki <predatoramigo@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Johannes.Schindelin@gmx.de,
sbeller@google.com, alban.gruin@gmail.com, gitster@pobox.com,
Pratik Karki <predatoramigo@gmail.com>
Subject: [PATCH 2/6] builtin rebase: optionally pass custom reflogs to reset_head()
Date: Wed, 8 Aug 2018 21:21:31 +0545 [thread overview]
Message-ID: <20180808153635.19944-3-predatoramigo@gmail.com> (raw)
In-Reply-To: <20180808153635.19944-1-predatoramigo@gmail.com>
In the next patch, we will make use of that in the code that
fast-forwards to `onto` whenever possible.
Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
---
builtin/rebase.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index c5b2534717..c51b9d288a 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -431,7 +431,8 @@ static int run_specific_rebase(struct rebase_options *opts)
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
static int reset_head(struct object_id *oid, const char *action,
- const char *switch_to_branch, int detach_head)
+ const char *switch_to_branch, int detach_head,
+ const char *reflog_orig_head, const char *reflog_head)
{
struct object_id head_oid;
struct tree_desc desc;
@@ -506,20 +507,26 @@ static int reset_head(struct object_id *oid, const char *action,
old_orig = &oid_old_orig;
if (!get_oid("HEAD", &oid_orig)) {
orig = &oid_orig;
- strbuf_addstr(&msg, "updating ORIG_HEAD");
- update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
+ 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);
- strbuf_setlen(&msg, prefix_len);
- strbuf_addstr(&msg, "updating HEAD");
+ if (!reflog_head) {
+ strbuf_setlen(&msg, prefix_len);
+ strbuf_addstr(&msg, "updating HEAD");
+ reflog_head = msg.buf;
+ }
if (!switch_to_branch)
- ret = update_ref(msg.buf, "HEAD", oid, orig, REF_NO_DEREF,
+ ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF,
UPDATE_REFS_MSG_ON_ERR);
else {
ret = create_symref("HEAD", switch_to_branch, msg.buf);
if (!ret)
- ret = update_ref(msg.buf, "HEAD", oid, NULL, 0,
+ ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR);
}
@@ -899,7 +906,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
rerere_clear(&merge_rr);
string_list_clear(&merge_rr, 1);
- if (reset_head(NULL, "reset", NULL, 0) < 0)
+ if (reset_head(NULL, "reset", NULL, 0, NULL, NULL) < 0)
die(_("could not discard worktree changes"));
if (read_basic_state(&options))
exit(1);
@@ -915,7 +922,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (read_basic_state(&options))
exit(1);
if (reset_head(&options.orig_head, "reset",
- options.head_name, 0) < 0)
+ options.head_name, 0, NULL, NULL) < 0)
die(_("could not move back to %s"),
oid_to_hex(&options.orig_head));
ret = finish_rebase(&options);
@@ -1235,7 +1242,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
write_file(autostash, "%s", buf.buf);
printf(_("Created autostash: %s\n"), buf.buf);
if (reset_head(&head->object.oid, "reset --hard",
- NULL, 0) < 0)
+ NULL, 0, NULL, NULL) < 0)
die(_("could not reset --hard"));
printf(_("HEAD is now at %s"),
find_unique_abbrev(&head->object.oid,
@@ -1289,7 +1296,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
strbuf_addf(&buf, "rebase: checkout %s",
options.switch_to);
if (reset_head(&oid, "checkout",
- options.head_name, 0) < 0) {
+ options.head_name, 0,
+ NULL, NULL) < 0) {
ret = !!error(_("could not switch to "
"%s"),
options.switch_to);
@@ -1354,7 +1362,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
"it...\n"));
strbuf_addf(&msg, "rebase: checkout %s", options.onto_name);
- if (reset_head(&options.onto->object.oid, "checkout", NULL, 1))
+ if (reset_head(&options.onto->object.oid, "checkout", NULL, 1,
+ NULL, msg.buf))
die(_("Could not detach HEAD"));
strbuf_release(&msg);
--
2.18.0
next prev parent reply other threads:[~2018-08-08 15:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-08 15:36 [GSoC] [PATCH 0/6] builtin rebase rest Pratik Karki
2018-08-08 15:36 ` [PATCH 1/6] builtin rebase: optionally auto-detect the upstream Pratik Karki
2018-08-08 15:36 ` Pratik Karki [this message]
2018-08-08 15:36 ` [PATCH 3/6] builtin rebase: fast-forward to onto if it is a proper descendant Pratik Karki
2018-08-08 15:36 ` [PATCH 4/6] builtin rebase: show progress when connected to a terminal Pratik Karki
2018-08-08 15:36 ` [PATCH 5/6] builtin rebase: use no-op editor when interactive is "implied" Pratik Karki
2018-08-08 15:36 ` [PATCH 6/6] builtin rebase: error out on incompatible option/mode combinations Pratik Karki
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=20180808153635.19944-3-predatoramigo@gmail.com \
--to=predatoramigo@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=alban.gruin@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.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).